Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::Pallet as InboundQueue;
use frame_benchmarking::v2::*;
use frame_support::assert_ok;
use frame_system::RawOrigin;
use snowbridge_pallet_inbound_queue_v2_fixtures::register_token::make_register_token_message;

#[benchmarks]
mod benchmarks {
Expand All @@ -16,12 +15,7 @@ mod benchmarks {
fn submit() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();

let create_message = make_register_token_message();

T::Helper::initialize_storage(
create_message.finalized_header,
create_message.block_roots_root,
);
let create_message = T::Helper::initialize_storage();

#[block]
{
Expand Down
7 changes: 4 additions & 3 deletions bridges/snowbridge/pallets/inbound-queue-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ use sp_core::H160;
use sp_runtime::traits::TryConvert;
use sp_std::prelude::*;
use xcm::prelude::{ExecuteXcm, Junction::*, Location, SendXcm, *};
#[cfg(feature = "runtime-benchmarks")]
use {snowbridge_beacon_primitives::BeaconHeader, sp_core::H256};

pub use pallet::*;

Expand All @@ -69,12 +67,15 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[cfg(feature = "runtime-benchmarks")]
use snowbridge_inbound_queue_primitives::EventFixture;

#[pallet::pallet]
pub struct Pallet<T>(_);

#[cfg(feature = "runtime-benchmarks")]
pub trait BenchmarkHelper<T> {
fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256);
fn initialize_storage() -> EventFixture;
}

#[pallet::config]
Expand Down
9 changes: 8 additions & 1 deletion bridges/snowbridge/pallets/inbound-queue-v2/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type Block = frame_system::mocking::MockBlock<Test>;
use snowbridge_test_utils::mock_rewards::{BridgeReward, MockRewardLedger};
pub use snowbridge_test_utils::mock_xcm::{MockXcmExecutor, MockXcmSender};

#[cfg(feature = "runtime-benchmarks")]
use snowbridge_inbound_queue_primitives::EventFixture;
#[cfg(feature = "runtime-benchmarks")]
use snowbridge_pallet_inbound_queue_v2_fixtures::register_token::make_register_token_message;

frame_support::construct_runtime!(
pub enum Test
{
Expand Down Expand Up @@ -71,7 +76,9 @@ const GATEWAY_ADDRESS: [u8; 20] = hex!["b1185ede04202fe62d38f5db72f71e38ff3e8305
#[cfg(feature = "runtime-benchmarks")]
impl<T: Config> BenchmarkHelper<T> for Test {
// not implemented since the MockVerifier is used for tests
fn initialize_storage(_: BeaconHeader, _: H256) {}
fn initialize_storage() -> EventFixture {
make_register_token_message()
}
}

pub struct MockTokenIdConvert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::Pallet as InboundQueue;
use frame_benchmarking::v2::*;
use frame_support::assert_ok;
use frame_system::RawOrigin;
use snowbridge_pallet_inbound_queue_fixtures::register_token::make_register_token_message;

#[benchmarks]
mod benchmarks {
Expand All @@ -16,12 +15,7 @@ mod benchmarks {
fn submit() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();

let create_message = make_register_token_message();

T::Helper::initialize_storage(
create_message.finalized_header,
create_message.block_roots_root,
);
let create_message = T::Helper::initialize_storage();

let sovereign_account = sibling_sovereign_account::<T>(1000u32.into());

Expand Down
8 changes: 4 additions & 4 deletions bridges/snowbridge/pallets/inbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ use sp_runtime::{traits::Saturating, SaturatedConversion, TokenError};

pub use weights::WeightInfo;

#[cfg(feature = "runtime-benchmarks")]
use snowbridge_beacon_primitives::BeaconHeader;

type BalanceOf<T> =
<<T as pallet::Config>::Token as Inspect<<T as frame_system::Config>::AccountId>>::Balance;

Expand All @@ -87,12 +84,15 @@ pub mod pallet {
use frame_system::pallet_prelude::*;
use sp_core::H256;

#[cfg(feature = "runtime-benchmarks")]
use snowbridge_inbound_queue_primitives::EventFixture;

#[pallet::pallet]
pub struct Pallet<T>(_);

#[cfg(feature = "runtime-benchmarks")]
pub trait BenchmarkHelper<T> {
fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256);
fn initialize_storage() -> EventFixture;
}

#[pallet::config]
Expand Down
9 changes: 8 additions & 1 deletion bridges/snowbridge/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ use xcm::{
};
use xcm_executor::AssetsInHolding;

#[cfg(feature = "runtime-benchmarks")]
use snowbridge_inbound_queue_primitives::EventFixture;
#[cfg(feature = "runtime-benchmarks")]
use snowbridge_pallet_inbound_queue_fixtures::register_token::make_register_token_message;

use crate::{self as inbound_queue};

type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -125,7 +130,9 @@ parameter_types! {
#[cfg(feature = "runtime-benchmarks")]
impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Test {
// not implemented since the MockVerifier is used for tests
Comment thread
dimartiro marked this conversation as resolved.
Outdated
fn initialize_storage(_: BeaconHeader, _: H256) {}
fn initialize_storage() -> EventFixture {
make_register_token_message()
}
}

// Mock XCM sender that always succeeds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ snowbridge-outbound-queue-primitives = { workspace = true }
snowbridge-outbound-queue-runtime-api = { workspace = true }
snowbridge-pallet-ethereum-client = { workspace = true }
snowbridge-pallet-inbound-queue = { workspace = true }
snowbridge-pallet-inbound-queue-fixtures = { workspace = true }
snowbridge-pallet-outbound-queue = { workspace = true }
snowbridge-pallet-system = { workspace = true }
snowbridge-system-runtime-api = { workspace = true }
Expand Down Expand Up @@ -195,6 +196,7 @@ std = [
"snowbridge-outbound-queue-primitives/std",
"snowbridge-outbound-queue-runtime-api/std",
"snowbridge-pallet-ethereum-client/std",
"snowbridge-pallet-inbound-queue-fixtures/std",
"snowbridge-pallet-inbound-queue/std",
"snowbridge-pallet-outbound-queue/std",
"snowbridge-pallet-system/std",
Expand Down Expand Up @@ -256,6 +258,7 @@ runtime-benchmarks = [
"snowbridge-core/runtime-benchmarks",
"snowbridge-inbound-queue-primitives/runtime-benchmarks",
"snowbridge-pallet-ethereum-client/runtime-benchmarks",
"snowbridge-pallet-inbound-queue-fixtures/runtime-benchmarks",
"snowbridge-pallet-inbound-queue/runtime-benchmarks",
"snowbridge-pallet-outbound-queue/runtime-benchmarks",
"snowbridge-pallet-system/runtime-benchmarks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,20 @@ impl snowbridge_pallet_system::Config for Runtime {
pub mod benchmark_helpers {
use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin};
use codec::Encode;
use snowbridge_beacon_primitives::BeaconHeader;
use snowbridge_inbound_queue_primitives::EventFixture;
use snowbridge_pallet_inbound_queue::BenchmarkHelper;
use sp_core::H256;
use snowbridge_pallet_inbound_queue_fixtures::register_token::make_register_token_message;
use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};

impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) {
EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
fn initialize_storage() -> EventFixture {
let message = make_register_token_message();
EthereumBeaconClient::store_finalized_header(
message.finalized_header,
message.block_roots_root,
)
.unwrap();
message
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ snowbridge-outbound-queue-runtime-api = { workspace = true }
snowbridge-outbound-queue-v2-runtime-api = { workspace = true }
snowbridge-pallet-ethereum-client = { workspace = true }
snowbridge-pallet-inbound-queue = { workspace = true }
snowbridge-pallet-inbound-queue-fixtures = { workspace = true }
snowbridge-pallet-inbound-queue-v2 = { workspace = true }
snowbridge-pallet-inbound-queue-v2-fixtures = { workspace = true }
snowbridge-pallet-outbound-queue = { workspace = true }
snowbridge-pallet-outbound-queue-v2 = { workspace = true }
snowbridge-pallet-system = { workspace = true }
Expand Down Expand Up @@ -197,6 +199,8 @@ std = [
"snowbridge-outbound-queue-runtime-api/std",
"snowbridge-outbound-queue-v2-runtime-api/std",
"snowbridge-pallet-ethereum-client/std",
"snowbridge-pallet-inbound-queue-fixtures/std",
"snowbridge-pallet-inbound-queue-v2-fixtures/std",
"snowbridge-pallet-inbound-queue-v2/std",
"snowbridge-pallet-inbound-queue/std",
"snowbridge-pallet-outbound-queue-v2/std",
Expand Down Expand Up @@ -265,6 +269,8 @@ runtime-benchmarks = [
"snowbridge-core/runtime-benchmarks",
"snowbridge-inbound-queue-primitives/runtime-benchmarks",
"snowbridge-pallet-ethereum-client/runtime-benchmarks",
"snowbridge-pallet-inbound-queue-fixtures/runtime-benchmarks",
"snowbridge-pallet-inbound-queue-v2-fixtures/runtime-benchmarks",
"snowbridge-pallet-inbound-queue-v2/runtime-benchmarks",
"snowbridge-pallet-inbound-queue/runtime-benchmarks",
"snowbridge-pallet-outbound-queue-v2/runtime-benchmarks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,26 @@ pub mod benchmark_helpers {
RuntimeOrigin, System,
};
use codec::Encode;
use frame_support::assert_ok;
use hex_literal::hex;
use snowbridge_beacon_primitives::BeaconHeader;
use snowbridge_inbound_queue_primitives::EventFixture;
use snowbridge_pallet_inbound_queue::BenchmarkHelper;
use snowbridge_pallet_inbound_queue_fixtures::register_token::make_register_token_message;
use snowbridge_pallet_inbound_queue_v2::BenchmarkHelper as InboundQueueBenchmarkHelperV2;
use snowbridge_pallet_inbound_queue_v2_fixtures::register_token::make_register_token_message as make_register_token_message_v2;
use snowbridge_pallet_outbound_queue_v2::BenchmarkHelper as OutboundQueueBenchmarkHelperV2;
use sp_core::H256;
use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};

impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) {
EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
fn initialize_storage() -> EventFixture {
let message = make_register_token_message();
EthereumBeaconClient::store_finalized_header(
message.finalized_header,
message.block_roots_root,
)
.unwrap();
System::set_storage(
RuntimeOrigin::root(),
vec![(
Expand All @@ -327,12 +336,20 @@ pub mod benchmark_helpers {
)],
)
.unwrap();
message
}
}

impl<T: snowbridge_pallet_inbound_queue_v2::Config> InboundQueueBenchmarkHelperV2<T> for Runtime {
fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) {
EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
fn initialize_storage() -> EventFixture {
let message = make_register_token_message_v2();

assert_ok!(EthereumBeaconClient::store_finalized_header(
message.finalized_header,
message.block_roots_root,
));

message
}
}

Expand Down
17 changes: 17 additions & 0 deletions prdoc/pr_9627.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: Improve inbound_queue::BenchmarkHelper to add more flexibility
doc:
- audience: Runtime Dev
description: |-
# Description

Improve the usage of the `inbound_queue::BenchmarkHelper` to decouple the mocks from the benchmark.
This change will enable any user to benchmark custom messages since now it's harcoded to the register_token_message only
crates:
- name: snowbridge-pallet-inbound-queue
bump: patch
- name: snowbridge-pallet-inbound-queue-v2
bump: patch
- name: bridge-hub-westend-runtime
bump: minor
- name: bridge-hub-rococo-runtime
bump: minor
Loading