Skip to content

Commit

Permalink
Use MaxValidatorsCount limit to check validators
Browse files Browse the repository at this point in the history
  • Loading branch information
re-gius committed Dec 16, 2024
1 parent cf9d8c3 commit c265974
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions substrate/frame/staking/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,12 +1531,8 @@ pub mod pallet {
#[pallet::compact] new: u32,
) -> DispatchResult {
ensure_root(origin)?;
// ensure new validator count does not exceed maximum winners
// support by election provider.
ensure!(
new <= <T::ElectionProvider as ElectionProviderBase>::MaxWinners::get(),
Error::<T>::TooManyValidators
);
// ensure new validator count does not exceed maximum number of validators allowed.
ensure!(new <= T::MaxValidatorsCount::get(), Error::<T>::TooManyValidators);
ValidatorCount::<T>::put(new);
Ok(())
}
Expand All @@ -1557,10 +1553,7 @@ pub mod pallet {
ensure_root(origin)?;
let old = ValidatorCount::<T>::get();
let new = old.checked_add(additional).ok_or(ArithmeticError::Overflow)?;
ensure!(
new <= <T::ElectionProvider as ElectionProviderBase>::MaxWinners::get(),
Error::<T>::TooManyValidators
);
ensure!(new <= T::MaxValidatorsCount::get(), Error::<T>::TooManyValidators);

ValidatorCount::<T>::put(new);
Ok(())
Expand All @@ -1580,10 +1573,7 @@ pub mod pallet {
let old = ValidatorCount::<T>::get();
let new = old.checked_add(factor.mul_floor(old)).ok_or(ArithmeticError::Overflow)?;

ensure!(
new <= <T::ElectionProvider as ElectionProviderBase>::MaxWinners::get(),
Error::<T>::TooManyValidators
);
ensure!(new <= T::MaxValidatorsCount::get(), Error::<T>::TooManyValidators);

ValidatorCount::<T>::put(new);
Ok(())
Expand Down

0 comments on commit c265974

Please sign in to comment.