Skip to content

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Jul 26, 2024
1 parent 1ebc3a0 commit 0e41d56
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 82 deletions.
26 changes: 19 additions & 7 deletions pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

//! Benchmarking setup for pallet-propgation
#![allow(unused_imports)]
use entropy_shared::SIGNING_PARTY_SIZE;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{
assert_ok, ensure,
Expand Down Expand Up @@ -177,17 +178,24 @@ benchmarks! {
}

confirm_key_reshare_confirmed {
// TODO: add proper validator sized and looping for confirmations
let c in 0 .. SIGNING_PARTY_SIZE as u32;
// leave a space for two as not to rotate and only confirm rotation
let confirmation_num = c.checked_sub(2).unwrap_or(0);
let signer_num = SIGNING_PARTY_SIZE - 1;
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();
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();
ThresholdToStash::<T>::insert(caller.clone(), validator_id_res.clone());

Signers::<T>::put(vec![validator_id_res.clone(), second_signer_id.clone()]);
// full signer list leaving room for one extra validator
let mut signers = vec![second_signer_id.clone(); signer_num as usize];
signers.push(validator_id_res.clone());
Signers::<T>::put(signers.clone());

NextSigners::<T>::put(NextSignerInfo {
next_signers: vec![validator_id_res.clone(), second_signer_id],
confirmations: vec![],
next_signers: signers,
confirmations: vec![second_signer_id.clone(); confirmation_num as usize],
});

}: confirm_key_reshare(RawOrigin::Signed(caller.clone()))
Expand All @@ -196,18 +204,22 @@ benchmarks! {
}

confirm_key_reshare_completed {
// TODO: add proper validator sized
// once less confirmation to always flip to rotate
let confirmation_num = SIGNING_PARTY_SIZE - 1;

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();
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();
ThresholdToStash::<T>::insert(caller.clone(), validator_id_res.clone());
let signers = vec![validator_id_res.clone(), second_signer_id.clone()];
// full signer list leaving room for one extra validator
let mut signers = vec![second_signer_id.clone(); confirmation_num as usize];
signers.push(validator_id_res.clone());

Signers::<T>::put(signers.clone());
NextSigners::<T>::put(NextSignerInfo {
next_signers: signers.clone(),
confirmations: vec![second_signer_id],
confirmations: vec![second_signer_id; confirmation_num as usize],
});

}: confirm_key_reshare(RawOrigin::Signed(caller.clone()))
Expand Down
15 changes: 9 additions & 6 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use sp_staking::SessionIndex;

#[frame_support::pallet]
pub mod pallet {
use entropy_shared::{ValidatorInfo, X25519PublicKey};
use entropy_shared::{ValidatorInfo, X25519PublicKey, SIGNING_PARTY_SIZE};
use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo},
pallet_prelude::*,
Expand Down Expand Up @@ -420,7 +420,7 @@ pub mod pallet {

#[pallet::call_index(5)]
#[pallet::weight({
<T as Config>::WeightInfo::confirm_key_reshare_confirmed()
<T as Config>::WeightInfo::confirm_key_reshare_confirmed(SIGNING_PARTY_SIZE as u32)
.max(<T as Config>::WeightInfo::confirm_key_reshare_completed())
})]
pub fn confirm_key_reshare(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Expand All @@ -442,16 +442,19 @@ pub mod pallet {

// TODO (#927): Add another check, such as a signature or a verifying key comparison, to
// ensure that rotation was indeed successful.

if signers_info.confirmations.len() == (signers_info.next_signers.len() - 1) {
let current_signer_length = signers_info.next_signers.len();
if signers_info.confirmations.len() == (current_signer_length - 1) {
Signers::<T>::put(signers_info.next_signers.clone());
Self::deposit_event(Event::SignersRotation(signers_info.next_signers));
Ok(Some(<T as Config>::WeightInfo::confirm_key_reshare_confirmed()).into())
Ok(Some(<T as Config>::WeightInfo::confirm_key_reshare_completed()).into())
} else {
signers_info.confirmations.push(validator_stash.clone());
NextSigners::<T>::put(signers_info);
Self::deposit_event(Event::SignerConfirmed(validator_stash));
Ok(Some(<T as Config>::WeightInfo::confirm_key_reshare_completed()).into())
Ok(Some(<T as Config>::WeightInfo::confirm_key_reshare_confirmed(
current_signer_length as u32,
))
.into())
}
}
}
Expand Down
49 changes: 7 additions & 42 deletions pallets/staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ pub trait WeightInfo {
fn withdraw_unbonded() -> Weight;
fn validate() -> Weight;
fn declare_synced() -> Weight;
fn new_session_handler_helper(c: u32, n: u32, ) -> Weight;
fn confirm_key_reshare_confirmed() -> Weight;
fn confirm_key_reshare_confirmed(c: u32) -> Weight;
fn confirm_key_reshare_completed() -> Weight;
}

Expand Down Expand Up @@ -160,34 +159,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `StakingExtension::SigningGroups` (r:2 w:2)
/// Proof: `StakingExtension::SigningGroups` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[0, 1000]`.
/// The range of component `n` is `[0, 1000]`.
fn new_session_handler_helper(c: u32, n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `218 + c * (32 ±0)`
// Estimated: `6156 + c * (32 ±0)`
// Minimum execution time: 20_000_000 picoseconds.
Weight::from_parts(20_000_000, 6156)
// Standard Error: 24_941
.saturating_add(Weight::from_parts(798_680, 0).saturating_mul(c.into()))
// Standard Error: 24_941
.saturating_add(Weight::from_parts(821_922, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into()))
}
/// 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`)
fn confirm_key_reshare_confirmed() -> Weight {
/// The range of component `c` is `[0, 2]`.
fn confirm_key_reshare_confirmed(_c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `445`
// Estimated: `3910`
// Minimum execution time: 11_000_000 picoseconds.
Weight::from_parts(12_000_000, 0)
Weight::from_parts(11_916_666, 0)
.saturating_add(Weight::from_parts(0, 3910))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
Expand Down Expand Up @@ -307,34 +289,17 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `StakingExtension::SigningGroups` (r:2 w:2)
/// Proof: `StakingExtension::SigningGroups` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[0, 1000]`.
/// The range of component `n` is `[0, 1000]`.
fn new_session_handler_helper(c: u32, n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `218 + c * (32 ±0)`
// Estimated: `6156 + c * (32 ±0)`
// Minimum execution time: 20_000_000 picoseconds.
Weight::from_parts(20_000_000, 6156)
// Standard Error: 24_941
.saturating_add(Weight::from_parts(798_680, 0).saturating_mul(c.into()))
// Standard Error: 24_941
.saturating_add(Weight::from_parts(821_922, 0).saturating_mul(n.into()))
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into()))
}
/// 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`)
fn confirm_key_reshare_confirmed() -> Weight {
/// The range of component `c` is `[0, 2]`.
fn confirm_key_reshare_confirmed(_c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `445`
// Estimated: `3910`
// Minimum execution time: 11_000_000 picoseconds.
Weight::from_parts(12_000_000, 0)
Weight::from_parts(11_916_666, 0)
.saturating_add(Weight::from_parts(0, 3910))
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
Expand Down
37 changes: 10 additions & 27 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-24, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-07-26, 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 @@ -56,7 +56,7 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Measured: `1342`
// Estimated: `4807`
// Minimum execution time: 25_000_000 picoseconds.
Weight::from_parts(26_000_000, 0)
Weight::from_parts(29_000_000, 0)
.saturating_add(Weight::from_parts(0, 4807))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -73,8 +73,8 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `1463`
// Estimated: `4928`
// Minimum execution time: 29_000_000 picoseconds.
Weight::from_parts(32_000_000, 0)
// Minimum execution time: 28_000_000 picoseconds.
Weight::from_parts(29_000_000, 0)
.saturating_add(Weight::from_parts(0, 4928))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
Expand Down Expand Up @@ -131,8 +131,8 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `1951`
// Estimated: `6248`
// Minimum execution time: 65_000_000 picoseconds.
Weight::from_parts(66_000_000, 0)
// Minimum execution time: 64_000_000 picoseconds.
Weight::from_parts(70_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 @@ -145,7 +145,7 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
// Proof Size summary in bytes:
// Measured: `353`
// Estimated: `3818`
// Minimum execution time: 11_000_000 picoseconds.
// Minimum execution time: 10_000_000 picoseconds.
Weight::from_parts(11_000_000, 0)
.saturating_add(Weight::from_parts(0, 3818))
.saturating_add(T::DbWeight::get().reads(1))
Expand All @@ -155,12 +155,13 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
/// 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`)
fn confirm_key_reshare_confirmed() -> Weight {
/// The range of component `c` is `[0, 2]`.
fn confirm_key_reshare_confirmed(_c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `445`
// Estimated: `3910`
// Minimum execution time: 11_000_000 picoseconds.
Weight::from_parts(12_000_000, 0)
Weight::from_parts(11_916_666, 0)
.saturating_add(Weight::from_parts(0, 3910))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -181,22 +182,4 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `StakingExtension::SigningGroups` (r:2 w:2)
/// Proof: `StakingExtension::SigningGroups` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[0, 1000]`.
/// The range of component `n` is `[0, 1000]`.
fn new_session_handler_helper(c: u32, n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `218 + c * (32 ±0)`
// Estimated: `6156 + c * (32 ±0)`
// Minimum execution time: 20_000_000 picoseconds.
Weight::from_parts(20_000_000, 6156)
// Standard Error: 24_941
.saturating_add(Weight::from_parts(798_680, 0).saturating_mul(c.into()))
// Standard Error: 24_941
.saturating_add(Weight::from_parts(821_922, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
.saturating_add(Weight::from_parts(0, 32).saturating_mul(c.into()))
}
}

0 comments on commit 0e41d56

Please sign in to comment.