Skip to content

Commit

Permalink
fix runtime benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthDesai committed Nov 19, 2024
1 parent 63f4554 commit 77d47fb
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 0 additions & 1 deletion pallets/external-validator-slashes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions solo-chains/runtime/dancelight/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
42 changes: 38 additions & 4 deletions solo-chains/runtime/dancelight/src/bridge_to_ethereum_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -174,6 +182,29 @@ mod benchmark_helper {
RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location))
}
}

impl snowbridge_pallet_inbound_queue::BenchmarkHelper<Runtime> 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::<Runtime>::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;
Expand Down Expand Up @@ -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<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
type Helper = benchmark_helper::EthSystemBenchHelper;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type MaxMessageSize = ConstU32<2048>;
type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
#[cfg(not(feature = "runtime-benchmarks"))]
type MessageProcessor = (SymbioticMessageProcessor<Runtime>,);
#[cfg(feature = "runtime-benchmarks")]
type MessageProcessor = (benchmark_helper::DoNothingMessageProcessor,);
}
1 change: 1 addition & 0 deletions solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,7 @@ mod benches {

// Bridges
[snowbridge_pallet_ethereum_client, EthereumBeaconClient]
[snowbridge_pallet_inbound_queue, EthereumInboundQueue]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -261,7 +264,12 @@ impl snowbridge_pallet_inbound_queue::Config for Test {
type LengthToFee = IdentityFee<u128>;
type MaxMessageSize = ConstU32<1024>;
type AssetTransactor = SuccessfulTransactor;
type MessageProcessor = (DummyPrefix, XcmMessageProcessor<Test>, SymbioticMessageProcessor<Test>, DummySuffix);
type MessageProcessor = (
DummyPrefix,
XcmMessageProcessor<Test>,
SymbioticMessageProcessor<Test>,
DummySuffix,
);
}

pub struct ValidatorIdOf;
Expand Down
1 change: 1 addition & 0 deletions solo-chains/runtime/dancelight/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>


//! 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: `<UNKNOWN>`
//! 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<T>(PhantomData<T>);
impl<T: frame_system::Config> snowbridge_pallet_inbound_queue::WeightInfo for SubstrateWeight<T> {
/// 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))
}
}

0 comments on commit 77d47fb

Please sign in to comment.