Skip to content

Commit

Permalink
update benchmarking logic in cumulus
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes committed Oct 9, 2023
1 parent 5508ea9 commit 755b82a
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 64 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ snowbridge-outbound-queue = { path = "../../../../../parachain/pallets/outbound-
snowbridge-outbound-queue-runtime-api = { path = "../../../../../parachain/pallets/outbound-queue/runtime-api", default-features = false }
snowbridge-ethereum-beacon-client = { path = "../../../../../parachain/pallets/ethereum-beacon-client", default-features = false }
snowbridge-control = { path = "../../../../../parachain/pallets/control", default-features = false }
snowbridge-control-runtime-api = { path = "../../../../../parachain/pallets/control/runtime-api", default-features = false }



[dev-dependencies]
Expand Down Expand Up @@ -182,6 +184,7 @@ std = [
"snowbridge-outbound-queue-runtime-api/std",
"snowbridge-ethereum-beacon-client/std",
"snowbridge-control/std",
"snowbridge-control-runtime-api/std",
"substrate-wasm-builder",
]

Expand Down
23 changes: 19 additions & 4 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ use sp_version::RuntimeVersion;

use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
dispatch::DispatchClass,
traits::{ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Everything},
weights::{ConstantMultiplier, Weight},
PalletId,
Expand All @@ -71,9 +71,9 @@ use pallet_xcm::EnsureXcm;

pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm::v3::NetworkId::{self, Rococo};
use xcm::VersionedMultiLocation;
use xcm_config::{
EthereumGatewayAddress, RelayLocation, UniversalLocation, XcmConfig,
EthereumGatewayAddress, XcmConfig,
XcmOriginToTransactDispatchOrigin,
};

Expand Down Expand Up @@ -108,6 +108,7 @@ use parachains_common::{
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use snowbridge_core::AgentId;
use xcm_executor::XcmExecutor;

/// The address format for describing accounts.
Expand Down Expand Up @@ -684,6 +685,13 @@ parameter_types! {
pub TreasuryAccount: AccountId = PalletId(*b"py/trsry").into_account_truncating();
}

#[cfg(feature = "runtime-benchmarks")]
impl snowbridge_control::BenchmarkHelper<RuntimeOrigin> for () {
fn make_xcm_origin(location: xcm::latest::MultiLocation) -> RuntimeOrigin {
RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location))
}
}

impl snowbridge_control::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OwnParaId = ParachainInfo;
Expand All @@ -692,11 +700,12 @@ impl snowbridge_control::Config for Runtime {
type AgentOwnerOrigin = EnsureXcm<Everything>;
type ChannelOwnerOrigin = EnsureXcm<Everything>;
type AgentIdOf = xcm_config::AgentIdOf;
type SovereignAccountOf = xcm_config::SovereignAccountOf;
type TreasuryAccount = TreasuryAccount;
type Fee = ConstU128<100000000000>; //should be enough to cover the existentialDeposit
type Token = Balances;
type WeightInfo = weights::snowbridge_control::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand Down Expand Up @@ -1045,6 +1054,12 @@ impl_runtime_apis! {
}
}

