diff --git a/substrate/frame/staking/src/pallet/mod.rs b/substrate/frame/staking/src/pallet/mod.rs index 28aa4f89b622..92c9311a74af 100644 --- a/substrate/frame/staking/src/pallet/mod.rs +++ b/substrate/frame/staking/src/pallet/mod.rs @@ -296,6 +296,9 @@ pub mod pallet { #[pallet::no_default_bounds] type DisablingStrategy: DisablingStrategy; + #[pallet::constant] + type MaxInvulnerables: Get; + /// Some parameters of the benchmarking. #[cfg(feature = "std")] type BenchmarkingConfig: BenchmarkingConfig; @@ -343,6 +346,7 @@ pub mod pallet { type MaxControllersInDeprecationBatch = ConstU32<100>; type EventListeners = (); type DisablingStrategy = crate::UpToLimitDisablingStrategy; + type MaxInvulnerables = ConstU32<4>; #[cfg(feature = "std")] type BenchmarkingConfig = crate::TestBenchmarkingConfig; type WeightInfo = (); @@ -365,7 +369,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn invulnerables)] #[pallet::unbounded] - pub type Invulnerables = StorageValue<_, Vec, ValueQuery>; + pub type Invulnerables = StorageValue<_, BoundedVec, ValueQuery>; /// Map from all locked "stash" accounts to the controller account. /// @@ -757,7 +761,7 @@ pub mod pallet { fn build(&self) { ValidatorCount::::put(self.validator_count); MinimumValidatorCount::::put(self.minimum_validator_count); - Invulnerables::::put(&self.invulnerables); + Invulnerables::::put(BoundedVec::truncate_from(self.invulnerables.clone())); ForceEra::::put(self.force_era); CanceledSlashPayout::::put(self.canceled_payout); SlashRewardFraction::::put(self.slash_reward_fraction); @@ -1536,7 +1540,8 @@ pub mod pallet { invulnerables: Vec, ) -> DispatchResult { ensure_root(origin)?; - >::put(invulnerables); + ensure!(invulnerables.len() <= T::MaxInvulnerables::get() as usize, Error::::BoundNotMet); + >::put(BoundedVec::truncate_from(invulnerables)); Ok(()) }