Skip to content

Commit

Permalink
fix benches
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Oct 17, 2024
1 parent 1864b4d commit 4f7167b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 130 deletions.
29 changes: 10 additions & 19 deletions pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,13 @@ benchmarks! {

let caller: T::AccountId = whitelisted_caller();
let validator_ids = create_validators::<T>(100, 1);
let signers_ids = create_validators::<T>((MAX_SIGNERS - 1) as u32, SEED);
let second_signer: T::AccountId = account("second_signer", 0, SEED);
let second_signer_id =
<T as pallet_session::Config>::ValidatorId::try_from(second_signer.clone())
.or(Err(Error::<T>::InvalidValidatorId))
.unwrap();
// let mut signers = //create_validators::<T>((MAX_SIGNERS - 1) as u32, SEED);
let mut signers = vec![second_signer_id.clone(); c as usize];

// For the purpose of the bench these values don't actually matter, we just care that there's a
// storage entry available
Expand All @@ -384,30 +390,15 @@ benchmarks! {
.or(Err(Error::<T>::InvalidValidatorId))
.unwrap();

let second_signer: T::AccountId = account("second_signer", 10000000, SEED);
let second_signer_id =
<T as pallet_session::Config>::ValidatorId::try_from(second_signer.clone())
.or(Err(Error::<T>::InvalidValidatorId))
.unwrap();

// full signer list leaving room for one extra validator
let mut signers = signers_ids;
// place new signer in the signers struct in different locations to calculate random selection
// re-run
// as well validators may be dropped before chosen
signers[l as usize % c as usize] = validator_id.clone();

// for signer in signers.clone() {
// validator_ids[l as usize % c as usize] = signer
// }
for i in 0 .. v {
if i as usize > signers.len() - 1 {
break;
}
signers[l as usize % c as usize] = validator_ids[l as usize % c as usize].clone();

for i in 0 .. c {
signers[i as usize] = validator_ids[i as usize].clone();
}
Signers::<T>::put(signers.clone());
signers.push(second_signer_id.clone());
}: {
let _ = Staking::<T>::new_session_handler(&validator_ids);
}
Expand Down
6 changes: 5 additions & 1 deletion pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,11 @@ pub mod pallet {
jump_start_details.parent_key_threshold = signers_info.threshold
});

weight = <T as Config>::WeightInfo::new_session(current_signers.len() as u32, count);
weight = <T as Config>::WeightInfo::new_session(
current_signers.len() as u32,
count,
remove_index_len as u32,
);

Ok(weight)
}
Expand Down
90 changes: 49 additions & 41 deletions pallets/staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub trait WeightInfo {
fn confirm_key_reshare_confirmed(c: u32) -> Weight;
fn confirm_key_reshare_completed() -> Weight;
fn new_session_base_weight(s: u32) -> Weight;
fn new_session(c: u32, l: u32) -> Weight;
fn new_session(c: u32, l: u32, v: u32) -> Weight;
fn on_initialize(s: u32, ) -> Weight;
}

