Skip to content

Commit

Permalink
chore: run benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
devwckd committed Jan 3, 2025
1 parent 750b36f commit a387838
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 140 deletions.
8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ gen-spec-file env: gen-base-spec

run-benchmarks:
cargo build -r --features runtime-benchmarks
. /target/release/node-subspace build-spec --disable-default-bootnode --chain local > specs/benchmarks.json
./target/release/node-subspace benchmark pallet --chain specs/local.json --pallet pallet_torus0 --extrinsic "*" --steps 50 --repeat 20 --output pallets/torus0/src/weights.rs --template=./.maintain/frame-weight-template.hbs
./target/release/node-subspace benchmark pallet --chain specs/local.json --pallet pallet_governance --extrinsic "*" --steps 50 --repeat 20 --output pallets/governance/src/weights.rs --template=./.maintain/frame-weight-template.hbs
./target/release/node-subspace benchmark pallet --chain specs/local.json --pallet pallet_emission0 --extrinsic "*" --steps 50 --repeat 20 --output pallets/emission0/src/weights.rs --template=./.maintain/frame-weight-template.hbs
./target/release/torus-node build-spec --disable-default-bootnode --chain dev > specs/benchmarks.json
# ./target/release/torus-node benchmark pallet --pallet pallet_torus0 --chain dev --extrinsic "*" --steps 50 --repeat 20 --output pallets/torus0/src/weights.rs --template=./.maintain/frame-weight-template.hbs
./target/release/torus-node benchmark pallet --pallet pallet_governance --chain dev --extrinsic "*" --steps 50 --repeat 20 --output pallets/governance/src/weights.rs --template=./.maintain/frame-weight-template.hbs
./target/release/torus-node benchmark pallet --pallet pallet_emission0 --chain dev --extrinsic "*" --steps 50 --repeat 20 --output pallets/emission0/src/weights.rs --template=./.maintain/frame-weight-template.hbs


