From 77d47fba62045769d07fb70f5cacf531a9f51184 Mon Sep 17 00:00:00 2001 From: Parth Desai Date: Tue, 19 Nov 2024 19:39:47 +0400 Subject: [PATCH] fix runtime benchmark --- Cargo.lock | 1 + Cargo.toml | 1 + pallets/external-validator-slashes/Cargo.toml | 1 - solo-chains/runtime/dancelight/Cargo.toml | 2 + .../src/bridge_to_ethereum_config.rs | 42 +++++++++- solo-chains/runtime/dancelight/src/lib.rs | 1 + .../src/tests/inbound_queue_tests/mock.rs | 14 +++- .../runtime/dancelight/src/weights/mod.rs | 1 + .../snowbridge_pallet_inbound_queue.rs | 82 +++++++++++++++++++ 9 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 solo-chains/runtime/dancelight/src/weights/snowbridge_pallet_inbound_queue.rs diff --git a/Cargo.lock b/Cargo.lock index 19c9819bc..b0763ed4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3469,6 +3469,7 @@ dependencies = [ "snowbridge-milagro-bls", "snowbridge-pallet-ethereum-client", "snowbridge-pallet-inbound-queue", + "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-pallet-outbound-queue", "snowbridge-pallet-system", "snowbridge-router-primitives", diff --git a/Cargo.toml b/Cargo.toml index ce5c5bc92..82421111b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -265,6 +265,7 @@ snowbridge-beacon-primitives = { git = "https://github.com/moondance-labs/polkad snowbridge-core = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } snowbridge-pallet-ethereum-client = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } snowbridge-pallet-inbound-queue = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } +snowbridge-pallet-inbound-queue-fixtures = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } snowbridge-pallet-outbound-queue = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } snowbridge-pallet-system = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } snowbridge-router-primitives = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } diff --git a/pallets/external-validator-slashes/Cargo.toml b/pallets/external-validator-slashes/Cargo.toml index 765400ab1..15b69549e 100644 --- a/pallets/external-validator-slashes/Cargo.toml +++ b/pallets/external-validator-slashes/Cargo.toml @@ -58,7 +58,6 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-staking/runtime-benchmarks", - "scale-info/std", "snowbridge-core/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "sp-staking/runtime-benchmarks", diff --git a/solo-chains/runtime/dancelight/Cargo.toml b/solo-chains/runtime/dancelight/Cargo.toml index b6a4923b3..e950e9069 100644 --- a/solo-chains/runtime/dancelight/Cargo.toml +++ b/solo-chains/runtime/dancelight/Cargo.toml @@ -147,6 +147,7 @@ snowbridge-beacon-primitives = { workspace = true } snowbridge-core = { workspace = true } snowbridge-pallet-ethereum-client = { workspace = true } snowbridge-pallet-inbound-queue = { workspace = true } +snowbridge-pallet-inbound-queue-fixtures = { workspace = true, optional = true } snowbridge-pallet-outbound-queue = { workspace = true } snowbridge-pallet-system = { workspace = true } snowbridge-router-primitives = { workspace = true } @@ -362,6 +363,7 @@ runtime-benchmarks = [ "snowbridge-core/runtime-benchmarks", "snowbridge-pallet-ethereum-client/runtime-benchmarks", "snowbridge-pallet-inbound-queue/runtime-benchmarks", + "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-pallet-outbound-queue/runtime-benchmarks", "snowbridge-pallet-system/runtime-benchmarks", "snowbridge-router-primitives/runtime-benchmarks", diff --git a/solo-chains/runtime/dancelight/src/bridge_to_ethereum_config.rs b/solo-chains/runtime/dancelight/src/bridge_to_ethereum_config.rs index cc43b98e7..bd5b06edc 100644 --- a/solo-chains/runtime/dancelight/src/bridge_to_ethereum_config.rs +++ b/solo-chains/runtime/dancelight/src/bridge_to_ethereum_config.rs @@ -17,7 +17,7 @@ //! The bridge to ethereum config pub const SLOTS_PER_EPOCH: u32 = snowbridge_pallet_ethereum_client::config::SLOTS_PER_EPOCH as u32; - +#[cfg(not(feature = "runtime-benchmarks"))] use crate::symbiotic_message_processor::SymbioticMessageProcessor; use frame_support::weights::ConstantMultiplier; use parity_scale_codec::Encode; @@ -159,7 +159,15 @@ impl snowbridge_pallet_system::Config for Runtime { #[cfg(feature = "runtime-benchmarks")] mod benchmark_helper { - use {crate::RuntimeOrigin, xcm::latest::Location}; + use snowbridge_beacon_primitives::BeaconHeader; + use snowbridge_router_primitives::inbound::envelope::Envelope; + use sp_core::H256; + use { + crate::EthereumBeaconClient, crate::Runtime, crate::RuntimeOrigin, xcm::latest::Location, + }; + use snowbridge_pallet_system::Channels; + use snowbridge_core::Channel; + use snowbridge_router_primitives::inbound::MessageProcessor; pub struct EthSystemBenchHelper; @@ -174,6 +182,29 @@ mod benchmark_helper { RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location)) } } + + impl snowbridge_pallet_inbound_queue::BenchmarkHelper for EthSystemBenchHelper { + fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) { + let submit_message = snowbridge_pallet_inbound_queue_fixtures::register_token::make_register_token_message(); + let envelope: Envelope = Envelope::try_from(&submit_message.message.event_log).unwrap(); + + Channels::::set(envelope.channel_id, Some(Channel { + agent_id: Default::default(), + para_id: Default::default() + })); + + EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap(); + } + } + + pub struct DoNothingMessageProcessor; + + impl MessageProcessor for DoNothingMessageProcessor { + fn can_process_message(_: &Channel, _: &Envelope) -> bool { true } + + fn process_message(_: Channel, _: Envelope) -> Result<(), sp_runtime::DispatchError> { Ok(()) } + + } } pub struct DoNothingRouter; @@ -214,12 +245,15 @@ impl snowbridge_pallet_inbound_queue::Config for Runtime { type MessageConverter = DoNothingConvertMessage; type ChannelLookup = EthereumSystem; type PricingParameters = EthereumSystem; - type WeightInfo = (); + type WeightInfo = weights::snowbridge_pallet_inbound_queue::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] - type Helper = Runtime; + type Helper = benchmark_helper::EthSystemBenchHelper; type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier; type MaxMessageSize = ConstU32<2048>; type AssetTransactor = ::AssetTransactor; + #[cfg(not(feature = "runtime-benchmarks"))] type MessageProcessor = (SymbioticMessageProcessor,); + #[cfg(feature = "runtime-benchmarks")] + type MessageProcessor = (benchmark_helper::DoNothingMessageProcessor,); } diff --git a/solo-chains/runtime/dancelight/src/lib.rs b/solo-chains/runtime/dancelight/src/lib.rs index cb5638153..30596530c 100644 --- a/solo-chains/runtime/dancelight/src/lib.rs +++ b/solo-chains/runtime/dancelight/src/lib.rs @@ -2086,6 +2086,7 @@ mod benches { // Bridges [snowbridge_pallet_ethereum_client, EthereumBeaconClient] + [snowbridge_pallet_inbound_queue, EthereumInboundQueue] ); } diff --git a/solo-chains/runtime/dancelight/src/tests/inbound_queue_tests/mock.rs b/solo-chains/runtime/dancelight/src/tests/inbound_queue_tests/mock.rs index 59ec8eecd..b6bbc5e63 100644 --- a/solo-chains/runtime/dancelight/src/tests/inbound_queue_tests/mock.rs +++ b/solo-chains/runtime/dancelight/src/tests/inbound_queue_tests/mock.rs @@ -17,14 +17,17 @@ use snowbridge_core::{ meth, Channel, ChannelId, PricingParameters, Rewards, StaticLookup, }; use snowbridge_pallet_inbound_queue::xcm_message_processor::XcmMessageProcessor; +use snowbridge_router_primitives::inbound::envelope::Envelope; use snowbridge_router_primitives::inbound::{MessageProcessor, MessageToXcm}; use sp_core::Encode; use sp_core::{H160, H256}; -use sp_runtime::{traits::{IdentifyAccount, IdentityLookup, Verify}, BuildStorage, DispatchError, FixedU128, MultiSignature}; +use sp_runtime::{ + traits::{IdentifyAccount, IdentityLookup, Verify}, + BuildStorage, DispatchError, FixedU128, MultiSignature, +}; use sp_staking::SessionIndex; use sp_std::{convert::From, default::Default}; use std::time::Duration; -use snowbridge_router_primitives::inbound::envelope::Envelope; use xcm::latest::SendError as XcmpSendError; use xcm::{latest::SendXcm, prelude::*}; use xcm_executor::traits::TransactAsset; @@ -261,7 +264,12 @@ impl snowbridge_pallet_inbound_queue::Config for Test { type LengthToFee = IdentityFee; type MaxMessageSize = ConstU32<1024>; type AssetTransactor = SuccessfulTransactor; - type MessageProcessor = (DummyPrefix, XcmMessageProcessor, SymbioticMessageProcessor, DummySuffix); + type MessageProcessor = ( + DummyPrefix, + XcmMessageProcessor, + SymbioticMessageProcessor, + DummySuffix, + ); } pub struct ValidatorIdOf; diff --git a/solo-chains/runtime/dancelight/src/weights/mod.rs b/solo-chains/runtime/dancelight/src/weights/mod.rs index ee0098635..56d1c6830 100644 --- a/solo-chains/runtime/dancelight/src/weights/mod.rs +++ b/solo-chains/runtime/dancelight/src/weights/mod.rs @@ -49,3 +49,4 @@ pub mod runtime_parachains_initializer; pub mod runtime_parachains_paras; pub mod runtime_parachains_paras_inherent; pub mod snowbridge_pallet_ethereum_client; +pub mod snowbridge_pallet_inbound_queue; diff --git a/solo-chains/runtime/dancelight/src/weights/snowbridge_pallet_inbound_queue.rs b/solo-chains/runtime/dancelight/src/weights/snowbridge_pallet_inbound_queue.rs new file mode 100644 index 000000000..ccf29844d --- /dev/null +++ b/solo-chains/runtime/dancelight/src/weights/snowbridge_pallet_inbound_queue.rs @@ -0,0 +1,82 @@ +// Copyright (C) Moondance Labs Ltd. +// This file is part of Tanssi. + +// Tanssi is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Tanssi 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 General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Tanssi. If not, see + + +//! Autogenerated weights for snowbridge_pallet_inbound_queue +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0 +//! DATE: 2024-11-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Parths-MacBook-Pro-Work.local`, CPU: `` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// target/release/tanssi-relay +// benchmark +// pallet +// --execution=wasm +// --wasm-execution=compiled +// --pallet +// snowbridge_pallet_inbound_queue +// --extrinsic +// * +// --chain=dev +// --steps +// 50 +// --repeat +// 20 +// --template=./benchmarking/frame-weight-runtime-template.hbs +// --json-file +// raw.json +// --output +// ./snowbridge_pallet_inbound_queue.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weights for snowbridge_pallet_inbound_queue using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl snowbridge_pallet_inbound_queue::WeightInfo for SubstrateWeight { + /// Storage: `EthereumInboundQueue::OperatingMode` (r:1 w:0) + /// Proof: `EthereumInboundQueue::OperatingMode` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + /// Storage: `EthereumBeaconClient::LatestFinalizedBlockRoot` (r:1 w:0) + /// Proof: `EthereumBeaconClient::LatestFinalizedBlockRoot` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `EthereumBeaconClient::FinalizedBeaconState` (r:1 w:0) + /// Proof: `EthereumBeaconClient::FinalizedBeaconState` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0xaed97c7854d601808b98ae43079dafb3` (r:1 w:0) + /// Proof: UNKNOWN KEY `0xaed97c7854d601808b98ae43079dafb3` (r:1 w:0) + /// Storage: `EthereumSystem::Channels` (r:1 w:0) + /// Proof: `EthereumSystem::Channels` (`max_values`: None, `max_size`: Some(76), added: 2551, mode: `MaxEncodedLen`) + /// Storage: `EthereumInboundQueue::Nonce` (r:1 w:1) + /// Proof: `EthereumInboundQueue::Nonce` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `EthereumSystem::PricingParameters` (r:1 w:0) + /// Proof: `EthereumSystem::PricingParameters` (`max_values`: Some(1), `max_size`: Some(112), added: 607, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn submit() -> Weight { + // Proof Size summary in bytes: + // Measured: `740` + // Estimated: `4205` + // Minimum execution time: 54_000_000 picoseconds. + Weight::from_parts(54_000_000, 4205) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} \ No newline at end of file