Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Add ValidatorSetId to BEEFY digest (#85)
Browse files Browse the repository at this point in the history
* add ValidatorSetId to BEEFY digest

* apply review changes
  • Loading branch information
adoerr authored Feb 15, 2021
1 parent 152e588 commit 442c741
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
15 changes: 12 additions & 3 deletions frame/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,18 @@ impl<T: Config> Pallet<T> {
// set has actually changed.
if new != Self::authorities() {
<Authorities<T>>::put(&new);
<ValidatorSetId<T>>::put(Self::validator_set_id() + 1);
let log: DigestItem<T::Hash> =
DigestItem::Consensus(BEEFY_ENGINE_ID, ConsensusLog::AuthoritiesChange(new).encode());

let next = Self::validator_set_id() + 1u64;
<ValidatorSetId<T>>::put(next);

let log: DigestItem<T::Hash> = DigestItem::Consensus(
BEEFY_ENGINE_ID,
ConsensusLog::AuthoritiesChange {
new_validator_set: new,
new_validator_set_id: next,
}
.encode(),
);
<frame_system::Module<T>>::deposit_log(log);
}

Expand Down
8 changes: 4 additions & 4 deletions frame/beefy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ fn session_change_updates_authorities() {

assert!(1 == Beefy::validator_set_id());

let want = beefy_log(ConsensusLog::AuthoritiesChange(vec![
mock_beefy_id(3),
mock_beefy_id(4),
]));
let want = beefy_log(ConsensusLog::AuthoritiesChange {
new_validator_set: vec![mock_beefy_id(3), mock_beefy_id(4)],
new_validator_set_id: 1,
});

let log = System::digest().logs[0].clone();

Expand Down
7 changes: 6 additions & 1 deletion primitives/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ pub type MmrRootHash = H256;
pub enum ConsensusLog<AuthorityId: Codec> {
/// The authorities have changed.
#[codec(index = 1)]
AuthoritiesChange(Vec<AuthorityId>),
AuthoritiesChange {
/// Set of new validators to be used
new_validator_set: Vec<AuthorityId>,
/// Id for this new set of validators
new_validator_set_id: ValidatorSetId,
},
/// Disable the authority with given index.
#[codec(index = 2)]
OnDisabled(AuthorityIndex),
Expand Down

0 comments on commit 442c741

Please sign in to comment.