Skip to content

Commit

Permalink
Benchmark for new session
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 19, 2024
1 parent db7f4e9 commit 5fa6a24
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 34 deletions.
12 changes: 12 additions & 0 deletions pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ benchmarks! {
verify {
assert_last_event::<T>(Event::<T>::SignersRotation(signers.clone()).into());
}

new_session_validators_less_then_signers {
let caller: T::AccountId = whitelisted_caller();
let validator_id_res = <T as pallet_session::Config>::ValidatorId::try_from(caller.clone()).or(Err(Error::<T>::InvalidValidatorId)).unwrap();
Signers::<T>::put(vec![validator_id_res.clone(), validator_id_res.clone()]);

}: {
Staking::<T>::new_session_handler(&vec![validator_id_res])
}
verify {
assert!(NextSigners::<T>::get().is_none());
}
}

impl_benchmark_test_suite!(Staking, crate::mock::new_test_ext(), crate::mock::Test);
21 changes: 15 additions & 6 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@ pub mod pallet {

pub fn new_session_handler(
validators: &[<T as pallet_session::Config>::ValidatorId],
) -> Result<(), DispatchError> {
) -> Result<Weight, DispatchError> {
let mut current_signers = Self::signers();
let current_signers_length = current_signers.len();
// Since not enough validators do not allow rotation
// TODO: https://github.com/entropyxyz/entropy-core/issues/943
if validators.len() <= current_signers_length {
return Ok(());
return Ok(<T as Config>::WeightInfo::new_session_validators_less_then_signers());
}

let signers_info = pallet_parameters::Pallet::<T>::signers_info();
Expand Down Expand Up @@ -583,7 +583,7 @@ pub mod pallet {
JumpStartProgress::<T>::mutate(|jump_start_details| {
jump_start_details.parent_key_threshold = signers_info.threshold
});
Ok(())
Ok(0.into())
}
}

Expand All @@ -600,9 +600,18 @@ pub mod pallet {
fn new_session(new_index: SessionIndex) -> Option<Vec<ValidatorId>> {
let new_session = I::new_session(new_index);
if let Some(validators) = &new_session {
let result = Pallet::<T>::new_session_handler(validators);
if result.is_err() {
log::warn!("Error splitting validators, Session: {:?}", new_index)
let result_weight = Pallet::<T>::new_session_handler(validators);
if let Err(why) = result_weight {
log::warn!(
"Error splitting validators, Session: {:?}, reason: {:?}",
new_index,
why
)
} else {
frame_system::Pallet::<T>::register_extra_weight_unchecked(
result_weight.expect("Error unwraping non error value"),
DispatchClass::Mandatory,
);
}
}
new_session
Expand Down
23 changes: 23 additions & 0 deletions pallets/staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub trait WeightInfo {
fn declare_synced() -> Weight;
fn confirm_key_reshare_confirmed(c: u32) -> Weight;
fn confirm_key_reshare_completed() -> Weight;
fn new_session_validators_less_then_signers() -> Weight;
}

/// Weights for pallet_staking_extension using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -190,6 +191,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
fn new_session_validators_less_then_signers() -> Weight {
// Proof Size summary in bytes:
// Measured: `234`
// Estimated: `1719`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(4_000_000, 0)
.saturating_add(Weight::from_parts(0, 1719))
.saturating_add(T::DbWeight::get().reads(1))
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -320,4 +332,15 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(2))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
fn new_session_validators_less_then_signers() -> Weight {
// Proof Size summary in bytes:
// Measured: `234`
// Estimated: `1719`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(4_000_000, 0)
.saturating_add(Weight::from_parts(0, 1719))
.saturating_add(RocksDbWeight::get().reads(1))
}
}
68 changes: 40 additions & 28 deletions runtime/src/weights/pallet_staking_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! Autogenerated weights for `pallet_staking_extension`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0
//! DATE: 2024-07-26, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-08-19, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024
Expand Down Expand Up @@ -53,11 +53,11 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn change_endpoint() -> Weight {
// Proof Size summary in bytes:
// Measured: `1342`
// Estimated: `4807`
// Measured: `1309`
// Estimated: `4774`
// Minimum execution time: 25_000_000 picoseconds.
Weight::from_parts(29_000_000, 0)
.saturating_add(Weight::from_parts(0, 4807))
Weight::from_parts(27_000_000, 0)
.saturating_add(Weight::from_parts(0, 4774))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -71,11 +71,11 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn change_threshold_accounts() -> Weight {
// Proof Size summary in bytes:
// Measured: `1463`
// Estimated: `4928`
// Minimum execution time: 28_000_000 picoseconds.
Weight::from_parts(29_000_000, 0)
.saturating_add(Weight::from_parts(0, 4928))
// Measured: `1430`
// Estimated: `4895`
// Minimum execution time: 30_000_000 picoseconds.
Weight::from_parts(33_000_000, 0)
.saturating_add(Weight::from_parts(0, 4895))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
}
Expand All @@ -95,8 +95,8 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `1262`
// Estimated: `4764`
// Minimum execution time: 42_000_000 picoseconds.
Weight::from_parts(43_000_000, 0)
// Minimum execution time: 43_000_000 picoseconds.
Weight::from_parts(55_000_000, 0)
.saturating_add(Weight::from_parts(0, 4764))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(3))
Expand Down Expand Up @@ -129,10 +129,10 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// Proof: `StakingExtension::ThresholdServers` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn validate() -> Weight {
// Proof Size summary in bytes:
// Measured: `1951`
// Measured: `1918`
// Estimated: `6248`
// Minimum execution time: 64_000_000 picoseconds.
Weight::from_parts(70_000_000, 0)
// Minimum execution time: 65_000_000 picoseconds.
Weight::from_parts(66_000_000, 0)
.saturating_add(Weight::from_parts(0, 6248))
.saturating_add(T::DbWeight::get().reads(13))
.saturating_add(T::DbWeight::get().writes(8))
Expand All @@ -143,28 +143,29 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// Proof: `StakingExtension::IsValidatorSynced` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn declare_synced() -> Weight {
// Proof Size summary in bytes:
// Measured: `353`
// Estimated: `3818`
// Measured: `320`
// Estimated: `3785`
// Minimum execution time: 10_000_000 picoseconds.
Weight::from_parts(11_000_000, 0)
.saturating_add(Weight::from_parts(0, 3818))
.saturating_add(Weight::from_parts(0, 3785))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::NextSigners` (r:1 w:1)
/// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[0, 2]`.
fn confirm_key_reshare_confirmed(_c: u32, ) -> Weight {
/// The range of component `c` is `[0, 15]`.
fn confirm_key_reshare_confirmed(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `445`
// Estimated: `3910`
// Measured: `797 + c * (32 ±0)`
// Estimated: `4298 + c * (29 ±1)`
// Minimum execution time: 11_000_000 picoseconds.
Weight::from_parts(11_916_666, 0)
.saturating_add(Weight::from_parts(0, 3910))
Weight::from_parts(12_756_906, 0)
.saturating_add(Weight::from_parts(0, 4298))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 29).saturating_mul(c.into()))
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
Expand All @@ -174,12 +175,23 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
fn confirm_key_reshare_completed() -> Weight {
// Proof Size summary in bytes:
// Measured: `477`
// Estimated: `3942`
// Measured: `1309`
// Estimated: `4774`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(13_000_000, 0)
.saturating_add(Weight::from_parts(0, 3942))
Weight::from_parts(12_000_000, 0)
.saturating_add(Weight::from_parts(0, 4774))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `StakingExtension::Signers` (r:1 w:0)
/// Proof: `StakingExtension::Signers` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
fn new_session_validators_less_then_signers() -> Weight {
// Proof Size summary in bytes:
// Measured: `234`
// Estimated: `1719`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(4_000_000, 0)
.saturating_add(Weight::from_parts(0, 1719))
.saturating_add(T::DbWeight::get().reads(1))
}
}

0 comments on commit 5fa6a24

Please sign in to comment.