mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Revise how staking configurations are set (#10955)
* Revise how staking configurations are set fixes #10938 * Fix and add additional tests * Format * Formatting * Add doc Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/staking/src/tests.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Format * Fix build * Update weights.rs * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
committed by
GitHub
parent
0b3b3e4bfd
commit
b199ccf386
@@ -19,6 +19,7 @@
|
||||
|
||||
use frame_election_provider_support::SortedListProvider;
|
||||
use frame_support::{
|
||||
dispatch::Codec,
|
||||
pallet_prelude::*,
|
||||
traits::{
|
||||
Currency, CurrencyToVote, DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get,
|
||||
@@ -32,7 +33,7 @@ use sp_runtime::{
|
||||
DispatchError, Perbill, Percent,
|
||||
};
|
||||
use sp_staking::{EraIndex, SessionIndex};
|
||||
use sp_std::{convert::From, prelude::*};
|
||||
use sp_std::{cmp::max, convert::From, prelude::*};
|
||||
|
||||
mod impls;
|
||||
|
||||
@@ -60,6 +61,17 @@ pub mod pallet {
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
/// Possible operations on the configuration values of this pallet.
|
||||
#[derive(TypeInfo, Debug, Clone, Encode, Decode, PartialEq)]
|
||||
pub enum ConfigOp<T: Default + Codec> {
|
||||
/// Don't change.
|
||||
Noop,
|
||||
/// Set the given value.
|
||||
Set(T),
|
||||
/// Remove from storage.
|
||||
Remove,
|
||||
}
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config + SendTransactionTypes<Call<Self>> {
|
||||
/// The staking balance.
|
||||
@@ -1532,23 +1544,39 @@ pub mod pallet {
|
||||
///
|
||||
/// NOTE: Existing nominators and validators will not be affected by this update.
|
||||
/// to kick people under the new limits, `chill_other` should be called.
|
||||
#[pallet::weight(T::WeightInfo::set_staking_configs())]
|
||||
// We assume the worst case for this call is either: all items are set or all items are
|
||||
// removed.
|
||||
#[pallet::weight(max(
|
||||
T::WeightInfo::set_staking_configs_all_set(),
|
||||
T::WeightInfo::set_staking_configs_all_remove()
|
||||
))]
|
||||
pub fn set_staking_configs(
|
||||
origin: OriginFor<T>,
|
||||
min_nominator_bond: BalanceOf<T>,
|
||||
min_validator_bond: BalanceOf<T>,
|
||||
max_nominator_count: Option<u32>,
|
||||
max_validator_count: Option<u32>,
|
||||
chill_threshold: Option<Percent>,
|
||||
min_commission: Perbill,
|
||||
min_nominator_bond: ConfigOp<BalanceOf<T>>,
|
||||
min_validator_bond: ConfigOp<BalanceOf<T>>,
|
||||
max_nominator_count: ConfigOp<u32>,
|
||||
max_validator_count: ConfigOp<u32>,
|
||||
chill_threshold: ConfigOp<Percent>,
|
||||
min_commission: ConfigOp<Perbill>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
MinNominatorBond::<T>::set(min_nominator_bond);
|
||||
MinValidatorBond::<T>::set(min_validator_bond);
|
||||
MaxNominatorsCount::<T>::set(max_nominator_count);
|
||||
MaxValidatorsCount::<T>::set(max_validator_count);
|
||||
ChillThreshold::<T>::set(chill_threshold);
|
||||
MinCommission::<T>::set(min_commission);
|
||||
|
||||
macro_rules! config_op_exp {
|
||||
($storage:ty, $op:ident) => {
|
||||
match $op {
|
||||
ConfigOp::Noop => (),
|
||||
ConfigOp::Set(v) => <$storage>::put(v),
|
||||
ConfigOp::Remove => <$storage>::kill(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
config_op_exp!(MinNominatorBond<T>, min_nominator_bond);
|
||||
config_op_exp!(MinValidatorBond<T>, min_validator_bond);
|
||||
config_op_exp!(MaxNominatorsCount<T>, max_nominator_count);
|
||||
config_op_exp!(MaxValidatorsCount<T>, max_validator_count);
|
||||
config_op_exp!(ChillThreshold<T>, chill_threshold);
|
||||
config_op_exp!(MinCommission<T>, min_commission);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user