# Github Actions
Expand Down
3 changes: 3 additions & 0 deletions pallets/emission0/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pallet_governance_api::GovernanceApi;
use pallet_torus0_api::Torus0Api;
use polkadot_sdk::{
frame_benchmarking::{account, benchmarks},
Expand All @@ -12,6 +13,8 @@ benchmarks! {
let module_key: T::AccountId = account("ModuleKey", 0, 2);
let module_key2: T::AccountId = account("ModuleKey2", 0, 3);

<T::Governance>::set_allocator(&module_key2);

<T::Torus>::force_register_agent(&module_key, vec![], vec![], vec![])?;
<T::Torus>::force_register_agent(&module_key2, vec![], vec![], vec![])?;

Expand Down
46 changes: 27 additions & 19 deletions pallets/emission0/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0
//! DATE: 2025-01-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Luizs-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! HOSTNAME: `MacBook-Pro-de-Joao.local`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
// Executed Command:
// ./target/release/torus-node
// benchmark
// pallet
// --chain
// dev
// --pallet
// pallet_emission0
// --chain
// dev
// --extrinsic
// *
// --steps
Expand Down Expand Up @@ -46,8 +46,12 @@ pub trait WeightInfo {
/// Weights for `pallet_emission0` using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: `Governance::Allocators` (r:1 w:0)
/// Proof: `Governance::Allocators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`)
/// Storage: `Emission0::MaxAllowedWeights` (r:1 w:0)
/// Proof: `Emission0::MaxAllowedWeights` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`)
/// Storage: `Emission0::WeightControlDelegation` (r:1 w:0)
/// Proof: `Emission0::WeightControlDelegation` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`)
/// Storage: `Torus0::Agents` (r:2 w:0)
/// Proof: `Torus0::Agents` (`max_values`: None, `max_size`: Some(849), added: 3324, mode: `MaxEncodedLen`)
/// Storage: `Torus0::StakedBy` (r:1 w:0)
Expand All @@ -58,11 +62,11 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: `Emission0::ConsensusMembers` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`)
fn set_weights() -> Weight {
// Proof Size summary in bytes:
// Measured: `277`
// Measured: `339`
// Estimated: `7638`
// Minimum execution time: 18_000_000 picoseconds.
Weight::from_parts(20_000_000, 7638)
.saturating_add(T::DbWeight::get().reads(6_u64))
// Minimum execution time: 33_000_000 picoseconds.
Weight::from_parts(34_000_000, 7638)
.saturating_add(T::DbWeight::get().reads(8_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `Torus0::Agents` (r:2 w:0)
Expand All @@ -73,8 +77,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `168`
// Estimated: `7638`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(12_000_000, 7638)
// Minimum execution time: 17_000_000 picoseconds.
Weight::from_parts(18_000_000, 7638)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -84,17 +88,21 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `199`
// Estimated: `3529`
// Minimum execution time: 7_000_000 picoseconds.
Weight::from_parts(8_000_000, 3529)
// Minimum execution time: 10_000_000 picoseconds.
Weight::from_parts(11_000_000, 3529)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests.
impl WeightInfo for () {
/// Storage: `Governance::Allocators` (r:1 w:0)
/// Proof: `Governance::Allocators` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`)
/// Storage: `Emission0::MaxAllowedWeights` (r:1 w:0)
/// Proof: `Emission0::MaxAllowedWeights` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`)
/// Storage: `Emission0::WeightControlDelegation` (r:1 w:0)
/// Proof: `Emission0::WeightControlDelegation` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`)
/// Storage: `Torus0::Agents` (r:2 w:0)
/// Proof: `Torus0::Agents` (`max_values`: None, `max_size`: Some(849), added: 3324, mode: `MaxEncodedLen`)
/// Storage: `Torus0::StakedBy` (r:1 w:0)
Expand All @@ -105,11 +113,11 @@ impl WeightInfo for () {
/// Proof: `Emission0::ConsensusMembers` (`max_values`: None, `max_size`: Some(4294967295), added: 2474, mode: `MaxEncodedLen`)
fn set_weights() -> Weight {
// Proof Size summary in bytes:
// Measured: `277`
// Measured: `339`
// Estimated: `7638`
// Minimum execution time: 18_000_000 picoseconds.
Weight::from_parts(20_000_000, 7638)
.saturating_add(RocksDbWeight::get().reads(6_u64))
// Minimum execution time: 33_000_000 picoseconds.
Weight::from_parts(34_000_000, 7638)
.saturating_add(RocksDbWeight::get().reads(8_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `Torus0::Agents` (r:2 w:0)
Expand All @@ -120,8 +128,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `168`
// Estimated: `7638`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(12_000_000, 7638)
// Minimum execution time: 17_000_000 picoseconds.
Weight::from_parts(18_000_000, 7638)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand All @@ -131,8 +139,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `199`
// Estimated: `3529`
// Minimum execution time: 7_000_000 picoseconds.
Weight::from_parts(8_000_000, 3529)
// Minimum execution time: 10_000_000 picoseconds.
Weight::from_parts(11_000_000, 3529)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand Down
2 changes: 2 additions & 0 deletions pallets/governance/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ pub trait GovernanceApi<AccountId> {
fn is_whitelisted(key: &AccountId) -> bool;

fn ensure_allocator(key: &AccountId) -> DispatchResult;

fn set_allocator(key: &AccountId);
}
5 changes: 3 additions & 2 deletions pallets/governance/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn create_application<T: Config>(module_key: &T::AccountId) {
let min_data_len = T::MinApplicationDataLength::get();
let data = vec![0; min_data_len as usize];

application::submit_application::<T>(module_key.clone(), module_key.clone(), data)
application::submit_application::<T>(module_key.clone(), module_key.clone(), data, false)
.expect("failed to submit application");
}

Expand Down Expand Up @@ -66,7 +66,7 @@ benchmarks! {

let min_data_len = T::MinApplicationDataLength::get();
let data = vec![0; min_data_len as usize];
}: _(RawOrigin::Signed(module_key.clone()), module_key.clone(), data)
}: _(RawOrigin::Signed(module_key.clone()), module_key.clone(), data, false)

accept_application {
let module_key: T::AccountId = account("ModuleKey", 0, 2);
Expand Down Expand Up @@ -196,6 +196,7 @@ benchmarks! {

add_emission_proposal {
let module_key: T::AccountId = account("ModuleKey", 0, 2);
let data = vec![0];

let config = crate::GlobalGovernanceConfig::<T>::get();
let cost = config.proposal_cost;
Expand Down
6 changes: 5 additions & 1 deletion pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub mod pallet {
}

#[pallet::call_index(17)]
#[pallet::weight(0)]
#[pallet::weight((<T as Config>::WeightInfo::add_emission_proposal(), DispatchClass::Normal, Pays::Yes))]
pub fn add_emission_proposal(
origin: OriginFor<T>,
recycling_percentage: Percent,
Expand Down Expand Up @@ -463,4 +463,8 @@ impl<T: Config> pallet_governance_api::GovernanceApi<T::AccountId> for Pallet<T>
fn ensure_allocator(key: &T::AccountId) -> DispatchResult {
crate::roles::ensure_allocator::<T>(key)
}

fn set_allocator(key: &T::AccountId) {
crate::Allocators::<T>::insert(key, ());
}
}
Loading

0 comments on commit a387838

Please sign in to comment.