Skip to content

Commit

Permalink
bound invulnerables
Browse files Browse the repository at this point in the history
  • Loading branch information
Ank4n committed Oct 8, 2024
1 parent 5d82bdc commit 1bd518e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions substrate/frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ pub mod pallet {
#[pallet::no_default_bounds]
type DisablingStrategy: DisablingStrategy<Self>;

#[pallet::constant]
type MaxInvulnerables: Get<u32>;

/// Some parameters of the benchmarking.
#[cfg(feature = "std")]
type BenchmarkingConfig: BenchmarkingConfig;
Expand Down Expand Up @@ -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 = ();
Expand All @@ -365,7 +369,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn invulnerables)]
#[pallet::unbounded]
pub type Invulnerables<T: Config> = StorageValue<_, Vec<T::AccountId>, ValueQuery>;
pub type Invulnerables<T: Config> = StorageValue<_, BoundedVec<T::AccountId, T::MaxInvulnerables>, ValueQuery>;

/// Map from all locked "stash" accounts to the controller account.
///
Expand Down Expand Up @@ -757,7 +761,7 @@ pub mod pallet {
fn build(&self) {
ValidatorCount::<T>::put(self.validator_count);
MinimumValidatorCount::<T>::put(self.minimum_validator_count);
Invulnerables::<T>::put(&self.invulnerables);
Invulnerables::<T>::put(BoundedVec::truncate_from(self.invulnerables.clone()));
ForceEra::<T>::put(self.force_era);
CanceledSlashPayout::<T>::put(self.canceled_payout);
SlashRewardFraction::<T>::put(self.slash_reward_fraction);
Expand Down Expand Up @@ -1536,7 +1540,8 @@ pub mod pallet {
invulnerables: Vec<T::AccountId>,
) -> DispatchResult {
ensure_root(origin)?;
<Invulnerables<T>>::put(invulnerables);
ensure!(invulnerables.len() <= T::MaxInvulnerables::get() as usize, Error::<T>::BoundNotMet);
<Invulnerables<T>>::put(BoundedVec::truncate_from(invulnerables));
Ok(())
}

Expand Down

0 comments on commit 1bd518e

Please sign in to comment.