Skip to content

Commit

Permalink
Add benchmarks to pallet propgation
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Aug 16, 2024
1 parent 685a1bb commit 56e69fb
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 9 deletions.
29 changes: 21 additions & 8 deletions pallets/propagation/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,28 @@

// //! Benchmarking setup for pallet-propgation

// use super::*;
use super::*;

// #[allow(unused)]
// use crate::Pallet as Template;
// use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
// use frame_system::RawOrigin;
#[allow(unused)]
use crate::Pallet as Propgation;
use frame_benchmarking::benchmarks;
use frame_support::traits::OnInitialize;
use pallet_staking_extension::RefreshInfo;
use scale_info::prelude::vec;

// benchmarks! {
benchmarks! {
on_initialize {
let block_number = 50u32;

// }
<pallet_staking_extension::ProactiveRefresh<T>>::put(RefreshInfo {
validators_info: vec![],
proactive_refresh_keys: vec![vec![10]]
});
}: {
Propgation::<T>::on_initialize(block_number.into());
} verify {
assert_eq!(<pallet_staking_extension::ProactiveRefresh<T>>::get().proactive_refresh_keys.len(), 0);
}

// impl_benchmark_test_suite!(Template, crate::mock::new_test_ext(), crate::mock::Test);
impl_benchmark_test_suite!(Propgation, crate::mock::new_test_ext(), crate::mock::Test);
}
10 changes: 9 additions & 1 deletion pallets/propagation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ mod mock;
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

pub mod weights;

#[frame_support::pallet]
pub mod pallet {
pub use crate::weights::WeightInfo;
use codec::Encode;
use entropy_shared::{
OcwMessageDkg, OcwMessageProactiveRefresh, OcwMessageReshare, ValidatorInfo,
Expand All @@ -49,6 +55,8 @@ pub mod pallet {
+ pallet_staking_extension::Config
{
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The weight information of this pallet.
type WeightInfo: WeightInfo;
}

#[pallet::pallet]
Expand All @@ -66,7 +74,7 @@ pub mod pallet {
fn on_initialize(block_number: BlockNumberFor<T>) -> Weight {
pallet_registry::Dkg::<T>::remove(block_number.saturating_sub(2u32.into()));
pallet_staking_extension::ProactiveRefresh::<T>::take();
T::DbWeight::get().writes(2)
<T as Config>::WeightInfo::on_initialize()
}
}

Expand Down
93 changes: 93 additions & 0 deletions pallets/propagation/src/weights.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (C) 2023 Entropy Cryptography Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.


//! Autogenerated weights for pallet_propagation
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-11-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `hcastano`, CPU: `<UNKNOWN>`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
// ./target/release/entropy
// benchmark
// pallet
// --chain
// dev
// --wasm-execution=compiled
// --pallet
// pallet_propagation
// --extrinsic
// *
// --steps
// 5
// --repeat
// 2
// --template
// .maintain/frame-weight-template.hbs
// --output
// pallets/propagation/src/weights.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;

/// Weight functions needed for pallet_propagation.
pub trait WeightInfo {
fn on_initialize() -> Weight;
}

/// Weights for pallet_propagation using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: `StakingExtension::ProactiveRefresh` (r:1 w:1)
/// Proof: `StakingExtension::ProactiveRefresh` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Registry::Dkg` (r:0 w:1)
/// Proof: `Registry::Dkg` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn on_initialize() -> Weight {
// Proof Size summary in bytes:
// Measured: `148`
// Estimated: `1633`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(5_000_000, 0)
.saturating_add(Weight::from_parts(0, 1633))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(2))
}
}

// For backwards compatibility and tests
impl WeightInfo for () {
/// Storage: `StakingExtension::ProactiveRefresh` (r:1 w:1)
/// Proof: `StakingExtension::ProactiveRefresh` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Registry::Dkg` (r:0 w:1)
/// Proof: `Registry::Dkg` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn on_initialize() -> Weight {
// Proof Size summary in bytes:
// Measured: `148`
// Estimated: `1633`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(5_000_000, 0)
.saturating_add(Weight::from_parts(0, 1633))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(2))
}
}
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ runtime-benchmarks=[
"pallet-offences-benchmarking/runtime-benchmarks",
"pallet-oracle/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-propagation/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-programs/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,7 @@ impl pallet_transaction_pause::Config for Runtime {

impl pallet_propagation::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_propagation::WeightInfo<Runtime>;
}

impl pallet_parameters::Config for Runtime {
Expand Down Expand Up @@ -1637,6 +1638,7 @@ mod benches {
[pallet_oracle, Oracle]
[pallet_preimage, Preimage]
[pallet_parameters, Parameters]
[pallet_propagation, Propagation]
[pallet_proxy, Proxy]
[pallet_recovery, Recovery]
[pallet_registry, Registry]
Expand Down
1 change: 1 addition & 0 deletions runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub mod pallet_oracle;
pub mod pallet_parameters;
pub mod pallet_preimage;
pub mod pallet_programs;
pub mod pallet_propagation;
pub mod pallet_proxy;
pub mod pallet_recovery;
pub mod pallet_registry;
Expand Down
62 changes: 62 additions & 0 deletions runtime/src/weights/pallet_propagation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (C) 2023 Entropy Cryptography Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Autogenerated weights for `pallet_propagation`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 33.0.0
//! DATE: 2024-08-16, 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

// Executed Command:
// ./target/release/entropy
// benchmark
// pallet
// --chain
// dev
// --pallet=pallet_propagation
// --extrinsic=*
// --steps=5
// --repeat=2
// --header=.maintain/AGPL-3.0-header.txt
// --output=./runtime/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;

/// Weight functions for `pallet_propagation`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_propagation::WeightInfo for WeightInfo<T> {
/// Storage: `StakingExtension::ProactiveRefresh` (r:1 w:1)
/// Proof: `StakingExtension::ProactiveRefresh` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `Registry::Dkg` (r:0 w:1)
/// Proof: `Registry::Dkg` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn on_initialize() -> Weight {
// Proof Size summary in bytes:
// Measured: `148`
// Estimated: `1633`
// Minimum execution time: 4_000_000 picoseconds.
Weight::from_parts(5_000_000, 0)
.saturating_add(Weight::from_parts(0, 1633))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(2))
}
}

0 comments on commit 56e69fb

Please sign in to comment.