diff --git a/pallets/staking/src/benchmarking.rs b/pallets/staking/src/benchmarking.rs index ab7535ec5..d03baf608 100644 --- a/pallets/staking/src/benchmarking.rs +++ b/pallets/staking/src/benchmarking.rs @@ -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, @@ -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 = ::ValidatorId::try_from(caller.clone()).or(Err(Error::::InvalidValidatorId)).unwrap(); let second_signer: T::AccountId = account("second_signer", 0, SEED); let second_signer_id = ::ValidatorId::try_from(second_signer.clone()).or(Err(Error::::InvalidValidatorId)).unwrap(); ThresholdToStash::::insert(caller.clone(), validator_id_res.clone()); - Signers::::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::::put(signers.clone()); + NextSigners::::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())) @@ -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 = ::ValidatorId::try_from(caller.clone()).or(Err(Error::::InvalidValidatorId)).unwrap(); let second_signer: T::AccountId = account("second_signer", 0, SEED); let second_signer_id = ::ValidatorId::try_from(second_signer.clone()).or(Err(Error::::InvalidValidatorId)).unwrap(); ThresholdToStash::::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::::put(signers.clone()); NextSigners::::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())) diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index 9c66f2ebe..ddc0ee4fb 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -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::*, @@ -420,7 +420,7 @@ pub mod pallet { #[pallet::call_index(5)] #[pallet::weight({ - ::WeightInfo::confirm_key_reshare_confirmed() + ::WeightInfo::confirm_key_reshare_confirmed(SIGNING_PARTY_SIZE as u32) .max(::WeightInfo::confirm_key_reshare_completed()) })] pub fn confirm_key_reshare(origin: OriginFor) -> DispatchResultWithPostInfo { @@ -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::::put(signers_info.next_signers.clone()); Self::deposit_event(Event::SignersRotation(signers_info.next_signers)); - Ok(Some(::WeightInfo::confirm_key_reshare_confirmed()).into()) + Ok(Some(::WeightInfo::confirm_key_reshare_completed()).into()) } else { signers_info.confirmations.push(validator_stash.clone()); NextSigners::::put(signers_info); Self::deposit_event(Event::SignerConfirmed(validator_stash)); - Ok(Some(::WeightInfo::confirm_key_reshare_completed()).into()) + Ok(Some(::WeightInfo::confirm_key_reshare_confirmed( + current_signer_length as u32, + )) + .into()) } } } diff --git a/pallets/staking/src/weights.rs b/pallets/staking/src/weights.rs index b1318c9d9..a78e552f0 100644 --- a/pallets/staking/src/weights.rs +++ b/pallets/staking/src/weights.rs @@ -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; } @@ -160,34 +159,17 @@ impl WeightInfo for SubstrateWeight { .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)) @@ -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)) diff --git a/runtime/src/weights/pallet_staking_extension.rs b/runtime/src/weights/pallet_staking_extension.rs index 11e1cc5bb..87698051d 100644 --- a/runtime/src/weights/pallet_staking_extension.rs +++ b/runtime/src/weights/pallet_staking_extension.rs @@ -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: `` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -56,7 +56,7 @@ impl 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)) @@ -73,8 +73,8 @@ impl 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)) @@ -131,8 +131,8 @@ impl 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)) @@ -145,7 +145,7 @@ impl 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)) @@ -155,12 +155,13 @@ impl 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)) @@ -181,22 +182,4 @@ impl 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())) - } }