Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Clean benchmark imports #90

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ use frame_system::{
};

use bp_runtime::HeaderId;
#[cfg(not(feature = "runtime-benchmarks"))]
use bridge_hub_common::BridgeHubMessageRouter;
use bridge_hub_common::{
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AggregateMessageOrigin,
Expand Down Expand Up @@ -102,17 +100,9 @@ use parachains_common::{
use polkadot_runtime_common::prod_or_fast;

#[cfg(feature = "runtime-benchmarks")]
use crate::xcm_config::benchmark_helpers::DoNothingRouter;
#[cfg(feature = "runtime-benchmarks")]
use snowbridge_beacon_primitives::CompactExecutionHeader;
#[cfg(feature = "runtime-benchmarks")]
use snowbridge_core::RingBufferMap;
#[cfg(feature = "runtime-benchmarks")]
pub use snowbridge_ethereum_beacon_client::ExecutionHeaderBuffer;
#[cfg(feature = "runtime-benchmarks")]
use snowbridge_inbound_queue::BenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
use sp_core::H256;
use benchmark_helpers::DoNothingRouter;
#[cfg(not(feature = "runtime-benchmarks"))]
use bridge_hub_common::BridgeHubMessageRouter;

/// The address format for describing accounts.
pub type Address = MultiAddress<AccountId, ()>;
Expand Down Expand Up @@ -521,9 +511,40 @@ parameter_types! {
}

#[cfg(feature = "runtime-benchmarks")]
impl<T: snowbridge_ethereum_beacon_client::Config> BenchmarkHelper<T> for Runtime {
fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) {
<ExecutionHeaderBuffer<T>>::insert(block_hash, header);
pub mod benchmark_helpers {
use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin};
use codec::Encode;
use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_inbound_queue::BenchmarkHelper;
use sp_core::H256;
use xcm::latest::{MultiAssets, MultiLocation, SendError, SendResult, SendXcm, Xcm, XcmHash};

impl<T: snowbridge_ethereum_beacon_client::Config> BenchmarkHelper<T> for Runtime {
fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) {
EthereumBeaconClient::store_execution_header(block_hash, header, 0, H256::default())
}
}

pub struct DoNothingRouter;
impl SendXcm for DoNothingRouter {
type Ticket = Xcm<()>;

fn validate(
_dest: &mut Option<MultiLocation>,
xcm: &mut Option<Xcm<()>>,
) -> SendResult<Self::Ticket> {
Ok((xcm.clone().unwrap(), MultiAssets::new()))
}
fn deliver(xcm: Xcm<()>) -> Result<XcmHash, SendError> {
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
Ok(hash)
}
}

impl snowbridge_system::BenchmarkHelper<RuntimeOrigin> for () {
fn make_xcm_origin(location: MultiLocation) -> RuntimeOrigin {
RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location))
}
}
}

Expand Down Expand Up @@ -623,13 +644,6 @@ impl snowbridge_ethereum_beacon_client::Config for Runtime {
type WeightInfo = weights::snowbridge_ethereum_beacon_client::WeightInfo<Runtime>;
}

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

impl snowbridge_system::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OutboundQueue = EthereumOutboundQueue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,22 +497,3 @@ impl<WaivedLocations: Contains<MultiLocation>, FeeHandler: HandleFee> FeeManager
FeeHandler::handle_fee(fee, context, reason);
}
}

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmark_helpers {
use crate::{MultiAssets, MultiLocation, SendError, SendResult, SendXcm, Xcm, XcmHash};

pub struct DoNothingRouter;
impl SendXcm for DoNothingRouter {
type Ticket = ();
fn validate(
_dest: &mut Option<MultiLocation>,
_msg: &mut Option<Xcm<()>>,
) -> SendResult<()> {
Ok(((), MultiAssets::new()))
}
fn deliver(_: ()) -> Result<XcmHash, SendError> {
Ok([0; 32])
}
}
}
Loading