From 3396ba9d6b939f3475167336a3b42fb97ab2a5c4 Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:58:54 +0100 Subject: [PATCH] run bench locally --- .../pallet_external_validator_slashes.rs | 33 ++++++++++ .../src/benchmarking.rs | 8 +-- pallets/external-validator-slashes/src/lib.rs | 15 ++--- .../external-validator-slashes/src/tests.rs | 6 +- .../external-validator-slashes/src/weights.rs | 65 +++++++++++++++++++ 5 files changed, 110 insertions(+), 17 deletions(-) diff --git a/chains/orchestrator-relays/runtime/dancelight/src/weights/pallet_external_validator_slashes.rs b/chains/orchestrator-relays/runtime/dancelight/src/weights/pallet_external_validator_slashes.rs index 31c33b6eb..daee2f2f8 100644 --- a/chains/orchestrator-relays/runtime/dancelight/src/weights/pallet_external_validator_slashes.rs +++ b/chains/orchestrator-relays/runtime/dancelight/src/weights/pallet_external_validator_slashes.rs @@ -108,4 +108,37 @@ impl pallet_external_validator_slashes::WeightInfo for .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } + + + /// Storage: `ExternalValidators::ActiveEra` (r:1 w:0) + /// Proof: `ExternalValidators::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`) + /// Storage: `ExternalValidatorSlashes::UnreportedSlashesQueue` (r:1 w:1) + /// Proof: `ExternalValidatorSlashes::UnreportedSlashesQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `EthereumSystem::Channels` (r:1 w:0) + /// Proof: `EthereumSystem::Channels` (`max_values`: None, `max_size`: Some(76), added: 2551, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::BookStateFor` (r:1 w:1) + /// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(136), added: 2611, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::ServiceHead` (r:1 w:1) + /// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(33), added: 528, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x3a72656c61795f64697370617463685f71756575655f72656d61696e696e675f` (r:0 w:1) + /// Proof: UNKNOWN KEY `0x3a72656c61795f64697370617463685f71756575655f72656d61696e696e675f` (r:0 w:1) + /// Storage: `MessageQueue::Pages` (r:0 w:1) + /// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(32845), added: 35320, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1) + /// Proof: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1) + /// The range of component `s` is `[1, 200]`. + fn process_slashes_queue(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `393 + s * (42 ±0)` + // Estimated: `3601 + s * (42 ±0)` + // Minimum execution time: 46_622_000 picoseconds. + Weight::from_parts(72_326_163, 3601) + // Standard Error: 58_929 + .saturating_add(Weight::from_parts(2_894_084, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 42).saturating_mul(s.into())) + } } \ No newline at end of file diff --git a/pallets/external-validator-slashes/src/benchmarking.rs b/pallets/external-validator-slashes/src/benchmarking.rs index 03c052750..2d1430246 100644 --- a/pallets/external-validator-slashes/src/benchmarking.rs +++ b/pallets/external-validator-slashes/src/benchmarking.rs @@ -104,8 +104,8 @@ mod benchmarks { fn process_slashes_queue(s: Linear<1, 200>) -> Result<(), BenchmarkError> { let mut queue = VecDeque::new(); let dummy = || T::AccountId::decode(&mut TrailingZeroInput::zeroes()).unwrap(); - - for _ in 0..(s+1) { + + for _ in 0..(s + 1) { queue.push_back(Slash::::default_from(dummy())); } @@ -115,11 +115,11 @@ mod benchmarks { #[block] { - processed = Pallet::::process_slashes_queue(s as usize); + processed = Pallet::::process_slashes_queue(s); } assert_eq!(UnreportedSlashesQueue::::get().len(), 1); - assert_eq!(processed, s as usize); + assert_eq!(processed, s); Ok(()) } diff --git a/pallets/external-validator-slashes/src/lib.rs b/pallets/external-validator-slashes/src/lib.rs index 08919ab01..26fc6300e 100644 --- a/pallets/external-validator-slashes/src/lib.rs +++ b/pallets/external-validator-slashes/src/lib.rs @@ -347,13 +347,8 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(_n: BlockNumberFor) -> Weight { - let weight = Weight::zero(); - - let processed = Self::process_slashes_queue(T::QueuedSlashesProcessedPerBlock::get() as usize); - - // TODO: Weight - - weight + let processed = Self::process_slashes_queue(T::QueuedSlashesProcessedPerBlock::get()); + T::WeightInfo::process_slashes_queue(processed) } } } @@ -522,7 +517,7 @@ impl Pallet { UnreportedSlashesQueue::::mutate(|queue| queue.append(&mut slashes)); } - fn process_slashes_queue(amount: usize) -> usize { + fn process_slashes_queue(amount: u32) -> u32 { let mut slashes_to_send: Vec<_> = vec![]; let era_index = T::EraIndexProvider::active_era().index; @@ -533,7 +528,7 @@ impl Pallet { // no more slashes to process in the queue break; }; - + // TODO: check if validator.clone().encode() matches with the actual account bytes. slashes_to_send.push(( slash.validator.clone().encode(), @@ -546,7 +541,7 @@ impl Pallet { return 0; } - let slashes_count = slashes_to_send.len(); + let slashes_count = slashes_to_send.len() as u32; // Build command with slashes. let command = Command::ReportSlashes { diff --git a/pallets/external-validator-slashes/src/tests.rs b/pallets/external-validator-slashes/src/tests.rs index be756ef94..b84a7f9bf 100644 --- a/pallets/external-validator-slashes/src/tests.rs +++ b/pallets/external-validator-slashes/src/tests.rs @@ -17,7 +17,8 @@ use { super::*, crate::mock::{ - new_test_ext, sent_ethereum_message_nonce, DeferPeriodGetter, ExternalValidatorSlashes, roll_one_block, Test, RuntimeOrigin + new_test_ext, roll_one_block, sent_ethereum_message_nonce, DeferPeriodGetter, + ExternalValidatorSlashes, RuntimeOrigin, Test, }, frame_support::{assert_noop, assert_ok}, mock::MockEraIndexProvider, @@ -353,7 +354,7 @@ fn test_on_offence_defer_period_0_messages_get_queued_across_eras() { 2, ); } - + start_era(3, 3); assert_eq!(UnreportedSlashesQueue::::get().len(), 30); @@ -366,7 +367,6 @@ fn test_on_offence_defer_period_0_messages_get_queued_across_eras() { roll_one_block(); assert_eq!(UnreportedSlashesQueue::::get().len(), 0); assert_eq!(sent_ethereum_message_nonce(), 3); - }); } diff --git a/pallets/external-validator-slashes/src/weights.rs b/pallets/external-validator-slashes/src/weights.rs index 0f947248f..83317165f 100644 --- a/pallets/external-validator-slashes/src/weights.rs +++ b/pallets/external-validator-slashes/src/weights.rs @@ -56,6 +56,7 @@ pub trait WeightInfo { fn cancel_deferred_slash(s: u32, ) -> Weight; fn force_inject_slash() -> Weight; fn root_test_send_msg_to_eth() -> Weight; + fn process_slashes_queue(s: u32, ) -> Weight; } /// Weights for pallet_external_validator_slashes using the Substrate node and recommended hardware. @@ -102,6 +103,37 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } + /// Storage: `ExternalValidators::ActiveEra` (r:1 w:0) + /// Proof: `ExternalValidators::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`) + /// Storage: `ExternalValidatorSlashes::UnreportedSlashesQueue` (r:1 w:1) + /// Proof: `ExternalValidatorSlashes::UnreportedSlashesQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `EthereumSystem::Channels` (r:1 w:0) + /// Proof: `EthereumSystem::Channels` (`max_values`: None, `max_size`: Some(76), added: 2551, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::BookStateFor` (r:1 w:1) + /// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(136), added: 2611, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::ServiceHead` (r:1 w:1) + /// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(33), added: 528, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x3a72656c61795f64697370617463685f71756575655f72656d61696e696e675f` (r:0 w:1) + /// Proof: UNKNOWN KEY `0x3a72656c61795f64697370617463685f71756575655f72656d61696e696e675f` (r:0 w:1) + /// Storage: `MessageQueue::Pages` (r:0 w:1) + /// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(32845), added: 35320, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1) + /// Proof: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1) + /// The range of component `s` is `[1, 200]`. + fn process_slashes_queue(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `393 + s * (42 ±0)` + // Estimated: `3601 + s * (42 ±0)` + // Minimum execution time: 46_622_000 picoseconds. + Weight::from_parts(72_326_163, 3601) + // Standard Error: 58_929 + .saturating_add(Weight::from_parts(2_894_084, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 42).saturating_mul(s.into())) + } } // For backwards compatibility and tests @@ -147,4 +179,37 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } + + + /// Storage: `ExternalValidators::ActiveEra` (r:1 w:0) + /// Proof: `ExternalValidators::ActiveEra` (`max_values`: Some(1), `max_size`: Some(13), added: 508, mode: `MaxEncodedLen`) + /// Storage: `ExternalValidatorSlashes::UnreportedSlashesQueue` (r:1 w:1) + /// Proof: `ExternalValidatorSlashes::UnreportedSlashesQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `EthereumSystem::Channels` (r:1 w:0) + /// Proof: `EthereumSystem::Channels` (`max_values`: None, `max_size`: Some(76), added: 2551, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::BookStateFor` (r:1 w:1) + /// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(136), added: 2611, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::ServiceHead` (r:1 w:1) + /// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(33), added: 528, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x3a72656c61795f64697370617463685f71756575655f72656d61696e696e675f` (r:0 w:1) + /// Proof: UNKNOWN KEY `0x3a72656c61795f64697370617463685f71756575655f72656d61696e696e675f` (r:0 w:1) + /// Storage: `MessageQueue::Pages` (r:0 w:1) + /// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(32845), added: 35320, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1) + /// Proof: UNKNOWN KEY `0xf5207f03cfdce586301014700e2c2593fad157e461d71fd4c1f936839a5f1f3e` (r:0 w:1) + /// The range of component `s` is `[1, 200]`. + fn process_slashes_queue(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `393 + s * (42 ±0)` + // Estimated: `3601 + s * (42 ±0)` + // Minimum execution time: 46_622_000 picoseconds. + Weight::from_parts(72_326_163, 3601) + // Standard Error: 58_929 + .saturating_add(Weight::from_parts(2_894_084, 0).saturating_mul(s.into())) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 42).saturating_mul(s.into())) + } }