Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 2bbef46

Browse files
authored
XCM ExportMessage benchmark support (#6923)
* XCM ExportMessage benchmark support * include inner-xcm in ExportMessage benchmark --------- Signed-off-by: acatangiu <[email protected]>
1 parent d8e6ca5 commit 2bbef46

File tree

11 files changed

+64
-8
lines changed

11 files changed

+64
-8
lines changed

runtime/kusama/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,12 @@ sp_api::impl_runtime_apis! {
21072107
// Kusama doesn't support asset locking
21082108
Err(BenchmarkError::Skip)
21092109
}
2110+
2111+
fn export_message_origin_and_destination(
2112+
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
2113+
// Kusama doesn't support exporting messages
2114+
Err(BenchmarkError::Skip)
2115+
}
21102116
}
21112117

21122118
let whitelist: Vec<TrackedStorageKey> = vec![

runtime/kusama/src/weights/xcm/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
243243
Weight::MAX
244244
}
245245
fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
246-
Weight::MAX // todo fix
246+
// Kusama relay should not support export message operations
247+
Weight::MAX
247248
}
248249
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
249250
// Kusama does not currently support asset locking operations

runtime/rococo/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,12 @@ sp_api::impl_runtime_apis! {
21182118
// Rococo doesn't support asset locking
21192119
Err(BenchmarkError::Skip)
21202120
}
2121+
2122+
fn export_message_origin_and_destination(
2123+
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
2124+
// Rococo doesn't support exporting messages
2125+
Err(BenchmarkError::Skip)
2126+
}
21212127
}
21222128

21232129
let whitelist: Vec<TrackedStorageKey> = vec![

runtime/rococo/src/weights/xcm/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for RococoXcmWeight<RuntimeCall> {
243243
Weight::MAX
244244
}
245245
fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
246-
Weight::MAX // todo fix
246+
// Rococo relay should not support export message operations
247+
Weight::MAX
247248
}
248249
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
249250
// Rococo does not currently support asset locking operations

runtime/westend/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,8 +1756,8 @@ sp_api::impl_runtime_apis! {
17561756
impl runtime_parachains::disputes::slashing::benchmarking::Config for Runtime {}
17571757

17581758
use xcm::latest::{
1759-
AssetId::*, Fungibility::*, Junction, Junctions::*, MultiAsset, MultiAssets,
1760-
MultiLocation, Response,
1759+
AssetId::*, Fungibility::*, InteriorMultiLocation, Junction, Junctions::*,
1760+
MultiAsset, MultiAssets, MultiLocation, NetworkId, Response,
17611761
};
17621762
use xcm_config::{Westmint, TokenLocation};
17631763

@@ -1833,6 +1833,12 @@ sp_api::impl_runtime_apis! {
18331833
// Westend doesn't support asset locking
18341834
Err(BenchmarkError::Skip)
18351835
}
1836+
1837+
fn export_message_origin_and_destination(
1838+
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
1839+
// Westend doesn't support exporting messages
1840+
Err(BenchmarkError::Skip)
1841+
}
18361842
}
18371843

18381844
type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;

runtime/westend/src/weights/xcm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
246246
Weight::MAX
247247
}
248248
fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
249-
// Westend does not currently support export message operations
249+
// Westend relay should not support export message operations
250250
Weight::MAX
251251
}
252252
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {

xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,27 @@ benchmarks! {
496496
assert_eq!(executor.origin(), &Some(X1(alias).relative_to(&universal_location)));
497497
}
498498

499+
export_message {
500+
let x in 1 .. 1000;
501+
// The `inner_xcm` influences `ExportMessage` total weight based on
502+
// `inner_xcm.encoded_size()`, so for this benchmark use smallest encoded instruction
503+
// to approximate weight per "unit" of encoded size; then actual weight can be estimated
504+
// to be `inner_xcm.encoded_size() * benchmarked_unit`.
505+
// Use `ClearOrigin` as the small encoded instruction.
506+
let inner_xcm = Xcm(vec![ClearOrigin; x as usize]);
507+
// Get `origin`, `network` and `destination` from configured runtime.
508+
let (origin, network, destination) = T::export_message_origin_and_destination()?;
509+
let mut executor = new_executor::<T>(origin);
510+
let xcm = Xcm(vec![ExportMessage {
511+
network, destination, xcm: inner_xcm,
512+
}]);
513+
}: {
514+
executor.bench_process(xcm)?;
515+
} verify {
516+
// The execute completing successfully is as good as we can check.
517+
// TODO: Potentially add new trait to XcmSender to detect a queued outgoing message. #4426
518+
}
519+
499520
set_fees_mode {
500521
let mut executor = new_executor::<T>(Default::default());
501522
executor.set_fees_mode(FeesMode { jit_withdraw: false });

xcm/pallet-xcm-benchmarks/src/generic/mock.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ impl generic::Config for Test {
186186
let assets: MultiAsset = (Concrete(Here.into()), 100).into();
187187
Ok((Default::default(), Default::default(), assets))
188188
}
189+
190+
fn export_message_origin_and_destination(
191+
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
192+
// No MessageExporter in tests
193+
Err(BenchmarkError::Skip)
194+
}
189195
}
190196

191197
pub fn new_test_ext() -> sp_io::TestExternalities {

xcm/pallet-xcm-benchmarks/src/generic/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ pub mod pallet {
2828
dispatch::{Dispatchable, GetDispatchInfo},
2929
pallet_prelude::Encode,
3030
};
31-
use xcm::latest::{Junction, MultiAsset, MultiAssets, MultiLocation, Response};
31+
use xcm::latest::{
32+
InteriorMultiLocation, Junction, MultiAsset, MultiAssets, MultiLocation, NetworkId,
33+
Response,
34+
};
3235

3336
#[pallet::config]
3437
pub trait Config<I: 'static = ()>: frame_system::Config + crate::Config {
@@ -71,6 +74,12 @@ pub mod pallet {
7174

7275
/// Return an unlocker, owner and assets that can be locked and unlocked.
7376
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError>;
77+
78+
/// A `(MultiLocation, NetworkId, InteriorMultiLocation)` we can successfully export message to.
79+
///
80+
/// If set to `Err`, benchmarks which rely on `export_message` will be skipped.
81+
fn export_message_origin_and_destination(
82+
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError>;
7483
}
7584

7685
#[pallet::pallet]

xcm/xcm-executor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
820820
Ok(())
821821
},
822822
ExportMessage { network, destination, xcm } => {
823-
// The actual message send to the bridge for forwarding is prepended with `UniversalOrigin`
823+
// The actual message sent to the bridge for forwarding is prepended with `UniversalOrigin`
824824
// and `DescendOrigin` in order to ensure that the message is executed with this Origin.
825825
//
826826
// Prepend the desired message with instructions which effectively rewrite the origin.

0 commit comments

Comments
 (0)