# Note for reviewer

Most changes are just syntax changes necessary for the new version.
Most important files should be the ones under the `xcm` folder.

# Description 

Added XCMv4.

## Removed `Multi` prefix
The following types have been renamed:
- MultiLocation -> Location
- MultiAsset -> Asset
- MultiAssets -> Assets
- InteriorMultiLocation -> InteriorLocation
- MultiAssetFilter -> AssetFilter
- VersionedMultiAsset -> VersionedAsset
- WildMultiAsset -> WildAsset
- VersionedMultiLocation -> VersionedLocation

In order to fix a name conflict, the `Assets` in `xcm-executor` were
renamed to `HoldingAssets`, as they represent assets in holding.

## Removed `Abstract` asset id

It was not being used anywhere and this simplifies the code.

Now assets are just constructed as follows:

```rust
let asset: Asset = (AssetId(Location::new(1, Here)), 100u128).into();
```

No need for specifying `Concrete` anymore.

## Outcome is now a named fields struct

Instead of

```rust
pub enum Outcome {
  Complete(Weight),
  Incomplete(Weight, Error),
  Error(Error),
}
```

we now have

```rust
pub enum Outcome {
  Complete { used: Weight },
  Incomplete { used: Weight, error: Error },
  Error { error: Error },
}
```

## Added Reanchorable trait

Now both locations and assets implement this trait, making it easier to
reanchor both.

## New syntax for building locations and junctions

Now junctions are built using the following methods:

```rust
let location = Location {
    parents: 1,
    interior: [Parachain(1000), PalletInstance(50), GeneralIndex(1984)].into()
};
```

or

```rust
let location = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1984)]);
```

And they are matched like so:

```rust
match location.unpack() {
  (1, [Parachain(id)]) => ...
  (0, Here) => ...,
  (1, [_]) => ...,
}
```

This syntax is mandatory in v4, and has been also implemented for v2 and
v3 for easier migration.

This was needed to make all sizes smaller.

# TODO
- [x] Scaffold v4
- [x] Port github.com/paritytech/polkadot/pull/7236
- [x] Remove `Multi` prefix
- [x] Remove `Abstract` asset id

---------

