diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 3101feb244..626e439eb4 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -2107,6 +2107,12 @@ sp_api::impl_runtime_apis! { // Kusama doesn't support asset locking Err(BenchmarkError::Skip) } + + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { + // Kusama doesn't support exporting messages + Err(BenchmarkError::Skip) + } } let whitelist: Vec = vec![ diff --git a/polkadot/runtime/kusama/src/weights/xcm/mod.rs b/polkadot/runtime/kusama/src/weights/xcm/mod.rs index 1a3630ac24..09c6bfa3a3 100644 --- a/polkadot/runtime/kusama/src/weights/xcm/mod.rs +++ b/polkadot/runtime/kusama/src/weights/xcm/mod.rs @@ -243,7 +243,8 @@ impl XcmWeightInfo for KusamaXcmWeight { Weight::MAX } fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight { - Weight::MAX // todo fix + // Kusama relay should not support export message operations + Weight::MAX } fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { // Kusama does not currently support asset locking operations diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 0d5f9a74a6..2405af9cc1 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -2118,6 +2118,12 @@ sp_api::impl_runtime_apis! { // Rococo doesn't support asset locking Err(BenchmarkError::Skip) } + + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { + // Rococo doesn't support exporting messages + Err(BenchmarkError::Skip) + } } let whitelist: Vec = vec![ diff --git a/polkadot/runtime/rococo/src/weights/xcm/mod.rs b/polkadot/runtime/rococo/src/weights/xcm/mod.rs index fc430805b5..fe894d3ad2 100644 --- a/polkadot/runtime/rococo/src/weights/xcm/mod.rs +++ b/polkadot/runtime/rococo/src/weights/xcm/mod.rs @@ -243,7 +243,8 @@ impl XcmWeightInfo for RococoXcmWeight { Weight::MAX } fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight { - Weight::MAX // todo fix + // Rococo relay should not support export message operations + Weight::MAX } fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { // Rococo does not currently support asset locking operations diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9b213e0078..37695dbcc6 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1756,8 +1756,8 @@ sp_api::impl_runtime_apis! { impl runtime_parachains::disputes::slashing::benchmarking::Config for Runtime {} use xcm::latest::{ - AssetId::*, Fungibility::*, Junction, Junctions::*, MultiAsset, MultiAssets, - MultiLocation, Response, + AssetId::*, Fungibility::*, InteriorMultiLocation, Junction, Junctions::*, + MultiAsset, MultiAssets, MultiLocation, NetworkId, Response, }; use xcm_config::{Westmint, TokenLocation}; @@ -1833,6 +1833,12 @@ sp_api::impl_runtime_apis! { // Westend doesn't support asset locking Err(BenchmarkError::Skip) } + + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { + // Westend doesn't support exporting messages + Err(BenchmarkError::Skip) + } } type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; diff --git a/polkadot/runtime/westend/src/weights/xcm/mod.rs b/polkadot/runtime/westend/src/weights/xcm/mod.rs index 8b8c533970..4fb27c1209 100644 --- a/polkadot/runtime/westend/src/weights/xcm/mod.rs +++ b/polkadot/runtime/westend/src/weights/xcm/mod.rs @@ -246,7 +246,7 @@ impl XcmWeightInfo for WestendXcmWeight { Weight::MAX } fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight { - // Westend does not currently support export message operations + // Westend relay should not support export message operations Weight::MAX } fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs index 3976c482eb..19aecdd47c 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs @@ -496,6 +496,27 @@ benchmarks! { assert_eq!(executor.origin(), &Some(X1(alias).relative_to(&universal_location))); } + export_message { + let x in 1 .. 1000; + // The `inner_xcm` influences `ExportMessage` total weight based on + // `inner_xcm.encoded_size()`, so for this benchmark use smallest encoded instruction + // to approximate weight per "unit" of encoded size; then actual weight can be estimated + // to be `inner_xcm.encoded_size() * benchmarked_unit`. + // Use `ClearOrigin` as the small encoded instruction. + let inner_xcm = Xcm(vec![ClearOrigin; x as usize]); + // Get `origin`, `network` and `destination` from configured runtime. + let (origin, network, destination) = T::export_message_origin_and_destination()?; + let mut executor = new_executor::(origin); + let xcm = Xcm(vec![ExportMessage { + network, destination, xcm: inner_xcm, + }]); + }: { + executor.bench_process(xcm)?; + } verify { + // The execute completing successfully is as good as we can check. + // TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426 + } + set_fees_mode { let mut executor = new_executor::(Default::default()); executor.set_fees_mode(FeesMode { jit_withdraw: false }); diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index 79f9f28e32..c76a9f2759 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -186,6 +186,12 @@ impl generic::Config for Test { let assets: MultiAsset = (Concrete(Here.into()), 100).into(); Ok((Default::default(), Default::default(), assets)) } + + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> { + // No MessageExporter in tests + Err(BenchmarkError::Skip) + } } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs index 8fee41142f..b12ac0ba23 100644 --- a/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs +++ b/polkadot/xcm/pallet-xcm-benchmarks/src/generic/mod.rs @@ -28,7 +28,10 @@ pub mod pallet { dispatch::{Dispatchable, GetDispatchInfo}, pallet_prelude::Encode, }; - use xcm::latest::{Junction, MultiAsset, MultiAssets, MultiLocation, Response}; + use xcm::latest::{ + InteriorMultiLocation, Junction, MultiAsset, MultiAssets, MultiLocation, NetworkId, + Response, + }; #[pallet::config] pub trait Config: frame_system::Config + crate::Config { @@ -71,6 +74,12 @@ pub mod pallet { /// Return an unlocker, owner and assets that can be locked and unlocked. fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError>; + + /// A `(MultiLocation, NetworkId, InteriorMultiLocation)` we can successfully export message to. + /// + /// If set to `Err`, benchmarks which rely on `export_message` will be skipped. + fn export_message_origin_and_destination( + ) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError>; } #[pallet::pallet] diff --git a/polkadot/xcm/xcm-executor/src/lib.rs b/polkadot/xcm/xcm-executor/src/lib.rs index c4d3e2768a..4e63ad9147 100644 --- a/polkadot/xcm/xcm-executor/src/lib.rs +++ b/polkadot/xcm/xcm-executor/src/lib.rs @@ -820,7 +820,7 @@ impl XcmExecutor { Ok(()) }, ExportMessage { network, destination, xcm } => { - // The actual message send to the bridge for forwarding is prepended with `UniversalOrigin` + // The actual message sent to the bridge for forwarding is prepended with `UniversalOrigin` // and `DescendOrigin` in order to ensure that the message is executed with this Origin. // // Prepend the desired message with instructions which effectively rewrite the origin. diff --git a/polkadot/xcm/xcm-executor/src/traits/export.rs b/polkadot/xcm/xcm-executor/src/traits/export.rs index 61b76addfe..ef8daa3c82 100644 --- a/polkadot/xcm/xcm-executor/src/traits/export.rs +++ b/polkadot/xcm/xcm-executor/src/traits/export.rs @@ -31,7 +31,7 @@ use xcm::latest::prelude::*; /// destination must accept the local location to represent that location or the operation will /// fail. pub trait ExportXcm { - /// Intermediate value which connects the two phaases of the export operation. + /// Intermediate value which connects the two phases of the export operation. type Ticket; /// Check whether the given `message` is deliverable to the given `destination` on `network`,