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

Commit

Permalink
XCM ExportMessage benchmark support
Browse files Browse the repository at this point in the history
Signed-off-by: acatangiu <adrian@parity.io>
  • Loading branch information
acatangiu committed Mar 21, 2023
1 parent 395e45f commit fecbf12
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 7 deletions.
5 changes: 5 additions & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,11 @@ sp_api::impl_runtime_apis! {
// Kusama doesn't support asset locking
Err(BenchmarkError::Skip)
}

fn bridged_destination() -> Result<(NetworkId, InteriorMultiLocation), BenchmarkError> {
// Kusama doesn't support exporting messages
Err(BenchmarkError::Skip)
}
}

let whitelist: Vec<TrackedStorageKey> = vec![
Expand Down
3 changes: 2 additions & 1 deletion runtime/kusama/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
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
Expand Down
5 changes: 5 additions & 0 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,11 @@ sp_api::impl_runtime_apis! {
// Rococo doesn't support asset locking
Err(BenchmarkError::Skip)
}

fn bridged_destination() -> Result<(NetworkId, InteriorMultiLocation), BenchmarkError> {
// Rococo doesn't support exporting messages
Err(BenchmarkError::Skip)
}
}

let whitelist: Vec<TrackedStorageKey> = vec![
Expand Down
3 changes: 2 additions & 1 deletion runtime/rococo/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for RococoXcmWeight<RuntimeCall> {
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
Expand Down
9 changes: 7 additions & 2 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,8 +1741,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};

Expand Down Expand Up @@ -1818,6 +1818,11 @@ sp_api::impl_runtime_apis! {
// Westend doesn't support asset locking
Err(BenchmarkError::Skip)
}

fn bridged_destination() -> Result<(NetworkId, InteriorMultiLocation), BenchmarkError> {
// Westend doesn't support exporting messages
Err(BenchmarkError::Skip)
}
}

type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/westend/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
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 {
Expand Down
17 changes: 17 additions & 0 deletions xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,23 @@ benchmarks! {
assert_eq!(executor.origin(), &Some(X1(alias).relative_to(&universal_location)));
}

export_message {
let mut executor = new_executor::<T>(Here.into_location());
let (network, destination) = T::bridged_destination()?;
let expected_message = Xcm(vec![TransferAsset {
assets: (Here, 100u128).into(),
beneficiary: Parachain(2).into(),
}]);
let xcm = Xcm(vec![ExportMessage {
network, destination, xcm: expected_message.clone(),
}]);
}: {
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::<T>(Default::default());
executor.set_fees_mode(FeesMode { jit_withdraw: false });
Expand Down
5 changes: 5 additions & 0 deletions xcm/pallet-xcm-benchmarks/src/generic/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ impl generic::Config for Test {
let assets: MultiAsset = (Concrete(Here.into()), 100).into();
Ok((Default::default(), Default::default(), assets))
}

fn bridged_destination() -> Result<(NetworkId, InteriorMultiLocation), BenchmarkError> {
// No MessageExporter in tests
Err(BenchmarkError::Skip)
}
}

pub fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
10 changes: 9 additions & 1 deletion xcm/pallet-xcm-benchmarks/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I: 'static = ()>: frame_system::Config + crate::Config {
Expand Down Expand Up @@ -71,6 +74,11 @@ pub mod pallet {

/// Return an unlocker, owner and assets that can be locked and unlocked.
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError>;

/// A valid `(NetworkId, InteriorMultiLocation)` we can successfully export message to.
///
/// If set to `Err`, benchmarks which rely on `export_message` will be skipped.
fn bridged_destination() -> Result<(NetworkId, InteriorMultiLocation), BenchmarkError>;
}

#[pallet::pallet]
Expand Down
2 changes: 1 addition & 1 deletion xcm/xcm-executor/src/traits/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down

0 comments on commit fecbf12

Please sign in to comment.