From 4a645b619eb46442acbe5ba8868a88f47d6f9593 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. --- frame/aura/src/lib.rs | 8 ++++++++ frame/babe/src/lib.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/frame/aura/src/lib.rs b/frame/aura/src/lib.rs index 635e22c5d58aa..b19fbd57c5030 100644 --- a/frame/aura/src/lib.rs +++ b/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/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index 16b2b2119793a..28ae4bfdc9dad 100644 --- a/frame/babe/src/lib.rs +++ b/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)