mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Add Control to Growth of the Staking Pallet (#8920)
* start count * track count * add max limit * min bonds for participating * respect min bond when unbonding * revert a bit of u32 * fix merge * more merge fixes * update to `Current*` * add helper functions * Update frame/staking/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * fix * minbond as storage * checkpoint * chill_other * better bond tracking * MinBond to MinNominatorBond * better doc * use helper function * oops * simple hard limits to validators / nominators. * better doc * update storage version * fix tests * enable migrations * min bond tests * chill other tests * tests for max cap * check `None` on cap too * benchmarks * Update frame/staking/src/lib.rs * Update frame/staking/src/lib.rs Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com> * Update frame/staking/src/lib.rs Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com> * Update frame/staking/src/tests.rs Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com> * fix benchmark * cargo run --release --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 * nits * fix reap_stash benchmark * remove lower bound to min bond Co-authored-by: kianenigma <kian@parity.io> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>
This commit is contained in:
@@ -30,6 +30,7 @@ pub use frame_benchmarking::{
|
||||
const SEED: u32 = 0;
|
||||
const MAX_SPANS: u32 = 100;
|
||||
const MAX_VALIDATORS: u32 = 1000;
|
||||
const MAX_NOMINATORS: u32 = 1000;
|
||||
const MAX_SLASHES: u32 = 1000;
|
||||
|
||||
// Add slashing spans to a user account. Not relevant for actual use, only to benchmark
|
||||
@@ -463,12 +464,18 @@ benchmarks! {
|
||||
reap_stash {
|
||||
let s in 1 .. MAX_SPANS;
|
||||
let (stash, controller) = create_stash_controller::<T>(0, 100, Default::default())?;
|
||||
Staking::<T>::validate(RawOrigin::Signed(controller.clone()).into(), ValidatorPrefs::default())?;
|
||||
add_slashing_spans::<T>(&stash, s);
|
||||
T::Currency::make_free_balance_be(&stash, T::Currency::minimum_balance());
|
||||
whitelist_account!(controller);
|
||||
|
||||
assert!(Bonded::<T>::contains_key(&stash));
|
||||
assert!(Validators::<T>::contains_key(&stash));
|
||||
|
||||
}: _(RawOrigin::Signed(controller), stash.clone(), s)
|
||||
verify {
|
||||
assert!(!Bonded::<T>::contains_key(&stash));
|
||||
assert!(!Validators::<T>::contains_key(&stash));
|
||||
}
|
||||
|
||||
new_era {
|
||||
@@ -563,9 +570,9 @@ benchmarks! {
|
||||
|
||||
get_npos_voters {
|
||||
// number of validator intention.
|
||||
let v in 200 .. 400;
|
||||
let v in (MAX_VALIDATORS / 2) .. MAX_VALIDATORS;
|
||||
// number of nominator intention.
|
||||
let n in 200 .. 400;
|
||||
let n in (MAX_NOMINATORS / 2) .. MAX_NOMINATORS;
|
||||
// total number of slashing spans. Assigned to validators randomly.
|
||||
let s in 1 .. 20;
|
||||
|
||||
@@ -584,15 +591,42 @@ benchmarks! {
|
||||
|
||||
get_npos_targets {
|
||||
// number of validator intention.
|
||||
let v in 200 .. 400;
|
||||
let v in (MAX_VALIDATORS / 2) .. MAX_VALIDATORS;
|
||||
// number of nominator intention.
|
||||
let n = 500;
|
||||
let n = MAX_NOMINATORS;
|
||||
|
||||
let _ = create_validators_with_nominators_for_era::<T>(v, n, T::MAX_NOMINATIONS as usize, false, None)?;
|
||||
}: {
|
||||
let targets = <Staking<T>>::get_npos_targets();
|
||||
assert_eq!(targets.len() as u32, v);
|
||||
}
|
||||
|
||||
update_staking_limits {
|
||||
// This function always does the same thing... just write to 4 storage items.
|
||||
}: _(
|
||||
RawOrigin::Root,
|
||||
BalanceOf::<T>::max_value(),
|
||||
BalanceOf::<T>::max_value(),
|
||||
Some(u32::max_value()),
|
||||
Some(u32::max_value())
|
||||
) verify {
|
||||
assert_eq!(MinNominatorBond::<T>::get(), BalanceOf::<T>::max_value());
|
||||
assert_eq!(MinValidatorBond::<T>::get(), BalanceOf::<T>::max_value());
|
||||
assert_eq!(MaxNominatorsCount::<T>::get(), Some(u32::max_value()));
|
||||
assert_eq!(MaxValidatorsCount::<T>::get(), Some(u32::max_value()));
|
||||
}
|
||||
|
||||
chill_other {
|
||||
let (_, controller) = create_stash_controller::<T>(USER_SEED, 100, Default::default())?;
|
||||
Staking::<T>::validate(RawOrigin::Signed(controller.clone()).into(), ValidatorPrefs::default())?;
|
||||
Staking::<T>::update_staking_limits(
|
||||
RawOrigin::Root.into(), BalanceOf::<T>::max_value(), BalanceOf::<T>::max_value(), None, None,
|
||||
)?;
|
||||
let caller = whitelisted_caller();
|
||||
}: _(RawOrigin::Signed(caller), controller.clone())
|
||||
verify {
|
||||
assert!(!Validators::<T>::contains_key(controller));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -603,7 +637,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn create_validators_with_nominators_for_era_works() {
|
||||
ExtBuilder::default().has_stakers(true).build().execute_with(|| {
|
||||
ExtBuilder::default().has_stakers(true).build_and_execute(|| {
|
||||
let v = 10;
|
||||
let n = 100;
|
||||
|
||||
@@ -625,7 +659,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn create_validator_with_nominators_works() {
|
||||
ExtBuilder::default().has_stakers(true).build().execute_with(|| {
|
||||
ExtBuilder::default().has_stakers(true).build_and_execute(|| {
|
||||
let n = 10;
|
||||
|
||||
let (validator_stash, nominators) = create_validator_with_nominators::<Test>(
|
||||
@@ -649,7 +683,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn add_slashing_spans_works() {
|
||||
ExtBuilder::default().has_stakers(true).build().execute_with(|| {
|
||||
ExtBuilder::default().has_stakers(true).build_and_execute(|| {
|
||||
let n = 10;
|
||||
|
||||
let (validator_stash, _nominators) = create_validator_with_nominators::<Test>(
|
||||
@@ -680,7 +714,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_payout_all() {
|
||||
ExtBuilder::default().has_stakers(true).build().execute_with(|| {
|
||||
ExtBuilder::default().has_stakers(true).build_and_execute(|| {
|
||||
let v = 10;
|
||||
let n = 100;
|
||||
|
||||
@@ -700,6 +734,7 @@ mod tests {
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Staking,
|
||||
crate::mock::ExtBuilder::default().has_stakers(true).build(),
|
||||
crate::mock::ExtBuilder::default().has_stakers(true),
|
||||
crate::mock::Test,
|
||||
exec_name = build_and_execute
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user