Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark for on_container_author_noted only #767

Merged
merged 12 commits into from
Dec 16, 2024
29 changes: 24 additions & 5 deletions pallets/author-noting/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use {
frame_system::RawOrigin,
parity_scale_codec::Encode,
sp_std::{boxed::Box, vec},
tp_traits::{GetContainerChainAuthor, GetCurrentContainerChains},
tp_traits::{AuthorNotingHook, GetContainerChainAuthor, GetCurrentContainerChains},
};

mod test_sproof {
Expand Down Expand Up @@ -60,11 +60,11 @@ benchmarks! {
let mut container_chains = vec![];

let data = if TypeId::of::<<<T as Config>::RelayOrPara as RelayOrPara>::InherentArg>() == TypeId::of::<tp_author_noting_inherent::OwnParachainInherentData>() {


// RELAY MODE
let mut sproof_builder = test_sproof::ParaHeaderSproofBuilder::default();

for para_id in 1..x {
// Must start at 0 in Relay mode (why?)
for para_id in 0..x {
let para_id = para_id.into();
container_chains.push(para_id);
// Mock assigned authors for this para id
Expand All @@ -73,8 +73,8 @@ benchmarks! {
let num_each_container_chain = 2;
T::ContainerChainAuthor::set_authors_for_para_id(para_id, vec![author; num_each_container_chain]);
sproof_builder.num_items += 1;
}

}
let (root, proof) = sproof_builder.into_state_root_and_proof();
T::RelayOrPara::set_current_relay_chain_state(cumulus_pallet_parachain_system::RelayChainState {
state_root: root,
Expand All @@ -85,9 +85,18 @@ benchmarks! {
relay_storage_proof: proof,
};

for para_id in 0..x {
let para_id = para_id.into();
let author: T::AccountId = account("account id", 0u32, 0u32);

T::AuthorNotingHook::prepare_worst_case_for_bench(&author, 1, para_id);
}

*(Box::new(arg) as Box<dyn Any>).downcast().unwrap()
} else if TypeId::of::<<<T as Config>::RelayOrPara as RelayOrPara>::InherentArg>() == TypeId::of::<()>() {
// PARA MODE

// Must start at 1 in Para mode (why?)
for para_id in 1..x {
let slot: crate::InherentType = 13u64.into();
let header = sp_runtime::generic::Header::<crate::BlockNumber, crate::BlakeTwo256> {
Expand All @@ -113,6 +122,8 @@ benchmarks! {

let head_data = HeadData(header.encode());
frame_support::storage::unhashed::put(&key, &head_data);

T::AuthorNotingHook::prepare_worst_case_for_bench(&author, 1, para_id);
}
let arg = ();
*(Box::new(arg) as Box<dyn Any>).downcast().unwrap()
Expand All @@ -137,6 +148,14 @@ benchmarks! {
assert_ok!(Pallet::<T>::set_author(RawOrigin::Root.into(), para_id, block_number, author, u64::from(block_number).into()));
}: _(RawOrigin::Root, para_id)

on_container_author_noted {
nanocryk marked this conversation as resolved.
Show resolved Hide resolved
let para_id = 1000.into();
let block_number = 1;
let author: T::AccountId = account("account id", 0u32, 0u32);

T::AuthorNotingHook::prepare_worst_case_for_bench(&author, block_number, para_id);
}: { T::AuthorNotingHook::on_container_author_noted(&author, block_number, para_id )}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
Expand Down
202 changes: 138 additions & 64 deletions pallets/author-noting/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

//! Autogenerated weights for pallet_author_noting
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-10-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0
//! DATE: 2024-12-11, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `tomasz-XPS-15-9520`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
//! HOSTNAME: `pop-os`, CPU: `12th Gen Intel(R) Core(TM) i7-1260P`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
// ./target/release/tanssi-node
Expand All @@ -33,15 +33,16 @@
// pallet_author_noting
// --extrinsic
// *
// --chain=dev
// --steps
// 50
// --repeat
// 20
// --template=./benchmarking/frame-weight-template.hbs
// --template=./benchmarking/frame-weight-pallet-template.hbs
// --json-file
// raw.json
// --output
// weights.rs
// tmp/dancebox_weights/pallet_author_noting.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
Expand All @@ -55,101 +56,174 @@ pub trait WeightInfo {
fn set_latest_author_data(x: u32, ) -> Weight;
fn set_author() -> Weight;
fn kill_author_data() -> Weight;
fn on_container_author_noted() -> Weight;
}

/// Weights for pallet_author_noting using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: AuthorNoting DidSetContainerAuthorData (r:1 w:1)
/// Proof: AuthorNoting DidSetContainerAuthorData (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: Registrar RegisteredParaIds (r:1 w:0)
/// Proof Skipped: Registrar RegisteredParaIds (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: ParachainSystem ValidationData (r:1 w:0)
/// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: CollatorAssignment CollatorContainerChain (r:1 w:0)
/// Proof Skipped: CollatorAssignment CollatorContainerChain (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: AuthorNoting LatestAuthor (r:0 w:100)
/// Proof: AuthorNoting LatestAuthor (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
/// The range of component `x` is `[0, 100]`.
/// Storage: `AuthorNoting::DidSetContainerAuthorData` (r:1 w:1)
/// Proof: `AuthorNoting::DidSetContainerAuthorData` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
/// Storage: `Registrar::RegisteredParaIds` (r:1 w:0)
/// Proof: `Registrar::RegisteredParaIds` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`)
/// Storage: `ParachainSystem::ValidationData` (r:1 w:0)
/// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `System::Digest` (r:1 w:0)
/// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `CollatorAssignment::CollatorContainerChain` (r:1 w:0)
/// Proof: `CollatorAssignment::CollatorContainerChain` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `AuthorNoting::LatestAuthor` (r:100 w:100)
/// Proof: `AuthorNoting::LatestAuthor` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`)
/// Storage: `InflationRewards::ChainsToReward` (r:1 w:1)
/// Proof: `InflationRewards::ChainsToReward` (`max_values`: Some(1), `max_size`: Some(418), added: 913, mode: `MaxEncodedLen`)
/// Storage: `ServicesPayment::BlockProductionCredits` (r:100 w:0)
/// Proof: `ServicesPayment::BlockProductionCredits` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:103 w:102)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Invulnerables::Invulnerables` (r:1 w:0)
/// Proof: `Invulnerables::Invulnerables` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`)
/// Storage: `PooledStaking::Pools` (r:2 w:0)
/// Proof: `PooledStaking::Pools` (`max_values`: None, `max_size`: Some(113), added: 2588, mode: `MaxEncodedLen`)
/// Storage: `XcmCoreBuyer::PendingBlocks` (r:0 w:100)
/// Proof: `XcmCoreBuyer::PendingBlocks` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 100]`.
fn set_latest_author_data(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `427 + x * (73 ±0)`
// Estimated: `1912 + x * (73 ±0)`
// Minimum execution time: 7_767_000 picoseconds.
Weight::from_parts(7_985_000, 1912)
// Standard Error: 125_649
.saturating_add(Weight::from_parts(19_274_325, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into())))
.saturating_add(Weight::from_parts(0, 73).saturating_mul(x.into()))
// Measured: `1015 + x * (208 ±0)`
// Estimated: `8799 + x * (2603 ±0)`
// Minimum execution time: 122_225_000 picoseconds.
Weight::from_parts(123_639_000, 8799)
// Standard Error: 128_105
.saturating_add(Weight::from_parts(36_913_982, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(12_u64))
.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(x.into())))
.saturating_add(T::DbWeight::get().writes(4_u64))
.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(x.into())))
.saturating_add(Weight::from_parts(0, 2603).saturating_mul(x.into()))
}
/// Storage: AuthorNoting LatestAuthor (r:0 w:1)
/// Proof: AuthorNoting LatestAuthor (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
/// Storage: `AuthorNoting::LatestAuthor` (r:0 w:1)
/// Proof: `AuthorNoting::LatestAuthor` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`)
fn set_author() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 7_877_000 picoseconds.
Weight::from_parts(8_127_000, 0)
// Minimum execution time: 5_776_000 picoseconds.
Weight::from_parts(6_057_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: AuthorNoting LatestAuthor (r:0 w:1)
/// Proof: AuthorNoting LatestAuthor (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
/// Storage: `AuthorNoting::LatestAuthor` (r:0 w:1)
/// Proof: `AuthorNoting::LatestAuthor` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`)
fn kill_author_data() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 7_190_000 picoseconds.
Weight::from_parts(7_520_000, 0)
// Minimum execution time: 5_542_000 picoseconds.
Weight::from_parts(5_844_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `InflationRewards::ChainsToReward` (r:1 w:1)
/// Proof: `InflationRewards::ChainsToReward` (`max_values`: Some(1), `max_size`: Some(418), added: 913, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:4 w:3)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Invulnerables::Invulnerables` (r:1 w:0)
/// Proof: `Invulnerables::Invulnerables` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`)
/// Storage: `PooledStaking::Pools` (r:2 w:0)
/// Proof: `PooledStaking::Pools` (`max_values`: None, `max_size`: Some(113), added: 2588, mode: `MaxEncodedLen`)
/// Storage: `ServicesPayment::BlockProductionCredits` (r:1 w:0)
/// Proof: `ServicesPayment::BlockProductionCredits` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`)
/// Storage: `XcmCoreBuyer::PendingBlocks` (r:0 w:1)
/// Proof: `XcmCoreBuyer::PendingBlocks` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`)
fn on_container_author_noted() -> Weight {
// Proof Size summary in bytes:
// Measured: `881`
// Estimated: `11402`
// Minimum execution time: 92_792_000 picoseconds.
Weight::from_parts(99_983_000, 11402)
.saturating_add(T::DbWeight::get().reads(9_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
}

// For backwards compatibility and tests
impl WeightInfo for () {
/// Storage: AuthorNoting DidSetContainerAuthorData (r:1 w:1)
/// Proof: AuthorNoting DidSetContainerAuthorData (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: Registrar RegisteredParaIds (r:1 w:0)
/// Proof Skipped: Registrar RegisteredParaIds (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: ParachainSystem ValidationData (r:1 w:0)
/// Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: CollatorAssignment CollatorContainerChain (r:1 w:0)
/// Proof Skipped: CollatorAssignment CollatorContainerChain (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: AuthorNoting LatestAuthor (r:0 w:100)
/// Proof: AuthorNoting LatestAuthor (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
/// The range of component `x` is `[0, 100]`.
/// Storage: `AuthorNoting::DidSetContainerAuthorData` (r:1 w:1)
/// Proof: `AuthorNoting::DidSetContainerAuthorData` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
/// Storage: `Registrar::RegisteredParaIds` (r:1 w:0)
/// Proof: `Registrar::RegisteredParaIds` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`)
/// Storage: `ParachainSystem::ValidationData` (r:1 w:0)
/// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `System::Digest` (r:1 w:0)
/// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `CollatorAssignment::CollatorContainerChain` (r:1 w:0)
/// Proof: `CollatorAssignment::CollatorContainerChain` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `AuthorNoting::LatestAuthor` (r:100 w:100)
/// Proof: `AuthorNoting::LatestAuthor` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`)
/// Storage: `InflationRewards::ChainsToReward` (r:1 w:1)
/// Proof: `InflationRewards::ChainsToReward` (`max_values`: Some(1), `max_size`: Some(418), added: 913, mode: `MaxEncodedLen`)
/// Storage: `ServicesPayment::BlockProductionCredits` (r:100 w:0)
/// Proof: `ServicesPayment::BlockProductionCredits` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:103 w:102)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Invulnerables::Invulnerables` (r:1 w:0)
/// Proof: `Invulnerables::Invulnerables` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`)
/// Storage: `PooledStaking::Pools` (r:2 w:0)
/// Proof: `PooledStaking::Pools` (`max_values`: None, `max_size`: Some(113), added: 2588, mode: `MaxEncodedLen`)
/// Storage: `XcmCoreBuyer::PendingBlocks` (r:0 w:100)
/// Proof: `XcmCoreBuyer::PendingBlocks` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 100]`.
fn set_latest_author_data(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `427 + x * (73 ±0)`
// Estimated: `1912 + x * (73 ±0)`
// Minimum execution time: 7_767_000 picoseconds.
Weight::from_parts(7_985_000, 1912)
// Standard Error: 125_649
.saturating_add(Weight::from_parts(19_274_325, 0).saturating_mul(x.into()))
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(x.into())))
.saturating_add(Weight::from_parts(0, 73).saturating_mul(x.into()))
// Measured: `1015 + x * (208 ±0)`
// Estimated: `8799 + x * (2603 ±0)`
// Minimum execution time: 122_225_000 picoseconds.
Weight::from_parts(123_639_000, 8799)
// Standard Error: 128_105
.saturating_add(Weight::from_parts(36_913_982, 0).saturating_mul(x.into()))
.saturating_add(RocksDbWeight::get().reads(12_u64))
.saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(x.into())))
.saturating_add(RocksDbWeight::get().writes(4_u64))
.saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(x.into())))
.saturating_add(Weight::from_parts(0, 2603).saturating_mul(x.into()))
}
/// Storage: AuthorNoting LatestAuthor (r:0 w:1)
/// Proof: AuthorNoting LatestAuthor (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
/// Storage: `AuthorNoting::LatestAuthor` (r:0 w:1)
/// Proof: `AuthorNoting::LatestAuthor` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`)
fn set_author() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 7_877_000 picoseconds.
Weight::from_parts(8_127_000, 0)
// Minimum execution time: 5_776_000 picoseconds.
Weight::from_parts(6_057_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: AuthorNoting LatestAuthor (r:0 w:1)
/// Proof: AuthorNoting LatestAuthor (max_values: None, max_size: Some(56), added: 2531, mode: MaxEncodedLen)
/// Storage: `AuthorNoting::LatestAuthor` (r:0 w:1)
/// Proof: `AuthorNoting::LatestAuthor` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`)
fn kill_author_data() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 7_190_000 picoseconds.
Weight::from_parts(7_520_000, 0)
// Minimum execution time: 5_542_000 picoseconds.
Weight::from_parts(5_844_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `InflationRewards::ChainsToReward` (r:1 w:1)
/// Proof: `InflationRewards::ChainsToReward` (`max_values`: Some(1), `max_size`: Some(418), added: 913, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:4 w:3)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Invulnerables::Invulnerables` (r:1 w:0)
/// Proof: `Invulnerables::Invulnerables` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`)
/// Storage: `PooledStaking::Pools` (r:2 w:0)
/// Proof: `PooledStaking::Pools` (`max_values`: None, `max_size`: Some(113), added: 2588, mode: `MaxEncodedLen`)
/// Storage: `ServicesPayment::BlockProductionCredits` (r:1 w:0)
/// Proof: `ServicesPayment::BlockProductionCredits` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`)
/// Storage: `XcmCoreBuyer::PendingBlocks` (r:0 w:1)
/// Proof: `XcmCoreBuyer::PendingBlocks` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`)
fn on_container_author_noted() -> Weight {
// Proof Size summary in bytes:
// Measured: `881`
// Estimated: `11402`
// Minimum execution time: 92_792_000 picoseconds.
Weight::from_parts(99_983_000, 11402)
.saturating_add(RocksDbWeight::get().reads(9_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
}
19 changes: 19 additions & 0 deletions pallets/inflation-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,23 @@ impl<T: Config> AuthorNotingHook<T::AccountId> for Pallet<T> {
}
total_weight
}

#[cfg(feature = "runtime-benchmarks")]
fn prepare_worst_case_for_bench(_a: &T::AccountId, _b: BlockNumber, para_id: ParaId) {
// arbitrary amount to perform rewarding
// we mint twice as much to the rewards account to make it possible
let reward_amount = 1_000_000_000u32;
let mint = reward_amount * 2;

T::Currency::resolve(
&T::PendingRewardsAccount::get(),
T::Currency::issue(BalanceOf::<T>::from(mint)),
)
.expect("to mint tokens");

ChainsToReward::<T>::put(ChainsToRewardValue {
para_ids: sp_std::vec![para_id].try_into().expect("to be in bound"),
rewards_per_chain: BalanceOf::<T>::from(reward_amount),
});
}
}
Loading
Loading