Skip to content

Commit

Permalink
fix change_validators call (#515) (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostekIV authored Jul 11, 2022
1 parent 650e6cc commit 849ee27
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("aleph-node"),
impl_name: create_runtime_str!("aleph-node"),
authoring_version: 1,
spec_version: 20,
spec_version: 21,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 8,
Expand Down
9 changes: 6 additions & 3 deletions pallets/elections/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
traits::{EraInfoProvider, SessionInfoProvider, ValidatorRewardsHandler},
CommitteeSize, Config, CurrentEraValidators, EraValidators, NextEraNonReservedValidators,
NextEraReservedValidators, Pallet, SessionValidatorBlockCount, ValidatorEraTotalReward,
ValidatorTotalRewards,
CommitteeSize, Config, CurrentEraValidators, EraValidators, NextEraCommitteeSize,
NextEraNonReservedValidators, NextEraReservedValidators, Pallet, SessionValidatorBlockCount,
ValidatorEraTotalReward, ValidatorTotalRewards,
};
use frame_election_provider_support::sp_arithmetic::Perquintill;
use frame_support::pallet_prelude::Get;
Expand Down Expand Up @@ -200,10 +200,13 @@ where
Self::if_era_starts_do(active_era + 1, session, || {
let reserved_validators = NextEraReservedValidators::<T>::get();
let non_reserved_validators = NextEraNonReservedValidators::<T>::get();
let committee_size = NextEraCommitteeSize::<T>::get();

CurrentEraValidators::<T>::put(EraValidators {
reserved: reserved_validators,
non_reserved: non_reserved_validators,
});
CommitteeSize::<T>::put(committee_size);
});
}

Expand Down
16 changes: 14 additions & 2 deletions pallets/elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ pub mod pallet {
#[pallet::storage]
pub type CommitteeSize<T> = StorageValue<_, u32, ValueQuery>;

#[pallet::type_value]
pub fn DefaultNextEraCommitteeSize<T: Config>() -> u32 {
CommitteeSize::<T>::get()
}

/// Desired size of a committee in effect from a new era.
///
/// can be changed via `change_validators` call that requires sudo.
#[pallet::storage]
pub type NextEraCommitteeSize<T> =
StorageValue<_, u32, ValueQuery, DefaultNextEraCommitteeSize<T>>;

/// List of reserved validators in force from a new era.
///
/// Can be changed via `change_validators` call that requires sudo.
Expand Down Expand Up @@ -173,7 +185,7 @@ pub mod pallet {
committee_size: Option<u32>,
) -> DispatchResult {
ensure_root(origin)?;
let committee_size = committee_size.unwrap_or_else(CommitteeSize::<T>::get);
let committee_size = committee_size.unwrap_or_else(NextEraCommitteeSize::<T>::get);
let reserved_validators =
reserved_validators.unwrap_or_else(NextEraReservedValidators::<T>::get);
let non_reserved_validators =
Expand All @@ -187,7 +199,7 @@ pub mod pallet {

NextEraNonReservedValidators::<T>::put(non_reserved_validators.clone());
NextEraReservedValidators::<T>::put(reserved_validators.clone());
CommitteeSize::<T>::put(committee_size);
NextEraCommitteeSize::<T>::put(committee_size);

Self::deposit_event(Event::ChangeValidators(
reserved_validators,
Expand Down

0 comments on commit 849ee27

Please sign in to comment.