From e053d34cc5db19c8dbfdfe97cd8b5d75f5360b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 23 Dec 2022 23:28:11 +0100 Subject: [PATCH] Ignore empty authority changes (#13010) When something tries to enact an authority change with an empty authority set, we will ignore this now. --- substrate/frame/aura/src/lib.rs | 8 ++++++++ substrate/frame/babe/src/lib.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/substrate/frame/aura/src/lib.rs b/substrate/frame/aura/src/lib.rs index 635e22c5d5..b19fbd57c5 100644 --- a/substrate/frame/aura/src/lib.rs +++ b/substrate/frame/aura/src/lib.rs @@ -153,7 +153,15 @@ impl Pallet { /// /// The storage will be applied immediately. /// And aura consensus log will be appended to block's log. + /// + /// This is a no-op if `new` is empty. pub fn change_authorities(new: BoundedVec) { + if new.is_empty() { + log::warn!(target: LOG_TARGET, "Ignoring empty authority change."); + + return + } + >::put(&new); let log = DigestItem::Consensus( diff --git a/substrate/frame/babe/src/lib.rs b/substrate/frame/babe/src/lib.rs index 16b2b21197..28ae4bfdc9 100644 --- a/substrate/frame/babe/src/lib.rs +++ b/substrate/frame/babe/src/lib.rs @@ -572,6 +572,8 @@ impl Pallet { /// /// Typically, this is not handled directly by the user, but by higher-level validator-set /// manager logic like `pallet-session`. + /// + /// This doesn't do anything if `authorities` is empty. pub fn enact_epoch_change( authorities: WeakBoundedVec<(AuthorityId, BabeAuthorityWeight), T::MaxAuthorities>, next_authorities: WeakBoundedVec<(AuthorityId, BabeAuthorityWeight), T::MaxAuthorities>, @@ -580,6 +582,12 @@ impl Pallet { // by the session module to be called before this. debug_assert!(Self::initialized().is_some()); + if authorities.is_empty() { + log::warn!(target: LOG_TARGET, "Ignoring empty epoch change."); + + return + } + // Update epoch index let epoch_index = EpochIndex::::get() .checked_add(1)