impl snowbridge_control_runtime_api::ControlApi<Block> for Runtime {
fn agent_id(location: VersionedMultiLocation) -> Option<AgentId> {
snowbridge_control::api::agent_id::<Runtime>(location)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@
//! Autogenerated weights for `snowbridge_control`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-07-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-10-09, STEPS: `2`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `macbook pro 14 m2`, CPU: `m2-arm64`
//! HOSTNAME: `crake.local`, CPU: `<UNKNOWN>`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bridge-hub-rococo-dev"), DB CACHE: 1024

// Executed Command:
// target/release/polkadot-parachain
// benchmark
// pallet
// --chain=bridge-hub-rococo-dev
// --chain
// bridge-hub-rococo-dev
// --pallet=snowbridge_control
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --steps
// 50
// --repeat
// 20
// --output
// ./parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs
// parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
Expand All @@ -44,23 +41,22 @@ impl<T: frame_system::Config> snowbridge_control::WeightInfo for WeightInfo<T> {
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:0 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
/// The range of component `x` is `[0, 1023]`.
fn upgrade() -> Weight {
// Proof Size summary in bytes:
// Measured: `80`
// Estimated: `3517`
// Minimum execution time: 29_000_000 picoseconds.
Weight::from_parts(30_740_411, 0)
// Minimum execution time: 47_000_000 picoseconds.
Weight::from_parts(47_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
// Standard Error: 66
.saturating_add(Weight::from_parts(8_805, 0).saturating_mul(256))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: ParachainInfo ParachainId (r:1 w:0)
/// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: EthereumControl Agents (r:1 w:1)
/// Proof: EthereumControl Agents (max_values: None, max_size: Some(40), added: 2515, mode: MaxEncodedLen)
/// Storage: System Account (r:2 w:2)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: ParachainInfo ParachainId (r:1 w:0)
/// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: EthereumOutboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumOutboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:1 w:1)
Expand All @@ -71,57 +67,136 @@ impl<T: frame_system::Config> snowbridge_control::WeightInfo for WeightInfo<T> {
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
fn create_agent() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
// Measured: `187`
// Estimated: `6196`
// Minimum execution time: 87_000_000 picoseconds.
Weight::from_parts(87_000_000, 0)
.saturating_add(Weight::from_parts(0, 6196))
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(6))
}

/// Todo: update with benchmarked
/// Storage: System Account (r:2 w:2)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: EthereumControl Agents (r:1 w:0)
/// Proof: EthereumControl Agents (max_values: None, max_size: Some(40), added: 2515, mode: MaxEncodedLen)
/// Storage: EthereumControl Channels (r:1 w:1)
/// Proof: EthereumControl Channels (max_values: None, max_size: Some(12), added: 2487, mode: MaxEncodedLen)
/// Storage: ParachainInfo ParachainId (r:1 w:0)
/// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: EthereumOutboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumOutboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:1 w:1)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:1 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
fn create_channel() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
// Measured: `602`
// Estimated: `69050`
// Minimum execution time: 84_000_000 picoseconds.
Weight::from_parts(84_000_000, 0)
.saturating_add(Weight::from_parts(0, 69050))
.saturating_add(T::DbWeight::get().reads(8))
.saturating_add(T::DbWeight::get().writes(5))
}

/// Storage: EthereumControl Channels (r:1 w:0)
/// Proof: EthereumControl Channels (max_values: None, max_size: Some(12), added: 2487, mode: MaxEncodedLen)
/// Storage: EthereumOutboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumOutboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:2 w:2)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue ServiceHead (r:1 w:0)
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:0 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
fn update_channel() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
// Measured: `256`
// Estimated: `6044`
// Minimum execution time: 41_000_000 picoseconds.
Weight::from_parts(41_000_000, 0)
.saturating_add(Weight::from_parts(0, 6044))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
.saturating_add(T::DbWeight::get().writes(3))
}

/// Storage: EthereumControl Channels (r:1 w:0)
/// Proof: EthereumControl Channels (max_values: None, max_size: Some(12), added: 2487, mode: MaxEncodedLen)
/// Storage: EthereumOutboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumOutboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:2 w:2)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue ServiceHead (r:1 w:0)
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:0 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
fn force_update_channel() -> Weight {
// Proof Size summary in bytes:
// Measured: `256`
// Estimated: `6044`
// Minimum execution time: 41_000_000 picoseconds.
Weight::from_parts(41_000_000, 0)
.saturating_add(Weight::from_parts(0, 6044))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: ParachainInfo ParachainId (r:1 w:0)
/// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: EthereumOutboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumOutboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:1 w:1)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue ServiceHead (r:1 w:1)
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:0 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
fn set_operating_mode() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Measured: `80`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
// Minimum execution time: 30_000_000 picoseconds.
Weight::from_parts(30_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(3))
}

/// Storage: EthereumControl Agents (r:1 w:0)
/// Proof: EthereumControl Agents (max_values: None, max_size: Some(40), added: 2515, mode: MaxEncodedLen)
/// Storage: EthereumOutboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumOutboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:2 w:2)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue ServiceHead (r:1 w:0)
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:0 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
fn transfer_native_from_agent() -> Weight {
// Proof Size summary in bytes:
// Measured: `84`
// Estimated: `3517`
// Minimum execution time: 34_000_000 picoseconds.
Weight::from_parts(35_000_000, 0)
.saturating_add(Weight::from_parts(0, 3517))
// Measured: `252`
// Estimated: `6044`
// Minimum execution time: 43_000_000 picoseconds.
Weight::from_parts(43_000_000, 0)
.saturating_add(Weight::from_parts(0, 6044))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: EthereumControl Agents (r:1 w:0)
/// Proof: EthereumControl Agents (max_values: None, max_size: Some(40), added: 2515, mode: MaxEncodedLen)
/// Storage: EthereumOutboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumOutboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: MessageQueue BookStateFor (r:2 w:2)
/// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen)
/// Storage: MessageQueue ServiceHead (r:1 w:0)
/// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen)
/// Storage: MessageQueue Pages (r:0 w:1)
/// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen)
fn force_transfer_native_from_agent() -> Weight {
// Proof Size summary in bytes:
// Measured: `252`
// Estimated: `6044`
// Minimum execution time: 42_000_000 picoseconds.
Weight::from_parts(42_000_000, 0)
.saturating_add(Weight::from_parts(0, 6044))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,6 @@ impl cumulus_pallet_xcm::Config for Runtime {

pub type AgentIdOf = HashedDescription<H256, DescribeFamily<DescribeAllTerminal>>;

/// Ethereum control pallet: Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
/// when determining sovereign accounts for asset transacting
pub type SovereignAccountOf = (
// Relay chain, sibling parachains, and local children
LocationToAccountId,
// Other nested consensus systems on sibling parachains
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>,
);

pub type SnowbridgeExporter = EthereumBlobExporter<
UniversalLocation,
EthereumGatewayLocation,
Expand Down

0 comments on commit 755b82a

Please sign in to comment.