Beefy: Provide well-formed ValidatorSet (#10445)

* beefy: provide well-formed ValidatorSet

* pallet-beefy: use well-formed ValidatorSet

* pallet-beefy-mmr: use well-formed ValidatorSet

* beefy-gadget: fail votes early when ValidatorSet empty

* beefy: small efficiency improvements

* address review comments

Signed-off-by: acatangiu <adrian@parity.io>
This commit is contained in:
Adrian Catangiu
2021-12-21 16:34:32 +02:00
committed by GitHub
parent 2d347e68f2
commit 3d8ce67383
7 changed files with 146 additions and 99 deletions
+11 -9
View File
@@ -97,8 +97,10 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// Return the current active BEEFY validator set.
pub fn validator_set() -> ValidatorSet<T::BeefyId> {
ValidatorSet::<T::BeefyId> { validators: Self::authorities(), id: Self::validator_set_id() }
pub fn validator_set() -> Option<ValidatorSet<T::BeefyId>> {
let validators: Vec<T::BeefyId> = Self::authorities();
let id: beefy_primitives::ValidatorSetId = Self::validator_set_id();
ValidatorSet::<T::BeefyId>::new(validators, id)
}
fn change_authorities(new: Vec<T::BeefyId>, queued: Vec<T::BeefyId>) {
@@ -109,13 +111,13 @@ impl<T: Config> Pallet<T> {
let next_id = Self::validator_set_id() + 1u64;
<ValidatorSetId<T>>::put(next_id);
let log = DigestItem::Consensus(
BEEFY_ENGINE_ID,
ConsensusLog::AuthoritiesChange(ValidatorSet { validators: new, id: next_id })
.encode(),
);
<frame_system::Pallet<T>>::deposit_log(log);
if let Some(validator_set) = ValidatorSet::<T::BeefyId>::new(new, next_id) {
let log = DigestItem::Consensus(
BEEFY_ENGINE_ID,
ConsensusLog::AuthoritiesChange(validator_set).encode(),
);
<frame_system::Pallet<T>>::deposit_log(log);
}
}
<NextAuthorities<T>>::put(&queued);