Skip to content

Commit

Permalink
Limit validator set by MaxVal
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailK committed Apr 26, 2024
1 parent b69913c commit aff32a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pallets/validator-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ pub mod pallet {

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

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

#[pallet::pallet]
Expand Down Expand Up @@ -325,6 +328,8 @@ pub mod pallet {
InvalidDuration,
/// Failed to estimate next session.
EstimateNextSessionFailed,
/// Too many validators.
TooManyValidators,
}

#[pallet::hooks]
Expand Down Expand Up @@ -854,6 +859,8 @@ impl<T: Config> Pallet<T> {
fn do_add_validator(validator_id: T::AccountId, check_block_num: bool) -> DispatchResult {
let cur_block_number = <frame_system::Pallet<T>>::block_number();

ensure!(<Validators<T>>::get().len() < T::MaxVal::get() as usize, Error::<T>::TooManyValidators);

let item_lock = ValidatorLock::<T>::get(&validator_id).ok_or(Error::<T>::AmountLockedBelowLimit)?;
let deposit =
if item_lock.0 < cur_block_number {
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ parameter_types! {
pub const MinLockPeriod: u32 = 30 * 24 * HOURS;
pub const SlashValidatorFor: u32 = 2 * HOURS;
pub const AddAfterSlashPeriod: u32 = 7 * 24 * HOURS;
pub const MaxVal: u32 = 1000;
}

impl pallet_validator_set::Config for Runtime {
Expand All @@ -1017,6 +1018,7 @@ impl pallet_validator_set::Config for Runtime {
type Slash = Treasury;
type DefaultOffset = Offset;
type DefaultPeriod = Period;
type MaxVal = MaxVal;
}
use sp_core::U256;

Expand Down

0 comments on commit aff32a5

Please sign in to comment.