pallet-beefy: ensure mandatory block once per session (#11269)

* pallet-beefy: ensure mandatory block once per session

Signed-off-by: acatangiu <adrian@parity.io>

* pallet-beefy: fix tests with auth changes every session

Signed-off-by: acatangiu <adrian@parity.io>

* Apply suggestions from code review

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* beefy: fix incorrect skip session metric on node restart

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
Adrian Catangiu
2022-04-28 14:19:32 +03:00
committed by GitHub
parent 21341f35e2
commit 0d73371bb8
5 changed files with 46 additions and 34 deletions
+6 -10
View File
@@ -105,10 +105,6 @@ impl<T: Config> Pallet<T> {
}
fn change_authorities(new: Vec<T::BeefyId>, queued: Vec<T::BeefyId>) {
// Always issue a change if `session` says that the validators have changed.
// Even if their session keys are the same as before, the underlying economic
// identities have changed. Furthermore, the digest below is used to signal
// BEEFY mandatory blocks.
<Authorities<T>>::put(&new);
let next_id = Self::validator_set_id() + 1u64;
@@ -153,16 +149,16 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
Self::initialize_authorities(&authorities);
}
fn on_new_session<'a, I: 'a>(changed: bool, validators: I, queued_validators: I)
fn on_new_session<'a, I: 'a>(_changed: bool, validators: I, queued_validators: I)
where
I: Iterator<Item = (&'a T::AccountId, T::BeefyId)>,
{
if changed {
let next_authorities = validators.map(|(_, k)| k).collect::<Vec<_>>();
let next_queued_authorities = queued_validators.map(|(_, k)| k).collect::<Vec<_>>();
let next_authorities = validators.map(|(_, k)| k).collect::<Vec<_>>();
let next_queued_authorities = queued_validators.map(|(_, k)| k).collect::<Vec<_>>();
Self::change_authorities(next_authorities, next_queued_authorities);
}
// Always issue a change on each `session`, even if validator set hasn't changed.
// We want to have at least one BEEFY mandatory block per session.
Self::change_authorities(next_authorities, next_queued_authorities);
}
fn on_disabled(i: u32) {