diff --git a/substrate/frame/aura/src/lib.rs b/substrate/frame/aura/src/lib.rs index fd6882ca9f..ff2c5df04a 100644 --- a/substrate/frame/aura/src/lib.rs +++ b/substrate/frame/aura/src/lib.rs @@ -40,8 +40,9 @@ use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ + log, traits::{DisabledValidators, FindAuthor, Get, OnTimestampSet, OneSessionHandler}, - BoundedSlice, ConsensusEngineId, Parameter, WeakBoundedVec, + BoundedSlice, BoundedVec, ConsensusEngineId, Parameter, }; use sp_consensus_aura::{AuthorityIndex, ConsensusLog, Slot, AURA_ENGINE_ID}; use sp_runtime::{ @@ -116,7 +117,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn authorities)] pub(super) type Authorities = - StorageValue<_, WeakBoundedVec, ValueQuery>; + StorageValue<_, BoundedVec, ValueQuery>; /// The current slot of this block. /// @@ -150,7 +151,7 @@ impl Pallet { /// /// The storage will be applied immediately. /// And aura consensus log will be appended to block's log. - pub fn change_authorities(new: WeakBoundedVec) { + pub fn change_authorities(new: BoundedVec) { >::put(&new); let log = DigestItem::Consensus( @@ -219,10 +220,14 @@ impl OneSessionHandler for Pallet { let next_authorities = validators.map(|(_, k)| k).collect::>(); let last_authorities = Self::authorities(); if last_authorities != next_authorities { - let bounded = >::force_from( - next_authorities, - Some("AuRa new session"), - ); + if next_authorities.len() as u32 > T::MaxAuthorities::get() { + log::warn!( + target: "runtime::aura", + "next authorities list larger than {}, truncating", + T::MaxAuthorities::get(), + ); + } + let bounded = >::truncate_from(next_authorities); Self::change_authorities(bounded); } }