Co-authored-by: command-bot <>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Francisco Aguirre
2024-01-16 19:18:04 +01:00
committed by GitHub
parent ec7bfae00a
commit 8428f678fe
255 changed files with 12425 additions and 6726 deletions
@@ -24,7 +24,7 @@ use frame_support::{
};
use sp_runtime::traits::{Bounded, Zero};
use sp_std::{prelude::*, vec};
use xcm::latest::{prelude::*, MAX_ITEMS_IN_MULTIASSETS};
use xcm::latest::{prelude::*, MAX_ITEMS_IN_ASSETS};
use xcm_executor::traits::{ConvertLocation, FeeReason, TransactAsset};
benchmarks_instance_pallet! {
@@ -43,7 +43,7 @@ benchmarks_instance_pallet! {
withdraw_asset {
let (sender_account, sender_location) = account_and_location::<T>(1);
let worst_case_holding = T::worst_case_holding(0);
let asset = T::get_multi_asset();
let asset = T::get_asset();
<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location, None).unwrap();
// check the assets of origin.
@@ -63,8 +63,8 @@ benchmarks_instance_pallet! {
transfer_asset {
let (sender_account, sender_location) = account_and_location::<T>(1);
let asset = T::get_multi_asset();
let assets: MultiAssets = vec![ asset.clone() ].into();
let asset = T::get_asset();
let assets: Assets = vec![ asset.clone() ].into();
// this xcm doesn't use holding
let dest_location = T::valid_destination()?;
@@ -95,10 +95,10 @@ benchmarks_instance_pallet! {
);
let sender_account_balance_before = T::TransactAsset::balance(&sender_account);
let asset = T::get_multi_asset();
let asset = T::get_asset();
<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location, None).unwrap();
assert!(T::TransactAsset::balance(&sender_account) > sender_account_balance_before);
let assets: MultiAssets = vec![ asset ].into();
let assets: Assets = vec![asset].into();
assert!(T::TransactAsset::balance(&dest_account).is_zero());
let mut executor = new_executor::<T>(sender_location);
@@ -129,7 +129,7 @@ benchmarks_instance_pallet! {
BenchmarkResult::from_weight(Weight::MAX)
))?;
let assets: MultiAssets = vec![ transferable_reserve_asset ].into();
let assets: Assets = vec![ transferable_reserve_asset ].into();
let mut executor = new_executor::<T>(trusted_reserve);
let instruction = Instruction::ReserveAssetDeposited(assets.clone());
@@ -143,7 +143,7 @@ benchmarks_instance_pallet! {
initiate_reserve_withdraw {
let (sender_account, sender_location) = account_and_location::<T>(1);
let holding = T::worst_case_holding(1);
let assets_filter = MultiAssetFilter::Definite(holding.clone().into_inner().into_iter().take(MAX_ITEMS_IN_MULTIASSETS).collect::<Vec<_>>().into());
let assets_filter = AssetFilter::Definite(holding.clone().into_inner().into_iter().take(MAX_ITEMS_IN_ASSETS).collect::<Vec<_>>().into());
let reserve = T::valid_destination().map_err(|_| BenchmarkError::Skip)?;
let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery(
@@ -188,7 +188,7 @@ benchmarks_instance_pallet! {
)?;
}
let assets: MultiAssets = vec![ teleportable_asset ].into();
let assets: Assets = vec![ teleportable_asset ].into();
let mut executor = new_executor::<T>(trusted_teleporter);
let instruction = Instruction::ReceiveTeleportedAsset(assets.clone());
@@ -204,7 +204,7 @@ benchmarks_instance_pallet! {
}
deposit_asset {
let asset = T::get_multi_asset();
let asset = T::get_asset();
let mut holding = T::worst_case_holding(1);
// Add our asset to the holding.
@@ -230,7 +230,7 @@ benchmarks_instance_pallet! {
}
deposit_reserve_asset {
let asset = T::get_multi_asset();
let asset = T::get_asset();
let mut holding = T::worst_case_holding(1);
// Add our asset to the holding.
@@ -257,7 +257,7 @@ benchmarks_instance_pallet! {
}
initiate_teleport {
let asset = T::get_multi_asset();
let asset = T::get_asset();
let mut holding = T::worst_case_holding(0);
// Add our asset to the holding.
@@ -93,10 +93,10 @@ parameter_types! {
pub struct MatchAnyFungible;
impl xcm_executor::traits::MatchesFungible<u64> for MatchAnyFungible {
fn matches_fungible(m: &MultiAsset) -> Option<u64> {
fn matches_fungible(m: &Asset) -> Option<u64> {
use sp_runtime::traits::SaturatedConversion;
match m {
MultiAsset { fun: Fungible(amount), .. } => Some((*amount).saturated_into::<u64>()),
Asset { fun: Fungible(amount), .. } => Some((*amount).saturated_into::<u64>()),
_ => None,
}
}
@@ -151,13 +151,12 @@ impl crate::Config for Test {
type XcmConfig = XcmConfig;
type AccountIdConverter = AccountIdConverter;
type DeliveryHelper = ();
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
let valid_destination: MultiLocation =
X1(AccountId32 { network: None, id: [0u8; 32] }).into();
fn valid_destination() -> Result<Location, BenchmarkError> {
let valid_destination: Location = [AccountId32 { network: None, id: [0u8; 32] }].into();
Ok(valid_destination)
}
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
fn worst_case_holding(depositable_count: u32) -> Assets {
crate::mock_worst_case_holding(
depositable_count,
<XcmConfig as xcm_executor::Config>::MaxAssetsIntoHolding::get(),
@@ -170,19 +169,19 @@ pub type TrustedReserves = xcm_builder::Case<ReserveConcreteFungible>;
parameter_types! {
pub const CheckingAccount: Option<(u64, MintLocation)> = Some((100, MintLocation::Local));
pub const ChildTeleporter: MultiLocation = Parachain(1000).into_location();
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
pub ChildTeleporter: Location = Parachain(1000).into_location();
pub TrustedTeleporter: Option<(Location, Asset)> = Some((
ChildTeleporter::get(),
MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) },
Asset { id: AssetId(Here.into_location()), fun: Fungible(100) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
pub TrustedReserve: Option<(Location, Asset)> = Some((
ChildTeleporter::get(),
MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) },
Asset { id: AssetId(Here.into_location()), fun: Fungible(100) },
));
pub const TeleportConcreteFungible: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get());
pub const ReserveConcreteFungible: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get());
pub TeleportConcreteFungible: (AssetFilter, Location) =
(Wild(AllOf { fun: WildFungible, id: AssetId(Here.into_location()) }), ChildTeleporter::get());
pub ReserveConcreteFungible: (AssetFilter, Location) =
(Wild(AllOf { fun: WildFungible, id: AssetId(Here.into_location()) }), ChildTeleporter::get());
}
impl xcm_balances_benchmark::Config for Test {
@@ -191,10 +190,10 @@ impl xcm_balances_benchmark::Config for Test {
type TrustedTeleporter = TrustedTeleporter;
type TrustedReserve = TrustedReserve;
fn get_multi_asset() -> MultiAsset {
fn get_asset() -> Asset {
let amount =
<Balances as frame_support::traits::fungible::Inspect<u64>>::minimum_balance() as u128;
MultiAsset { id: Concrete(Here.into()), fun: Fungible(amount) }
Asset { id: AssetId(Here.into()), fun: Fungible(amount) }
}
}
@@ -37,14 +37,14 @@ pub mod pallet {
type CheckedAccount: Get<Option<(Self::AccountId, xcm_builder::MintLocation)>>;
/// A trusted location which we allow teleports from, and the asset we allow to teleport.
type TrustedTeleporter: Get<Option<(xcm::latest::MultiLocation, xcm::latest::MultiAsset)>>;
type TrustedTeleporter: Get<Option<(xcm::latest::Location, xcm::latest::Asset)>>;
/// A trusted location where reserve assets are stored, and the asset we allow to be
/// reserves.
type TrustedReserve: Get<Option<(xcm::latest::MultiLocation, xcm::latest::MultiAsset)>>;
type TrustedReserve: Get<Option<(xcm::latest::Location, xcm::latest::Asset)>>;
/// Give me a fungible asset that your asset transactor is going to accept.
fn get_multi_asset() -> xcm::latest::MultiAsset;
fn get_asset() -> xcm::latest::Asset;
}
#[pallet::pallet]
@@ -77,7 +77,7 @@ benchmarks! {
let mut executor = new_executor::<T>(Default::default());
executor.set_holding(holding);
let fee_asset = Concrete(Here.into());
let fee_asset = AssetId(Here.into());
let instruction = Instruction::<XcmCallOf<T>>::BuyExecution {
fees: (fee_asset, 100_000_000u128).into(), // should be something inside of holding
@@ -95,7 +95,7 @@ benchmarks! {
let mut executor = new_executor::<T>(Default::default());
let (query_id, response) = T::worst_case_response();
let max_weight = Weight::MAX;
let querier: Option<MultiLocation> = Some(Here.into());
let querier: Option<Location> = Some(Here.into());
let instruction = Instruction::QueryResponse { query_id, response, max_weight, querier };
let xcm = Xcm(vec![instruction]);
}: {
@@ -174,15 +174,15 @@ benchmarks! {
descend_origin {
let mut executor = new_executor::<T>(Default::default());
let who = X2(OnlyChild, OnlyChild);
let instruction = Instruction::DescendOrigin(who);
let who = Junctions::from([OnlyChild, OnlyChild]);
let instruction = Instruction::DescendOrigin(who.clone());
let xcm = Xcm(vec![instruction]);
} : {
executor.bench_process(xcm)?;
} verify {
assert_eq!(
executor.origin(),
&Some(MultiLocation {
&Some(Location {
parents: 0,
interior: who,
}),
@@ -242,7 +242,7 @@ benchmarks! {
&origin,
assets.clone().into(),
&XcmContext {
origin: Some(origin),
origin: Some(origin.clone()),
message_id: [0; 32],
topic: None,
},
@@ -279,7 +279,7 @@ benchmarks! {
let origin = T::subscribe_origin()?;
let query_id = Default::default();
let max_response_weight = Default::default();
let mut executor = new_executor::<T>(origin);
let mut executor = new_executor::<T>(origin.clone());
let instruction = Instruction::SubscribeVersion { query_id, max_response_weight };
let xcm = Xcm(vec![instruction]);
} : {
@@ -299,14 +299,14 @@ benchmarks! {
query_id,
max_response_weight,
&XcmContext {
origin: Some(origin),
origin: Some(origin.clone()),
message_id: [0; 32],
topic: None,
},
).map_err(|_| "Could not start subscription")?;
assert!(<T::XcmConfig as xcm_executor::Config>::SubscriptionService::is_subscribed(&origin));
let mut executor = new_executor::<T>(origin);
let mut executor = new_executor::<T>(origin.clone());
let instruction = Instruction::UnsubscribeVersion;
let xcm = Xcm(vec![instruction]);
} : {
@@ -545,7 +545,7 @@ benchmarks! {
} verify {
use frame_support::traits::Get;
let universal_location = <T::XcmConfig as xcm_executor::Config>::UniversalLocation::get();
assert_eq!(executor.origin(), &Some(X1(alias).relative_to(&universal_location)));
assert_eq!(executor.origin(), &Some(Junctions::from([alias]).relative_to(&universal_location)));
}
export_message {
@@ -561,8 +561,8 @@ benchmarks! {
let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery(
&origin,
&destination.into(),
FeeReason::Export { network, destination },
&destination.clone().into(),
FeeReason::Export { network, destination: destination.clone() },
);
let sender_account = T::AccountIdConverter::convert_location(&origin).unwrap();
let sender_account_balance_before = T::TransactAsset::balance(&sender_account);
@@ -575,7 +575,7 @@ benchmarks! {
executor.set_holding(expected_assets_in_holding.into());
}
let xcm = Xcm(vec![ExportMessage {
network, destination, xcm: inner_xcm,
network, destination: destination.clone(), xcm: inner_xcm,
}]);
}: {
executor.bench_process(xcm)?;
@@ -632,13 +632,13 @@ benchmarks! {
let (unlocker, owner, asset) = T::unlockable_asset()?;
let mut executor = new_executor::<T>(unlocker);
let mut executor = new_executor::<T>(unlocker.clone());
// We first place the asset in lock first...
<T::XcmConfig as xcm_executor::Config>::AssetLocker::prepare_lock(
unlocker,
asset.clone(),
owner,
owner.clone(),
)
.map_err(|_| BenchmarkError::Skip)?
.enact()
@@ -658,13 +658,13 @@ benchmarks! {
let (unlocker, owner, asset) = T::unlockable_asset()?;
let mut executor = new_executor::<T>(unlocker);
let mut executor = new_executor::<T>(unlocker.clone());
// We first place the asset in lock first...
<T::XcmConfig as xcm_executor::Config>::AssetLocker::prepare_lock(
unlocker,
asset.clone(),
owner,
owner.clone(),
)
.map_err(|_| BenchmarkError::Skip)?
.enact()
@@ -686,9 +686,9 @@ benchmarks! {
// We first place the asset in lock first...
<T::XcmConfig as xcm_executor::Config>::AssetLocker::prepare_lock(
locker,
locker.clone(),
asset.clone(),
owner,
owner.clone(),
)
.map_err(|_| BenchmarkError::Skip)?
.enact()
@@ -739,7 +739,7 @@ benchmarks! {
let mut executor = new_executor::<T>(origin);
let instruction = Instruction::AliasOrigin(target);
let instruction = Instruction::AliasOrigin(target.clone());
let xcm = Xcm(vec![instruction]);
}: {
executor.bench_process(xcm)?;
@@ -19,16 +19,16 @@
use crate::{generic, mock::*, *};
use codec::Decode;
use frame_support::{
derive_impl, match_types, parameter_types,
traits::{Everything, OriginTrait},
derive_impl, parameter_types,
traits::{Contains, Everything, OriginTrait},
weights::Weight,
};
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput};
use xcm_builder::{
test_utils::{
Assets, TestAssetExchanger, TestAssetLocker, TestAssetTrap, TestSubscriptionService,
TestUniversalAliases,
AssetsInHolding, TestAssetExchanger, TestAssetLocker, TestAssetTrap,
TestSubscriptionService, TestUniversalAliases,
},
AliasForeignAccountId32, AllowUnpaidExecutionFrom,
};
@@ -81,19 +81,15 @@ impl frame_system::Config for Test {
/// The benchmarks in this pallet should never need an asset transactor to begin with.
pub struct NoAssetTransactor;
impl xcm_executor::traits::TransactAsset for NoAssetTransactor {
fn deposit_asset(
_: &MultiAsset,
_: &MultiLocation,
_: Option<&XcmContext>,
) -> Result<(), XcmError> {
fn deposit_asset(_: &Asset, _: &Location, _: Option<&XcmContext>) -> Result<(), XcmError> {
unreachable!();
}
fn withdraw_asset(
_: &MultiAsset,
_: &MultiLocation,
_: &Asset,
_: &Location,
_: Option<&XcmContext>,
) -> Result<Assets, XcmError> {
) -> Result<AssetsInHolding, XcmError> {
unreachable!();
}
}
@@ -103,10 +99,11 @@ parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
}
match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
};
pub struct OnlyParachains;
impl Contains<Location> for OnlyParachains {
fn contains(location: &Location) -> bool {
matches!(location.unpack(), (0, [Parachain(_)]))
}
}
type Aliasers = AliasForeignAccountId32<OnlyParachains>;
@@ -153,13 +150,13 @@ impl crate::Config for Test {
type XcmConfig = XcmConfig;
type AccountIdConverter = AccountIdConverter;
type DeliveryHelper = ();
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
let valid_destination: MultiLocation =
fn valid_destination() -> Result<Location, BenchmarkError> {
let valid_destination: Location =
Junction::AccountId32 { network: None, id: [0u8; 32] }.into();
Ok(valid_destination)
}
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
fn worst_case_holding(depositable_count: u32) -> Assets {
crate::mock_worst_case_holding(
depositable_count,
<XcmConfig as xcm_executor::Config>::MaxAssetsIntoHolding::get(),
@@ -172,48 +169,47 @@ impl generic::Config for Test {
type RuntimeCall = RuntimeCall;
fn worst_case_response() -> (u64, Response) {
let assets: MultiAssets = (Concrete(Here.into()), 100).into();
let assets: Assets = (AssetId(Here.into()), 100).into();
(0, Response::Assets(assets))
}
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> {
Ok(Default::default())
}
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> {
fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
Ok((Here.into(), GlobalConsensus(ByGenesis([0; 32]))))
}
fn transact_origin_and_runtime_call(
) -> Result<(MultiLocation, <Self as generic::Config>::RuntimeCall), BenchmarkError> {
) -> Result<(Location, <Self as generic::Config>::RuntimeCall), BenchmarkError> {
Ok((Default::default(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
}
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
fn subscribe_origin() -> Result<Location, BenchmarkError> {
Ok(Default::default())
}
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
let assets: MultiAssets = (Concrete(Here.into()), 100).into();
let ticket = MultiLocation { parents: 0, interior: X1(GeneralIndex(0)) };
fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
let assets: Assets = (AssetId(Here.into()), 100).into();
let ticket = Location { parents: 0, interior: [GeneralIndex(0)].into() };
Ok((Default::default(), ticket, assets))
}
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
let assets: MultiAsset = (Concrete(Here.into()), 100).into();
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
let assets: Asset = (AssetId(Here.into()), 100).into();
Ok((Default::default(), account_id_junction::<Test>(1).into(), assets))
}
fn export_message_origin_and_destination(
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
// No MessageExporter in tests
Err(BenchmarkError::Skip)
}
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
let origin: MultiLocation =
(Parachain(1), AccountId32 { network: None, id: [0; 32] }).into();
let target: MultiLocation = AccountId32 { network: None, id: [0; 32] }.into();
fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
let origin: Location = (Parachain(1), AccountId32 { network: None, id: [0; 32] }).into();
let target: Location = AccountId32 { network: None, id: [0; 32] }.into();
Ok((origin, target))
}
}
@@ -233,9 +229,9 @@ where
<RuntimeOrigin as OriginTrait>::AccountId: Decode,
{
fn convert_origin(
_origin: impl Into<MultiLocation>,
_origin: impl Into<Location>,
_kind: OriginKind,
) -> Result<RuntimeOrigin, MultiLocation> {
) -> Result<RuntimeOrigin, Location> {
Ok(RuntimeOrigin::signed(
<RuntimeOrigin as OriginTrait>::AccountId::decode(&mut TrailingZeroInput::zeroes())
.expect("infinite length input; no invalid inputs for type; qed"),
@@ -26,10 +26,7 @@ pub mod pallet {
use frame_benchmarking::BenchmarkError;
use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::Encode};
use sp_runtime::traits::Dispatchable;
use xcm::latest::{
InteriorMultiLocation, Junction, MultiAsset, MultiAssets, MultiLocation, NetworkId,
Response,
};
use xcm::latest::{Asset, Assets, InteriorLocation, Junction, Location, NetworkId, Response};
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config + crate::Config {
@@ -53,44 +50,44 @@ pub mod pallet {
/// from, whereas the second element represents the assets that are being exchanged to.
///
/// If set to `Err`, benchmarks which rely on an `exchange_asset` will be skipped.
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError>;
fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError>;
/// A `(MultiLocation, Junction)` that is one of the `UniversalAliases` configured by the
/// A `(Location, Junction)` that is one of the `UniversalAliases` configured by the
/// XCM executor.
///
/// If set to `Err`, benchmarks which rely on a universal alias will be skipped.
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError>;
fn universal_alias() -> Result<(Location, Junction), BenchmarkError>;
/// The `MultiLocation` and `RuntimeCall` used for successful transaction XCMs.
/// The `Location` and `RuntimeCall` used for successful transaction XCMs.
///
/// If set to `Err`, benchmarks which rely on a `transact_origin_and_runtime_call` will be
/// skipped.
fn transact_origin_and_runtime_call(
) -> Result<(MultiLocation, <Self as crate::generic::Config<I>>::RuntimeCall), BenchmarkError>;
) -> Result<(Location, <Self as crate::generic::Config<I>>::RuntimeCall), BenchmarkError>;
/// A valid `MultiLocation` we can successfully subscribe to.
/// A valid `Location` we can successfully subscribe to.
///
/// If set to `Err`, benchmarks which rely on a `subscribe_origin` will be skipped.
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError>;
fn subscribe_origin() -> Result<Location, BenchmarkError>;
/// Return an origin, ticket, and assets that can be trapped and claimed.
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError>;
fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError>;
/// Return an unlocker, owner and assets that can be locked and unlocked.
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError>;
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError>;
/// A `(MultiLocation, NetworkId, InteriorMultiLocation)` we can successfully export message
/// A `(Location, NetworkId, InteriorLocation)` 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>;
) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError>;
/// A `(MultiLocation, MultiLocation)` that is one of the `Aliasers` configured by the XCM
/// A `(Location, Location)` that is one of the `Aliasers` configured by the XCM
/// executor.
///
/// If set to `Err`, benchmarks which rely on a universal alias will be skipped.
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError>;
fn alias_origin() -> Result<(Location, Location), BenchmarkError>;
/// Returns a valid pallet info for `ExpectPallet` or `QueryPallet` benchmark.
///
+21 -21
View File
@@ -41,18 +41,18 @@ pub trait Config: frame_system::Config {
/// `TransactAsset` is implemented.
type XcmConfig: XcmConfig;
/// A converter between a multi-location to a sovereign account.
/// A converter between a location to a sovereign account.
type AccountIdConverter: ConvertLocation<Self::AccountId>;
/// Helper that ensures successful delivery for XCM instructions which need `SendXcm`.
type DeliveryHelper: EnsureDelivery;
/// Does any necessary setup to create a valid destination for XCM messages.
/// Returns that destination's multi-location to be used in benchmarks.
fn valid_destination() -> Result<MultiLocation, BenchmarkError>;
/// Returns that destination's location to be used in benchmarks.
fn valid_destination() -> Result<Location, BenchmarkError>;
/// Worst case scenario for a holding account in this runtime.
fn worst_case_holding(depositable_count: u32) -> MultiAssets;
fn worst_case_holding(depositable_count: u32) -> Assets;
}
const SEED: u32 = 0;
@@ -66,21 +66,21 @@ pub type AssetTransactorOf<T> = <<T as Config>::XcmConfig as XcmConfig>::AssetTr
/// The call type of executor's config. Should eventually resolve to the same overarching call type.
pub type XcmCallOf<T> = <<T as Config>::XcmConfig as XcmConfig>::RuntimeCall;
pub fn mock_worst_case_holding(depositable_count: u32, max_assets: u32) -> MultiAssets {
pub fn mock_worst_case_holding(depositable_count: u32, max_assets: u32) -> Assets {
let fungibles_amount: u128 = 100;
let holding_fungibles = max_assets / 2 - depositable_count;
let holding_non_fungibles = holding_fungibles;
(0..holding_fungibles)
.map(|i| {
MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
Asset {
id: AssetId(GeneralIndex(i as u128).into()),
fun: Fungible(fungibles_amount * i as u128),
}
.into()
})
.chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) }))
.chain((0..holding_non_fungibles).map(|i| MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
.chain(core::iter::once(Asset { id: AssetId(Here.into()), fun: Fungible(u128::MAX) }))
.chain((0..holding_non_fungibles).map(|i| Asset {
id: AssetId(GeneralIndex(i as u128).into()),
fun: NonFungible(asset_instance_from(i)),
}))
.collect::<Vec<_>>()
@@ -94,11 +94,11 @@ pub fn asset_instance_from(x: u32) -> AssetInstance {
AssetInstance::Array4(instance)
}
pub fn new_executor<T: Config>(origin: MultiLocation) -> ExecutorOf<T> {
pub fn new_executor<T: Config>(origin: Location) -> ExecutorOf<T> {
ExecutorOf::<T>::new(origin, [0; 32])
}
/// Build a multi-location from an account id.
/// Build a location from an account id.
fn account_id_junction<T: frame_system::Config>(index: u32) -> Junction {
let account: T::AccountId = account("account", index, SEED);
let mut encoded = account.encode();
@@ -108,8 +108,8 @@ fn account_id_junction<T: frame_system::Config>(index: u32) -> Junction {
Junction::AccountId32 { network: None, id }
}
pub fn account_and_location<T: Config>(index: u32) -> (T::AccountId, MultiLocation) {
let location: MultiLocation = account_id_junction::<T>(index).into();
pub fn account_and_location<T: Config>(index: u32) -> (T::AccountId, Location) {
let location: Location = account_id_junction::<T>(index).into();
let account = T::AccountIdConverter::convert_location(&location).unwrap();
(account, location)
@@ -121,21 +121,21 @@ pub trait EnsureDelivery {
/// Prepare all requirements for successful `XcmSender: SendXcm` passing (accounts, balances,
/// channels ...). Returns:
/// - possible `FeesMode` which is expected to be set to executor
/// - possible `MultiAssets` which are expected to be subsume to the Holding Register
/// - possible `Assets` which are expected to be subsume to the Holding Register
fn ensure_successful_delivery(
origin_ref: &MultiLocation,
dest: &MultiLocation,
origin_ref: &Location,
dest: &Location,
fee_reason: FeeReason,
) -> (Option<FeesMode>, Option<MultiAssets>);
) -> (Option<FeesMode>, Option<Assets>);
}
/// `()` implementation does nothing which means no special requirements for environment.
impl EnsureDelivery for () {
fn ensure_successful_delivery(
_origin_ref: &MultiLocation,
_dest: &MultiLocation,
_origin_ref: &Location,
_dest: &Location,
_fee_reason: FeeReason,
) -> (Option<FeesMode>, Option<MultiAssets>) {
) -> (Option<FeesMode>, Option<Assets>) {
// doing nothing
(None, None)
}
+12 -12
View File
@@ -22,8 +22,8 @@ use xcm::latest::Weight;
pub struct DevNull;
impl xcm::opaque::latest::SendXcm for DevNull {
type Ticket = ();
fn validate(_: &mut Option<MultiLocation>, _: &mut Option<Xcm<()>>) -> SendResult<()> {
Ok(((), MultiAssets::new()))
fn validate(_: &mut Option<Location>, _: &mut Option<Xcm<()>>) -> SendResult<()> {
Ok(((), Assets::new()))
}
fn deliver(_: ()) -> Result<XcmHash, SendError> {
Ok([0; 32])
@@ -31,13 +31,13 @@ impl xcm::opaque::latest::SendXcm for DevNull {
}
impl xcm_executor::traits::OnResponse for DevNull {
fn expecting_response(_: &MultiLocation, _: u64, _: Option<&MultiLocation>) -> bool {
fn expecting_response(_: &Location, _: u64, _: Option<&Location>) -> bool {
false
}
fn on_response(
_: &MultiLocation,
_: &Location,
_: u64,
_: Option<&MultiLocation>,
_: Option<&Location>,
_: Response,
_: Weight,
_: &XcmContext,
@@ -48,9 +48,9 @@ impl xcm_executor::traits::OnResponse for DevNull {
pub struct AccountIdConverter;
impl xcm_executor::traits::ConvertLocation<u64> for AccountIdConverter {
fn convert_location(ml: &MultiLocation) -> Option<u64> {
match ml {
MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { id, .. }) } =>
fn convert_location(ml: &Location) -> Option<u64> {
match ml.unpack() {
(0, [Junction::AccountId32 { id, .. }]) =>
Some(<u64 as codec::Decode>::decode(&mut &*id.to_vec()).unwrap()),
_ => None,
}
@@ -58,14 +58,14 @@ impl xcm_executor::traits::ConvertLocation<u64> for AccountIdConverter {
}
parameter_types! {
pub UniversalLocation: InteriorMultiLocation = Junction::Parachain(101).into();
pub UniversalLocation: InteriorLocation = Junction::Parachain(101).into();
pub UnitWeightCost: Weight = Weight::from_parts(10, 10);
pub WeightPrice: (AssetId, u128, u128) = (Concrete(Here.into()), 1_000_000, 1024);
pub WeightPrice: (AssetId, u128, u128) = (AssetId(Here.into()), 1_000_000, 1024);
}
pub struct AllAssetLocationsPass;
impl ContainsPair<MultiAsset, MultiLocation> for AllAssetLocationsPass {
fn contains(_: &MultiAsset, _: &MultiLocation) -> bool {
impl ContainsPair<Asset, Location> for AllAssetLocationsPass {
fn contains(_: &Asset, _: &Location) -> bool {
true
}
}