From 56e69fb36b5b832db7d372ee01a0869e397e6cfd Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Fri, 16 Aug 2024 14:28:40 -0400 Subject: [PATCH 1/2] Add benchmarks to pallet propgation --- pallets/propagation/src/benchmarking.rs | 29 +++++-- pallets/propagation/src/lib.rs | 10 ++- pallets/propagation/src/weights.rs | 93 +++++++++++++++++++++++ runtime/Cargo.toml | 1 + runtime/src/lib.rs | 2 + runtime/src/weights/mod.rs | 1 + runtime/src/weights/pallet_propagation.rs | 62 +++++++++++++++ 7 files changed, 189 insertions(+), 9 deletions(-) create mode 100644 pallets/propagation/src/weights.rs create mode 100644 runtime/src/weights/pallet_propagation.rs diff --git a/pallets/propagation/src/benchmarking.rs b/pallets/propagation/src/benchmarking.rs index 47ffabfa8..d04785cd2 100644 --- a/pallets/propagation/src/benchmarking.rs +++ b/pallets/propagation/src/benchmarking.rs @@ -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; -// } + >::put(RefreshInfo { + validators_info: vec![], + proactive_refresh_keys: vec![vec![10]] + }); + }: { + Propgation::::on_initialize(block_number.into()); + } verify { + assert_eq!(>::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); +} diff --git a/pallets/propagation/src/lib.rs b/pallets/propagation/src/lib.rs index 99062ca39..dcfb9f53d 100644 --- a/pallets/propagation/src/lib.rs +++ b/pallets/propagation/src/lib.rs @@ -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, @@ -49,6 +55,8 @@ pub mod pallet { + pallet_staking_extension::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The weight information of this pallet. + type WeightInfo: WeightInfo; } #[pallet::pallet] @@ -66,7 +74,7 @@ pub mod pallet { fn on_initialize(block_number: BlockNumberFor) -> Weight { pallet_registry::Dkg::::remove(block_number.saturating_sub(2u32.into())); pallet_staking_extension::ProactiveRefresh::::take(); - T::DbWeight::get().writes(2) + ::WeightInfo::on_initialize() } } diff --git a/pallets/propagation/src/weights.rs b/pallets/propagation/src/weights.rs new file mode 100644 index 000000000..174e0c991 --- /dev/null +++ b/pallets/propagation/src/weights.rs @@ -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 . + + +//! 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: `` +//! 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(PhantomData); +impl WeightInfo for SubstrateWeight { + /// 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)) + } +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 869769e5c..9ba99f073 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -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", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5cb70651c..779176a59 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -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; } impl pallet_parameters::Config for Runtime { @@ -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] diff --git a/runtime/src/weights/mod.rs b/runtime/src/weights/mod.rs index 8b73af704..f260ccb1b 100644 --- a/runtime/src/weights/mod.rs +++ b/runtime/src/weights/mod.rs @@ -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; diff --git a/runtime/src/weights/pallet_propagation.rs b/runtime/src/weights/pallet_propagation.rs new file mode 100644 index 000000000..784e2df21 --- /dev/null +++ b/runtime/src/weights/pallet_propagation.rs @@ -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 . + +//! 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: `` +//! 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(PhantomData); +impl pallet_propagation::WeightInfo for WeightInfo { + /// 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)) + } +} From 7e7de81b3056999955b88da10e059d57b1834fc4 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Mon, 19 Aug 2024 10:49:12 -0400 Subject: [PATCH 2/2] fix build --- pallets/propagation/src/mock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/propagation/src/mock.rs b/pallets/propagation/src/mock.rs index 0c02d2f76..f0f983106 100644 --- a/pallets/propagation/src/mock.rs +++ b/pallets/propagation/src/mock.rs @@ -359,6 +359,7 @@ impl pallet_programs::Config for Test { impl pallet_propagation::Config for Test { type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); } impl pallet_parameters::Config for Test {