Expand Down Expand Up @@ -299,46 +299,50 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Parameters::SignersInfo` (r:1 w:0)
/// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// The range of component `s` is `[2, 15]`.
fn new_session_base_weight(s: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `254 + s * (32 ±0)`
// Estimated: `1739 + s * (32 ±0)`
// Minimum execution time: 7_000_000 picoseconds.
Weight::from_parts(7_682_879, 0)
.saturating_add(Weight::from_parts(0, 1739))
// Measured: `266 + s * (32 ±0)`
// Estimated: `1751 + s * (32 ±0)`
// Minimum execution time: 5_000_000 picoseconds.
Weight::from_parts(5_772_373, 0)
.saturating_add(Weight::from_parts(0, 1751))
// Standard Error: 22_735
.saturating_add(Weight::from_parts(15_564, 0).saturating_mul(s.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(s.into()))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Parameters::SignersInfo` (r:1 w:0)
/// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Babe::NextRandomness` (r:1 w:0)
/// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
/// Storage: `Babe::EpochStart` (r:1 w:0)
/// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1)
/// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::ReshareData` (r:0 w:1)
/// Proof: `StakingExtension::ReshareData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::NextSigners` (r:0 w:1)
/// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Babe::NextRandomness` (r:1 w:0)
/// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
/// Storage: `Babe::EpochStart` (r:1 w:0)
/// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// The range of component `c` is `[1, 14]`.
/// The range of component `l` is `[0, 15]`.
fn new_session(c: u32, l: u32, ) -> Weight {
/// The range of component `v` is `[0, 15]`.
fn new_session(c: u32, l: u32, v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `482 + c * (32 ±0)`
// Estimated: `1966 + c * (32 ±0)`
// Minimum execution time: 13_000_000 picoseconds.
Weight::from_parts(12_791_889, 0)
.saturating_add(Weight::from_parts(0, 1966))
// Standard Error: 22_917
.saturating_add(Weight::from_parts(65_067, 0).saturating_mul(c.into()))
// Standard Error: 19_636
.saturating_add(Weight::from_parts(30_071, 0).saturating_mul(l.into()))
// Measured: `508 + c * (16 ±0)`
// Estimated: `2027 + c * (16 ±1) + l * (50 ±0) + v * (50 ±0)`
// Minimum execution time: 9_000_000 picoseconds.
Weight::from_parts(17_877_994, 0)
.saturating_add(Weight::from_parts(0, 2027))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into()))
.saturating_add(Weight::from_parts(0, 16).saturating_mul(c.into()))
.saturating_add(Weight::from_parts(0, 50).saturating_mul(l.into()))
.saturating_add(Weight::from_parts(0, 50).saturating_mul(v.into()))
}
/// Storage: `StakingExtension::ValidationQueue` (r:251 w:250)
/// Proof: `StakingExtension::ValidationQueue` (`max_values`: None, `max_size`: None, mode: `Measured`)
Expand Down Expand Up @@ -598,46 +602,50 @@ impl WeightInfo for () {
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Parameters::SignersInfo` (r:1 w:0)
/// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// The range of component `s` is `[2, 15]`.
fn new_session_base_weight(s: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `254 + s * (32 ±0)`
// Estimated: `1739 + s * (32 ±0)`
// Minimum execution time: 7_000_000 picoseconds.
Weight::from_parts(7_682_879, 0)
.saturating_add(Weight::from_parts(0, 1739))
// Measured: `266 + s * (32 ±0)`
// Estimated: `1751 + s * (32 ±0)`
// Minimum execution time: 5_000_000 picoseconds.
Weight::from_parts(5_772_373, 0)
.saturating_add(Weight::from_parts(0, 1751))
// Standard Error: 22_735
.saturating_add(Weight::from_parts(15_564, 0).saturating_mul(s.into()))
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(s.into()))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Parameters::SignersInfo` (r:1 w:0)
/// Proof: `Parameters::SignersInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Babe::NextRandomness` (r:1 w:0)
/// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
/// Storage: `Babe::EpochStart` (r:1 w:0)
/// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `StakingExtension::JumpStartProgress` (r:1 w:1)
/// Proof: `StakingExtension::JumpStartProgress` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::ReshareData` (r:0 w:1)
/// Proof: `StakingExtension::ReshareData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::NextSigners` (r:0 w:1)
/// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Babe::NextRandomness` (r:1 w:0)
/// Proof: `Babe::NextRandomness` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
/// Storage: `Babe::EpochStart` (r:1 w:0)
/// Proof: `Babe::EpochStart` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// The range of component `c` is `[1, 14]`.
/// The range of component `l` is `[0, 15]`.
fn new_session(c: u32, l: u32, ) -> Weight {
/// The range of component `v` is `[0, 15]`.
fn new_session(c: u32, l: u32, v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `482 + c * (32 ±0)`
// Estimated: `1966 + c * (32 ±0)`
// Minimum execution time: 13_000_000 picoseconds.
Weight::from_parts(12_791_889, 0)
.saturating_add(Weight::from_parts(0, 1966))
// Standard Error: 22_917
.saturating_add(Weight::from_parts(65_067, 0).saturating_mul(c.into()))
// Standard Error: 19_636
.saturating_add(Weight::from_parts(30_071, 0).saturating_mul(l.into()))
// Measured: `508 + c * (16 ±0)`
// Estimated: `2027 + c * (16 ±1) + l * (50 ±0) + v * (50 ±0)`
// Minimum execution time: 9_000_000 picoseconds.
Weight::from_parts(17_877_994, 0)
.saturating_add(Weight::from_parts(0, 2027))
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(3))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into()))
.saturating_add(Weight::from_parts(0, 16).saturating_mul(c.into()))
.saturating_add(Weight::from_parts(0, 50).saturating_mul(l.into()))
.saturating_add(Weight::from_parts(0, 50).saturating_mul(v.into()))
}
/// Storage: `StakingExtension::ValidationQueue` (r:251 w:250)
/// Proof: `StakingExtension::ValidationQueue` (`max_values`: None, `max_size`: None, mode: `Measured`)
Expand Down
Loading

0 comments on commit 4f7167b

Please sign in to comment.