diff --git a/bridges/modules/xcm-bridge-hub/src/lib.rs b/bridges/modules/xcm-bridge-hub/src/lib.rs index 7af7dbb96a21..55e57375c871 100644 --- a/bridges/modules/xcm-bridge-hub/src/lib.rs +++ b/bridges/modules/xcm-bridge-hub/src/lib.rs @@ -656,6 +656,32 @@ pub mod pallet { } } + #[cfg(feature = "runtime-benchmarks")] + impl, I: 'static> Pallet { + /// Open bridge for lane. + pub fn open_bridge_for_benchmarks( + lane_id: LaneIdOf, + bridge_origin_relative_location: Location, + bridge_destination_universal_location: InteriorLocation, + create_lanes: bool, + maybe_notify: Option, + ) -> Result, sp_runtime::DispatchError> { + let locations = Pallet::::bridge_locations( + bridge_origin_relative_location.into(), + bridge_destination_universal_location.into(), + )?; + + Pallet::::do_open_bridge( + locations.clone(), + lane_id, + create_lanes, + maybe_notify, + )?; + + Ok(locations) + } + } + #[cfg(any(test, feature = "try-runtime", feature = "std"))] impl, I: 'static> Pallet { /// Ensure the correctness of the state of this pallet. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_bulletin_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_bulletin_config.rs index d18dd2afb998..6bc0100c5310 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_bulletin_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_bulletin_config.rs @@ -235,55 +235,6 @@ mod tests { } } -#[cfg(feature = "runtime-benchmarks")] -pub(crate) fn open_bridge_for_benchmarks( - with: pallet_xcm_bridge_hub::LaneIdOf, - sibling_para_id: u32, -) -> InteriorLocation -where - R: pallet_xcm_bridge_hub::Config, - XBHI: 'static, - C: xcm_executor::traits::ConvertLocation< - bp_runtime::AccountIdOf>, - >, -{ - use pallet_xcm_bridge_hub::{Bridge, BridgeId, BridgeState}; - use sp_runtime::traits::Zero; - use xcm::{latest::ROCOCO_GENESIS_HASH, VersionedInteriorLocation}; - - // insert bridge metadata - let lane_id = with; - let sibling_parachain = Location::new(1, [Parachain(sibling_para_id)]); - let universal_source = - [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH)), Parachain(sibling_para_id)].into(); - let universal_destination = - [GlobalConsensus(RococoBulletinGlobalConsensusNetwork::get()), Parachain(2075)].into(); - let bridge_id = BridgeId::new(&universal_source, &universal_destination); - - // insert only bridge metadata, because the benchmarks create lanes - pallet_xcm_bridge_hub::Bridges::::insert( - bridge_id, - Bridge { - bridge_origin_relative_location: alloc::boxed::Box::new( - sibling_parachain.clone().into(), - ), - bridge_origin_universal_location: alloc::boxed::Box::new( - VersionedInteriorLocation::from(universal_source.clone()), - ), - bridge_destination_universal_location: alloc::boxed::Box::new( - VersionedInteriorLocation::from(universal_destination), - ), - state: BridgeState::Opened, - bridge_owner_account: C::convert_location(&sibling_parachain).expect("valid AccountId"), - deposit: Zero::zero(), - lane_id, - }, - ); - pallet_xcm_bridge_hub::LaneToBridge::::insert(lane_id, bridge_id); - - universal_source -} - /// Contains the migration for the PeopleRococo<>RococoBulletin bridge. pub mod migration { use super::*; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_westend_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_westend_config.rs index 2abfedfa8c4c..8c9a127bd1bc 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_westend_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_to_westend_config.rs @@ -193,55 +193,6 @@ impl pallet_xcm_bridge_hub::Config for Runtime >; } -#[cfg(feature = "runtime-benchmarks")] -pub(crate) fn open_bridge_for_benchmarks( - with: pallet_xcm_bridge_hub::LaneIdOf, - sibling_para_id: u32, -) -> InteriorLocation -where - R: pallet_xcm_bridge_hub::Config, - XBHI: 'static, - C: xcm_executor::traits::ConvertLocation< - bp_runtime::AccountIdOf>, - >, -{ - use pallet_xcm_bridge_hub::{Bridge, BridgeId, BridgeState}; - use sp_runtime::traits::Zero; - use xcm::{latest::ROCOCO_GENESIS_HASH, VersionedInteriorLocation}; - - // insert bridge metadata - let lane_id = with; - let sibling_parachain = Location::new(1, [Parachain(sibling_para_id)]); - let universal_source = - [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH)), Parachain(sibling_para_id)].into(); - let universal_destination = - [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)), Parachain(2075)].into(); - let bridge_id = BridgeId::new(&universal_source, &universal_destination); - - // insert only bridge metadata, because the benchmarks create lanes - pallet_xcm_bridge_hub::Bridges::::insert( - bridge_id, - Bridge { - bridge_origin_relative_location: alloc::boxed::Box::new( - sibling_parachain.clone().into(), - ), - bridge_origin_universal_location: alloc::boxed::Box::new( - VersionedInteriorLocation::from(universal_source.clone()), - ), - bridge_destination_universal_location: alloc::boxed::Box::new( - VersionedInteriorLocation::from(universal_destination), - ), - state: BridgeState::Opened, - bridge_owner_account: C::convert_location(&sibling_parachain).expect("valid AccountId"), - deposit: Zero::zero(), - lane_id, - }, - ); - pallet_xcm_bridge_hub::LaneToBridge::::insert(lane_id, bridge_id); - - universal_source -} - #[cfg(test)] mod tests { use super::*; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 421f1e0a934f..bc4fdd247bc4 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1278,14 +1278,12 @@ impl_runtime_apis! { // open bridge let bridge_destination_universal_location: InteriorLocation = [GlobalConsensus(NetworkId::ByGenesis(WESTEND_GENESIS_HASH)), Parachain(8765)].into(); - let locations = XcmOverBridgeHubWestend::bridge_locations( + let _ = XcmOverBridgeHubWestend::open_bridge_for_benchmarks( + bp_messages::LegacyLaneId([1, 2, 3, 4]), sibling_parachain_location.clone(), bridge_destination_universal_location.clone(), - )?; - XcmOverBridgeHubWestend::do_open_bridge( - locations, - bp_messages::LegacyLaneId([1, 2, 3, 4]), true, + None, ).map_err(|e| { log::error!( "Failed to `XcmOverBridgeHubWestend::open_bridge`({:?}, {:?})`, error: {:?}", @@ -1354,26 +1352,32 @@ impl_runtime_apis! { use cumulus_primitives_core::XcmpMessageSource; assert!(XcmpQueue::take_outbound_messages(usize::MAX).is_empty()); ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(42.into()); - let universal_source = bridge_to_westend_config::open_bridge_for_benchmarks::< - Runtime, - bridge_to_westend_config::XcmOverBridgeHubWestendInstance, - xcm_config::LocationToAccountId, - >(params.lane, 42); + let bridge_locations = XcmOverBridgeHubWestend::open_bridge_for_benchmarks( + params.lane, + Location::new(1, [Parachain(42)]), + [GlobalConsensus(bridge_to_westend_config::WestendGlobalConsensusNetwork::get()), Parachain(2075)].into(), + // do not create lanes, because they are already created `params.lane` + false, + None, + ).expect("valid bridge opened"); prepare_message_proof_from_parachain::< Runtime, bridge_common_config::BridgeGrandpaWestendInstance, bridge_to_westend_config::WithBridgeHubWestendMessagesInstance, - >(params, generate_xcm_builder_bridge_message_sample(universal_source)) + >(params, generate_xcm_builder_bridge_message_sample(bridge_locations.bridge_origin_universal_location().clone())) } fn prepare_message_delivery_proof( params: MessageDeliveryProofParams>, ) -> bridge_to_westend_config::ToWestendBridgeHubMessagesDeliveryProof { - let _ = bridge_to_westend_config::open_bridge_for_benchmarks::< - Runtime, - bridge_to_westend_config::XcmOverBridgeHubWestendInstance, - xcm_config::LocationToAccountId, - >(params.lane, 42); + let _ = XcmOverBridgeHubWestend::open_bridge_for_benchmarks( + params.lane, + Location::new(1, [Parachain(42)]), + [GlobalConsensus(bridge_to_westend_config::WestendGlobalConsensusNetwork::get()), Parachain(2075)].into(), + // do not create lanes, because they are already created `params.lane` + false, + None, + ); prepare_message_delivery_proof_from_parachain::< Runtime, bridge_common_config::BridgeGrandpaWestendInstance, @@ -1399,26 +1403,32 @@ impl_runtime_apis! { use cumulus_primitives_core::XcmpMessageSource; assert!(XcmpQueue::take_outbound_messages(usize::MAX).is_empty()); ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(42.into()); - let universal_source = bridge_to_bulletin_config::open_bridge_for_benchmarks::< - Runtime, - bridge_to_bulletin_config::XcmOverPolkadotBulletinInstance, - xcm_config::LocationToAccountId, - >(params.lane, 42); + let bridge_locations = XcmOverPolkadotBulletin::open_bridge_for_benchmarks( + params.lane, + Location::new(1, [Parachain(42)]), + [GlobalConsensus(bridge_to_bulletin_config::RococoBulletinGlobalConsensusNetwork::get())].into(), + // do not create lanes, because they are already created `params.lane` + false, + None, + ).expect("valid bridge opened"); prepare_message_proof_from_grandpa_chain::< Runtime, bridge_common_config::BridgeGrandpaRococoBulletinInstance, bridge_to_bulletin_config::WithRococoBulletinMessagesInstance, - >(params, generate_xcm_builder_bridge_message_sample(universal_source)) + >(params, generate_xcm_builder_bridge_message_sample(bridge_locations.bridge_origin_universal_location().clone())) } fn prepare_message_delivery_proof( params: MessageDeliveryProofParams>, ) -> bridge_to_bulletin_config::ToRococoBulletinMessagesDeliveryProof { - let _ = bridge_to_bulletin_config::open_bridge_for_benchmarks::< - Runtime, - bridge_to_bulletin_config::XcmOverPolkadotBulletinInstance, - xcm_config::LocationToAccountId, - >(params.lane, 42); + let _ = XcmOverPolkadotBulletin::open_bridge_for_benchmarks( + params.lane, + Location::new(1, [Parachain(42)]), + [GlobalConsensus(bridge_to_bulletin_config::RococoBulletinGlobalConsensusNetwork::get())].into(), + // do not create lanes, because they are already created `params.lane` + false, + None, + ).expect("valid bridge opened"); prepare_message_delivery_proof_from_grandpa_chain::< Runtime, bridge_common_config::BridgeGrandpaRococoBulletinInstance, diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_rococo_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_rococo_config.rs index 34fada7258f5..0e8402aefc59 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_rococo_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_rococo_config.rs @@ -222,55 +222,6 @@ impl pallet_xcm_bridge_hub::Config for Runtime { >; } -#[cfg(feature = "runtime-benchmarks")] -pub(crate) fn open_bridge_for_benchmarks( - with: pallet_xcm_bridge_hub::LaneIdOf, - sibling_para_id: u32, -) -> InteriorLocation -where - R: pallet_xcm_bridge_hub::Config, - XBHI: 'static, - C: xcm_executor::traits::ConvertLocation< - bp_runtime::AccountIdOf>, - >, -{ - use pallet_xcm_bridge_hub::{Bridge, BridgeId, BridgeState}; - use sp_runtime::traits::Zero; - use xcm::{latest::WESTEND_GENESIS_HASH, VersionedInteriorLocation}; - - // insert bridge metadata - let lane_id = with; - let sibling_parachain = Location::new(1, [Parachain(sibling_para_id)]); - let universal_source = - [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)), Parachain(sibling_para_id)].into(); - let universal_destination = - [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH)), Parachain(2075)].into(); - let bridge_id = BridgeId::new(&universal_source, &universal_destination); - - // insert only bridge metadata, because the benchmarks create lanes - pallet_xcm_bridge_hub::Bridges::::insert( - bridge_id, - Bridge { - bridge_origin_relative_location: alloc::boxed::Box::new( - sibling_parachain.clone().into(), - ), - bridge_origin_universal_location: alloc::boxed::Box::new( - VersionedInteriorLocation::from(universal_source.clone()), - ), - bridge_destination_universal_location: alloc::boxed::Box::new( - VersionedInteriorLocation::from(universal_destination), - ), - state: BridgeState::Opened, - bridge_owner_account: C::convert_location(&sibling_parachain).expect("valid AccountId"), - deposit: Zero::zero(), - lane_id, - }, - ); - pallet_xcm_bridge_hub::LaneToBridge::::insert(lane_id, bridge_id); - - universal_source -} - #[cfg(test)] mod tests { use super::*; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 5f953c7c0640..4033b6101bac 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -1163,14 +1163,12 @@ impl_runtime_apis! { // open bridge let bridge_destination_universal_location: InteriorLocation = [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH)), Parachain(8765)].into(); - let locations = XcmOverBridgeHubRococo::bridge_locations( + let _ = XcmOverBridgeHubRococo::open_bridge_for_benchmarks( + bp_messages::LegacyLaneId([1, 2, 3, 4]), sibling_parachain_location.clone(), bridge_destination_universal_location.clone(), - )?; - XcmOverBridgeHubRococo::do_open_bridge( - locations, - bp_messages::LegacyLaneId([1, 2, 3, 4]), true, + None, ).map_err(|e| { log::error!( "Failed to `XcmOverBridgeHubRococo::open_bridge`({:?}, {:?})`, error: {:?}", @@ -1234,26 +1232,32 @@ impl_runtime_apis! { use cumulus_primitives_core::XcmpMessageSource; assert!(XcmpQueue::take_outbound_messages(usize::MAX).is_empty()); ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(42.into()); - let universal_source = bridge_to_rococo_config::open_bridge_for_benchmarks::< - Runtime, - bridge_to_rococo_config::XcmOverBridgeHubRococoInstance, - xcm_config::LocationToAccountId, - >(params.lane, 42); + let bridge_locations = XcmOverBridgeHubRococo::open_bridge_for_benchmarks( + params.lane, + Location::new(1, [Parachain(42)]), + [GlobalConsensus(bridge_to_rococo_config::RococoGlobalConsensusNetwork::get()), Parachain(2075)].into(), + // do not create lanes, because they are already created `params.lane` + false, + None, + ).expect("valid bridge opened"); prepare_message_proof_from_parachain::< Runtime, bridge_to_rococo_config::BridgeGrandpaRococoInstance, bridge_to_rococo_config::WithBridgeHubRococoMessagesInstance, - >(params, generate_xcm_builder_bridge_message_sample(universal_source)) + >(params, generate_xcm_builder_bridge_message_sample(bridge_locations.bridge_origin_universal_location().clone())) } fn prepare_message_delivery_proof( params: MessageDeliveryProofParams>, ) -> bridge_to_rococo_config::ToRococoBridgeHubMessagesDeliveryProof { - let _ = bridge_to_rococo_config::open_bridge_for_benchmarks::< - Runtime, - bridge_to_rococo_config::XcmOverBridgeHubRococoInstance, - xcm_config::LocationToAccountId, - >(params.lane, 42); + let _ = XcmOverBridgeHubRococo::open_bridge_for_benchmarks( + params.lane, + Location::new(1, [Parachain(42)]), + [GlobalConsensus(bridge_to_rococo_config::RococoGlobalConsensusNetwork::get()), Parachain(2075)].into(), + // do not create lanes, because they are already created `params.lane` + false, + None, + ); prepare_message_delivery_proof_from_parachain::< Runtime, bridge_to_rococo_config::BridgeGrandpaRococoInstance,