Skip to content

Commit

Permalink
run bench locally
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Jan 9, 2025
1 parent ed91fc7 commit 3396ba9
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,37 @@ impl<T: frame_system::Config> 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()))
}
}
8 changes: 4 additions & 4 deletions pallets/external-validator-slashes/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T::AccountId, T::SlashId>::default_from(dummy()));
}

Expand All @@ -115,11 +115,11 @@ mod benchmarks {

#[block]
{
processed = Pallet::<T>::process_slashes_queue(s as usize);
processed = Pallet::<T>::process_slashes_queue(s);
}

assert_eq!(UnreportedSlashesQueue::<T>::get().len(), 1);
assert_eq!(processed, s as usize);
assert_eq!(processed, s);

Ok(())
}
Expand Down
15 changes: 5 additions & 10 deletions pallets/external-validator-slashes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,8 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_n: BlockNumberFor<T>) -> 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)
}
}
}
Expand Down Expand Up @@ -522,7 +517,7 @@ impl<T: Config> Pallet<T> {
UnreportedSlashesQueue::<T>::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;

Expand All @@ -533,7 +528,7 @@ impl<T: Config> Pallet<T> {
// 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(),
Expand All @@ -546,7 +541,7 @@ impl<T: Config> Pallet<T> {
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 {
Expand Down
6 changes: 3 additions & 3 deletions pallets/external-validator-slashes/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -353,7 +354,7 @@ fn test_on_offence_defer_period_0_messages_get_queued_across_eras() {
2,
);
}

start_era(3, 3);
assert_eq!(UnreportedSlashesQueue::<Test>::get().len(), 30);

Expand All @@ -366,7 +367,6 @@ fn test_on_offence_defer_period_0_messages_get_queued_across_eras() {
roll_one_block();
assert_eq!(UnreportedSlashesQueue::<Test>::get().len(), 0);
assert_eq!(sent_ethereum_message_nonce(), 3);

});
}

Expand Down
65 changes: 65 additions & 0 deletions pallets/external-validator-slashes/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -102,6 +103,37 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.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
Expand Down Expand Up @@ -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()))
}
}

0 comments on commit 3396ba9

Please sign in to comment.