Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pallet-staking] Bound all storage #5987

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading