Skip to content

Commit

Permalink
adds ext weight limit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gpestana committed Jun 4, 2024
1 parent f7669b6 commit 23590ab
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
38 changes: 38 additions & 0 deletions polkadot/runtime/westend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,44 @@ use crate::*;
use frame_support::traits::WhitelistedStorageKeys;
use sp_core::hexdisplay::HexDisplay;

#[test]
fn payout_block_limit() {
use pallet_staking::WeightInfo;

let step = 32;
let max_extrinsic = BlockWeights::get().get(DispatchClass::Normal).max_extrinsic.unwrap();

let mut page_size = 2048;

println!("{:?}", max_extrinsic);

loop {
let ext_weight =
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(page_size);
if ext_weight.all_lt(max_extrinsic) {
println!(" == Strict voter mode\n - page_size: {:?} \n - {:?}", page_size, ext_weight);
break;
}
page_size -= step;
}

let mut page_size = 2048;

loop {
let ext_weight =
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked_lazy(
page_size,
);
if ext_weight.all_lt(max_extrinsic) {
println!(" == Lazy voter mode\n - page_size: {:?} \n - {:?}", page_size, ext_weight);
break;
}
page_size -= step;
}

assert!(false);
}

#[test]
fn remove_keys_weight_is_sensible() {
use runtime_common::crowdloan::WeightInfo;
Expand Down
58 changes: 58 additions & 0 deletions polkadot/runtime/westend/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,64 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(n.into())))
.saturating_add(Weight::from_parts(0, 3774).saturating_mul(n.into()))
}

// -- from https://github.com/paritytech/polkadot-sdk/pull/1933/files#diff-3cc81e200445313205a23ce4453156c3a3b92bdd6a007160ea0e82ea6f4c8182R584
//
/// Storage: `Staking::Bonded` (r:65 w:0)
/// Proof: `Staking::Bonded` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`)
/// Storage: `Staking::Ledger` (r:65 w:65)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStakersClipped` (r:1 w:0)
/// Proof: `Staking::ErasStakersClipped` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::ErasStakersOverview` (r:1 w:0)
/// Proof: `Staking::ErasStakersOverview` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`)
/// Storage: `Staking::ClaimedRewards` (r:1 w:1)
/// Proof: `Staking::ClaimedRewards` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::CurrentEra` (r:1 w:0)
/// Proof: `Staking::CurrentEra` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasValidatorReward` (r:1 w:0)
/// Proof: `Staking::ErasValidatorReward` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasStakersPaged` (r:1 w:0)
/// Proof: `Staking::ErasStakersPaged` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::VirtualStakers` (r:65 w:0)
/// Proof: `Staking::VirtualStakers` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`)
/// Storage: `Balances::Locks` (r:65 w:65)
/// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`)
/// Storage: `Balances::Freezes` (r:65 w:0)
/// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(67), added: 2542, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:65 w:65)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Staking::ErasRewardPoints` (r:1 w:0)
/// Proof: `Staking::ErasRewardPoints` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Staking::ErasValidatorPrefs` (r:1 w:0)
/// Proof: `Staking::ErasValidatorPrefs` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`)
/// Storage: `Staking::Payee` (r:65 w:0)
/// Proof: `Staking::Payee` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`)
/// Storage: `Staking::Validators` (r:65 w:0)
/// Proof: `Staking::Validators` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`)
/// Storage: `Staking::Nominators` (r:65 w:0)
/// Proof: `Staking::Nominators` (`max_values`: None, `max_size`: Some(558), added: 3033, mode: `MaxEncodedLen`)
/// Storage: `TargetList::ListNodes` (r:1 w:1)
/// Proof: `TargetList::ListNodes` (`max_values`: None, `max_size`: Some(170), added: 2645, mode: `MaxEncodedLen`)
/// Storage: `TargetList::ListBags` (r:8 w:8)
/// Proof: `TargetList::ListBags` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`)
/// The range of component `n` is `[0, 64]`.
fn payout_stakers_alive_staked_lazy(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `8725 + n * (482 ±0)`
// Estimated: `17769 + n * (3774 ±0)`
// Minimum execution time: 184_524_000 picoseconds.
Weight::from_parts(244_791_126, 0)
.saturating_add(Weight::from_parts(0, 17769))
// Standard Error: 46_100
.saturating_add(Weight::from_parts(62_744_799, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(25))
.saturating_add(T::DbWeight::get().reads((9_u64).saturating_mul(n.into())))
.saturating_add(T::DbWeight::get().writes(12))
.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(n.into())))
.saturating_add(Weight::from_parts(0, 3774).saturating_mul(n.into()))
}

/// Storage: `Staking::Ledger` (r:1 w:1)
/// Proof: `Staking::Ledger` (`max_values`: None, `max_size`: Some(1091), added: 3566, mode: `MaxEncodedLen`)
/// Storage: `Staking::Bonded` (r:1 w:0)
Expand Down
42 changes: 42 additions & 0 deletions substrate/frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7847,6 +7847,48 @@ mod stake_tracker {
assert!(false);
}

#[test]
fn block_limits() {
let max_extrinsic = Weight::from_parts(1_479_873_955_000, 13_650_590_614_545_068_195);

let step = 32;
let mut page_size = 512;

loop {
let ext_weight =
<Test as pallet::pallet::Config>::WeightInfo::payout_stakers_alive_staked(
page_size,
);
if ext_weight.all_lte(max_extrinsic) {
println!(
" == Strict voter mode\n - page_size: {:?} \n - {:?}",
page_size, ext_weight
);
break;
}
page_size -= step;
}

let mut page_size = 512;
loop {
let ext_weight =
<Test as pallet::pallet::Config>::WeightInfo::payout_stakers_alive_staked_lazy(
page_size,
);
if ext_weight.all_lte(max_extrinsic) {
println!(
" == Lazy voter mode\n - page_size: {:?} \n - {:?}",
page_size, ext_weight
);
break;
}
page_size -= step;
}

// err for printout.
assert!(false);
}

#[test]
fn duplicate_nominations_dedup_approvals_works() {
ExtBuilder::default()
Expand Down
22 changes: 22 additions & 0 deletions substrate/frame/staking/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23590ab

Please sign in to comment.