# 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
+8 -10
View File
@@ -22,7 +22,7 @@ use primitives::Balance;
use runtime_common::identity_migrator::{OnReapIdentity, WeightInfo};
use sp_std::{marker::PhantomData, prelude::*};
use westend_runtime_constants::currency::*;
use xcm::{latest::prelude::*, VersionedMultiLocation, VersionedXcm};
use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm};
use xcm_executor::traits::TransactAsset;
/// A type containing the encoding of the People Chain pallets in its runtime. Used to construct any
@@ -95,9 +95,9 @@ where
let total_to_send = Self::calculate_remote_deposit(fields, subs);
// define asset / destination from relay perspective
let wnd = MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(total_to_send) };
let wnd = Asset { id: AssetId(Here.into_location()), fun: Fungible(total_to_send) };
// People Chain: ParaId 1004
let destination: MultiLocation = MultiLocation::new(0, Parachain(1004));
let destination: Location = Location::new(0, Parachain(1004));
// Do `check_out` accounting since the XCM Executor's `InitiateTeleport` doesn't support
// unpaid teleports.
@@ -138,11 +138,9 @@ where
);
// reanchor
let wnd_reanchored: MultiAssets = vec![MultiAsset {
id: Concrete(MultiLocation::new(1, Here)),
fun: Fungible(total_to_send),
}]
.into();
let wnd_reanchored: Assets =
vec![Asset { id: AssetId(Location::new(1, Here)), fun: Fungible(total_to_send) }]
.into();
let poke = PeopleRuntimePallets::<AccountId>::IdentityMigrator(PokeDeposit(who.clone()));
let remote_weight_limit = MigratorWeights::<Runtime>::poke_deposit().saturating_mul(2);
@@ -172,8 +170,8 @@ where
// send
let _ = <pallet_xcm::Pallet<Runtime>>::send(
RawOrigin::Root.into(),
Box::new(VersionedMultiLocation::V3(destination)),
Box::new(VersionedXcm::V3(program)),
Box::new(VersionedLocation::V4(destination)),
Box::new(VersionedXcm::V4(program)),
)?;
Ok(())
}
+39 -40
View File
@@ -59,7 +59,7 @@ use runtime_common::{
elections::OnChainAccuracy,
identity_migrator, impl_runtime_weights,
impls::{
LocatableAssetConverter, ToAuthor, VersionedLocatableAsset, VersionedMultiLocationConverter,
LocatableAssetConverter, ToAuthor, VersionedLocatableAsset, VersionedLocationConverter,
},
paras_registrar, paras_sudo_wrapper, prod_or_fast, slots, BalanceToU256, BlockHashCount,
BlockLength, CurrencyToVote, SlowAdjustingFeeUpdate, U256ToBalance,
@@ -98,8 +98,8 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*};
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::{
latest::{InteriorMultiLocation, Junction, Junction::PalletInstance},
VersionedMultiLocation,
latest::{InteriorLocation, Junction, Junction::PalletInstance},
VersionedLocation,
};
use xcm_builder::PayOverXcm;
@@ -714,7 +714,7 @@ parameter_types! {
pub const PayoutSpendPeriod: BlockNumber = 30 * DAYS;
// The asset's interior location for the paying account. This is the Treasury
// pallet instance (which sits at index 37).
pub TreasuryInteriorLocation: InteriorMultiLocation = PalletInstance(37).into();
pub TreasuryInteriorLocation: InteriorLocation = PalletInstance(37).into();
pub const TipCountdown: BlockNumber = 1 * DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
@@ -745,7 +745,7 @@ impl pallet_treasury::Config for Runtime {
type SpendFunds = ();
type SpendOrigin = TreasurySpender;
type AssetKind = VersionedLocatableAsset;
type Beneficiary = VersionedMultiLocation;
type Beneficiary = VersionedLocation;
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
type Paymaster = PayOverXcm<
TreasuryInteriorLocation,
@@ -755,7 +755,7 @@ impl pallet_treasury::Config for Runtime {
Self::Beneficiary,
Self::AssetKind,
LocatableAssetConverter,
VersionedMultiLocationConverter,
VersionedLocationConverter,
>;
type BalanceConverter = AssetRate;
type PayoutPeriod = PayoutSpendPeriod;
@@ -2286,31 +2286,31 @@ sp_api::impl_runtime_apis! {
impl pallet_offences_benchmarking::Config for Runtime {}
impl pallet_election_provider_support_benchmarking::Config for Runtime {}
impl pallet_xcm::benchmarking::Config for Runtime {
fn reachable_dest() -> Option<MultiLocation> {
fn reachable_dest() -> Option<Location> {
Some(crate::xcm_config::AssetHub::get())
}
fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
// Relay/native token can be teleported to/from AH.
Some((
MultiAsset { fun: Fungible(EXISTENTIAL_DEPOSIT), id: Concrete(Here.into()) },
Asset { fun: Fungible(EXISTENTIAL_DEPOSIT), id: AssetId(Here.into()) },
crate::xcm_config::AssetHub::get(),
))
}
fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
// Relay can reserve transfer native token to some random parachain.
Some((
MultiAsset {
Asset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
id: Concrete(Here.into())
id: AssetId(Here.into())
},
crate::Junction::Parachain(43211234).into(),
))
}
fn set_up_complex_asset_transfer(
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
) -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)> {
// Relay supports only native token, either reserve transfer it to non-system parachains,
// or teleport it to system parachain. Use the teleport case for benchmarking as it's
// slightly heavier.
@@ -2329,13 +2329,13 @@ sp_api::impl_runtime_apis! {
impl runtime_parachains::disputes::slashing::benchmarking::Config for Runtime {}
use xcm::latest::{
AssetId::*, Fungibility::*, InteriorMultiLocation, Junction, Junctions::*,
MultiAsset, MultiAssets, MultiLocation, NetworkId, Response,
AssetId, Fungibility::*, InteriorLocation, Junction, Junctions::*,
Asset, Assets, Location, NetworkId, Response,
};
use xcm_config::{AssetHub, TokenLocation};
parameter_types! {
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
pub ExistentialDepositAsset: Option<Asset> = Some((
TokenLocation::get(),
ExistentialDeposit::get()
).into());
@@ -2347,29 +2347,29 @@ sp_api::impl_runtime_apis! {
type AccountIdConverter = xcm_config::LocationConverter;
type DeliveryHelper = runtime_common::xcm_sender::ToParachainDeliveryHelper<
xcm_config::XcmConfig,
ExistentialDepositMultiAsset,
ExistentialDepositAsset,
xcm_config::PriceForChildParachainDelivery,
ToParachain,
(),
>;
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
fn valid_destination() -> Result<Location, BenchmarkError> {
Ok(AssetHub::get())
}
fn worst_case_holding(_depositable_count: u32) -> MultiAssets {
fn worst_case_holding(_depositable_count: u32) -> Assets {
// Westend only knows about WND.
vec![MultiAsset{
id: Concrete(TokenLocation::get()),
vec![Asset{
id: AssetId(TokenLocation::get()),
fun: Fungible(1_000_000 * UNITS),
}].into()
}
}
parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
pub TrustedTeleporter: Option<(Location, Asset)> = Some((
AssetHub::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) },
Asset { fun: Fungible(1 * UNITS), id: AssetId(TokenLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None;
pub const TrustedReserve: Option<(Location, Asset)> = None;
}
impl pallet_xcm_benchmarks::fungible::Config for Runtime {
@@ -2379,9 +2379,9 @@ sp_api::impl_runtime_apis! {
type TrustedTeleporter = TrustedTeleporter;
type TrustedReserve = TrustedReserve;
fn get_multi_asset() -> MultiAsset {
MultiAsset {
id: Concrete(TokenLocation::get()),
fn get_asset() -> Asset {
Asset {
id: AssetId(TokenLocation::get()),
fun: Fungible(1 * UNITS),
}
}
@@ -2395,43 +2395,43 @@ sp_api::impl_runtime_apis! {
(0u64, Response::Version(Default::default()))
}
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> {
// Westend doesn't support asset exchanges
Err(BenchmarkError::Skip)
}
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> {
fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
// The XCM executor of Westend doesn't have a configured `UniversalAliases`
Err(BenchmarkError::Skip)
}
fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> {
fn transact_origin_and_runtime_call() -> Result<(Location, RuntimeCall), BenchmarkError> {
Ok((AssetHub::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
}
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
fn subscribe_origin() -> Result<Location, BenchmarkError> {
Ok(AssetHub::get())
}
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
let origin = AssetHub::get();
let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into();
let ticket = MultiLocation { parents: 0, interior: Here };
let assets: Assets = (AssetId(TokenLocation::get()), 1_000 * UNITS).into();
let ticket = Location { parents: 0, interior: Here };
Ok((origin, ticket, assets))
}
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
// Westend doesn't support asset locking
Err(BenchmarkError::Skip)
}
fn export_message_origin_and_destination(
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
// Westend doesn't support exporting messages
Err(BenchmarkError::Skip)
}
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
// The XCM executor of Westend doesn't have a configured `Aliasers`
Err(BenchmarkError::Skip)
}
@@ -2503,12 +2503,11 @@ mod remote_tests {
mod clean_state_migration {
use super::Runtime;
#[cfg(feature = "try-runtime")]
use super::Vec;
use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade};
use pallet_state_trie_migration::MigrationLimits;
#[cfg(not(feature = "std"))]
use sp_std::prelude::*;
#[storage_alias]
type AutoLimits = StorageValue<StateTrieMigration, Option<MigrationLimits>, ValueQuery>;
+48 -60
View File
@@ -36,25 +36,25 @@ pub enum AssetTypes {
Unknown,
}
impl From<&MultiAsset> for AssetTypes {
fn from(asset: &MultiAsset) -> Self {
impl From<&Asset> for AssetTypes {
fn from(asset: &Asset) -> Self {
match asset {
MultiAsset { id: Concrete(MultiLocation { parents: 0, interior: Here }), .. } =>
Asset { id: AssetId(Location { parents: 0, interior: Here }), .. } =>
AssetTypes::Balances,
_ => AssetTypes::Unknown,
}
}
}
trait WeighMultiAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight;
trait WeighAssets {
fn weigh_assets(&self, balances_weight: Weight) -> Weight;
}
// Westend only knows about one asset, the balances pallet.
const MAX_ASSETS: u64 = 1;
impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
impl WeighAssets for AssetFilter {
fn weigh_assets(&self, balances_weight: Weight) -> Weight {
match self {
Self::Definite(assets) => assets
.inner()
@@ -75,11 +75,11 @@ impl WeighMultiAssets for MultiAssetFilter {
}
}
impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
impl WeighAssets for Assets {
fn weigh_assets(&self, balances_weight: Weight) -> Weight {
self.inner()
.into_iter()
.map(|m| <AssetTypes as From<&MultiAsset>>::from(m))
.map(|m| <AssetTypes as From<&Asset>>::from(m))
.map(|t| match t {
AssetTypes::Balances => balances_weight,
AssetTypes::Unknown => Weight::MAX,
@@ -90,32 +90,28 @@ impl WeighMultiAssets for MultiAssets {
pub struct WestendXcmWeight<RuntimeCall>(core::marker::PhantomData<RuntimeCall>);
impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
fn withdraw_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
fn withdraw_asset(assets: &Assets) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
}
fn reserve_asset_deposited(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::reserve_asset_deposited())
fn reserve_asset_deposited(assets: &Assets) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::reserve_asset_deposited())
}
fn receive_teleported_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
fn receive_teleported_asset(assets: &Assets) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
}
fn query_response(
_query_id: &u64,
_response: &Response,
_max_weight: &Weight,
_querier: &Option<MultiLocation>,
_querier: &Option<Location>,
) -> Weight {
XcmGeneric::<Runtime>::query_response()
}
fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
}
fn transfer_reserve_asset(
assets: &MultiAssets,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(
_origin_kind: &OriginKind,
@@ -143,45 +139,37 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
fn clear_origin() -> Weight {
XcmGeneric::<Runtime>::clear_origin()
}
fn descend_origin(_who: &InteriorMultiLocation) -> Weight {
fn descend_origin(_who: &InteriorLocation) -> Weight {
XcmGeneric::<Runtime>::descend_origin()
}
fn report_error(_query_repsonse_info: &QueryResponseInfo) -> Weight {
XcmGeneric::<Runtime>::report_error()
}
fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
}
fn deposit_reserve_asset(
assets: &MultiAssetFilter,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets, _maximal: &bool) -> Weight {
fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
// Westend does not currently support exchange asset operations
Weight::MAX
}
fn initiate_reserve_withdraw(
assets: &MultiAssetFilter,
_reserve: &MultiLocation,
assets: &AssetFilter,
_reserve: &Location,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_reserve_withdraw())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(
assets: &MultiAssetFilter,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
}
fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight {
fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> Weight {
XcmGeneric::<Runtime>::buy_execution()
}
fn refund_surplus() -> Weight {
@@ -196,7 +184,7 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
fn clear_error() -> Weight {
XcmGeneric::<Runtime>::clear_error()
}
fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight {
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
XcmGeneric::<Runtime>::claim_asset()
}
fn trap(_code: &u64) -> Weight {
@@ -208,13 +196,13 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
fn unsubscribe_version() -> Weight {
XcmGeneric::<Runtime>::unsubscribe_version()
}
fn burn_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
fn burn_asset(assets: &Assets) -> Weight {
assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
}
fn expect_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
fn expect_asset(assets: &Assets) -> Weight {
assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
}
fn expect_origin(_origin: &Option<MultiLocation>) -> Weight {
fn expect_origin(_origin: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::expect_origin()
}
fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
@@ -249,19 +237,19 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
// Westend relay should not support export message operations
Weight::MAX
}
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
fn lock_asset(_: &Asset, _: &Location) -> Weight {
// Westend does not currently support asset locking operations
Weight::MAX
}
fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
fn unlock_asset(_: &Asset, _: &Location) -> Weight {
// Westend does not currently support asset locking operations
Weight::MAX
}
fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight {
fn note_unlockable(_: &Asset, _: &Location) -> Weight {
// Westend does not currently support asset locking operations
Weight::MAX
}
fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight {
fn request_unlock(_: &Asset, _: &Location) -> Weight {
// Westend does not currently support asset locking operations
Weight::MAX
}
@@ -274,19 +262,19 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
fn clear_topic() -> Weight {
XcmGeneric::<Runtime>::clear_topic()
}
fn alias_origin(_: &MultiLocation) -> Weight {
fn alias_origin(_: &Location) -> Weight {
// XCM Executor does not currently support alias origin operations
Weight::MAX
}
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> Weight {
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::unpaid_execution()
}
}
#[test]
fn all_counted_has_a_sane_weight_upper_limit() {
let assets = MultiAssetFilter::Wild(AllCounted(4294967295));
let assets = AssetFilter::Wild(AllCounted(4294967295));
let weight = Weight::from_parts(1000, 1000);
assert_eq!(assets.weigh_multi_assets(weight), weight * MAX_ASSETS);
assert_eq!(assets.weigh_assets(weight), weight * MAX_ASSETS);
}
+49 -38
View File
@@ -23,8 +23,8 @@ use super::{
};
use crate::governance::pallet_custom_origins::Treasurer;
use frame_support::{
match_types, parameter_types,
traits::{Equals, Everything, Nothing},
parameter_types,
traits::{Contains, Equals, Everything, Nothing},
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
@@ -53,15 +53,15 @@ use xcm_builder::{
use xcm_executor::XcmExecutor;
parameter_types! {
pub const RootLocation: MultiLocation = MultiLocation::here();
pub const TokenLocation: MultiLocation = Here.into_location();
pub const TokenLocation: Location = Here.into_location();
pub const RootLocation: Location = Location::here();
pub const ThisNetwork: NetworkId = Westend;
pub const UniversalLocation: InteriorMultiLocation = X1(GlobalConsensus(ThisNetwork::get()));
pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetwork::get())].into();
pub CheckAccount: AccountId = XcmPallet::check_account();
pub LocalCheckAccount: (AccountId, MintLocation) = (CheckAccount::get(), MintLocation::Local);
pub TreasuryAccount: AccountId = Treasury::account_id();
/// The asset ID for the asset that we use to pay for message delivery fees.
pub FeeAssetId: AssetId = Concrete(TokenLocation::get());
pub FeeAssetId: AssetId = AssetId(TokenLocation::get());
/// The base fee for the message delivery fees.
pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
}
@@ -81,7 +81,7 @@ pub type LocalAssetTransactor = XcmCurrencyAdapter<
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<TokenLocation>,
// We can convert the MultiLocations with our converter above:
// We can convert the Locations with our converter above:
LocationConverter,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
@@ -114,17 +114,17 @@ pub type XcmRouter = WithUniqueTopic<
>;
parameter_types! {
pub const AssetHub: MultiLocation = Parachain(ASSET_HUB_ID).into_location();
pub const Collectives: MultiLocation = Parachain(COLLECTIVES_ID).into_location();
pub const BridgeHub: MultiLocation = Parachain(BRIDGE_HUB_ID).into_location();
pub const People: MultiLocation = Parachain(PEOPLE_ID).into_location();
pub const Wnd: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
pub const WndForAssetHub: (MultiAssetFilter, MultiLocation) = (Wnd::get(), AssetHub::get());
pub const WndForCollectives: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Collectives::get());
pub const WndForBridgeHub: (MultiAssetFilter, MultiLocation) = (Wnd::get(), BridgeHub::get());
pub const WndForPeople: (MultiAssetFilter, MultiLocation) = (Wnd::get(), People::get());
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
pub AssetHub: Location = Parachain(ASSET_HUB_ID).into_location();
pub Collectives: Location = Parachain(COLLECTIVES_ID).into_location();
pub BridgeHub: Location = Parachain(BRIDGE_HUB_ID).into_location();
pub People: Location = Parachain(PEOPLE_ID).into_location();
pub Wnd: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) });
pub WndForAssetHub: (AssetFilter, Location) = (Wnd::get(), AssetHub::get());
pub WndForCollectives: (AssetFilter, Location) = (Wnd::get(), Collectives::get());
pub WndForBridgeHub: (AssetFilter, Location) = (Wnd::get(), BridgeHub::get());
pub WndForPeople: (AssetFilter, Location) = (Wnd::get(), People::get());
pub MaxInstructions: u32 = 100;
pub MaxAssetsIntoHolding: u32 = 64;
}
pub type TrustedTeleporters = (
@@ -134,17 +134,29 @@ pub type TrustedTeleporters = (
xcm_builder::Case<WndForPeople>,
);
match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
};
pub type CollectivesOrFellows: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(COLLECTIVES_ID)) } |
MultiLocation { parents: 0, interior: X2(Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }) }
};
pub type LocalPlurality: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Plurality { .. }) }
};
pub struct OnlyParachains;
impl Contains<Location> for OnlyParachains {
fn contains(location: &Location) -> bool {
matches!(location.unpack(), (0, [Parachain(_)]))
}
}
pub struct CollectivesOrFellows;
impl Contains<Location> for CollectivesOrFellows {
fn contains(location: &Location) -> bool {
matches!(
location.unpack(),
(0, [Parachain(COLLECTIVES_ID)]) |
(0, [Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }])
)
}
}
pub struct LocalPlurality;
impl Contains<Location> for LocalPlurality {
fn contains(loc: &Location) -> bool {
matches!(loc.unpack(), (0, [Plurality { .. }]))
}
}
/// The barriers one of which must be passed for an XCM message to be executed.
@@ -218,11 +230,10 @@ parameter_types! {
pub const TreasurerBodyId: BodyId = BodyId::Index(TREASURER_INDEX);
}
/// Type to convert the `GeneralAdmin` origin to a Plurality `MultiLocation` value.
/// Type to convert the `GeneralAdmin` origin to a Plurality `Location` value.
pub type GeneralAdminToPlurality =
OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior
/// location of this chain.
pub type LocalOriginToLocation = (
GeneralAdminToPlurality,
@@ -230,25 +241,25 @@ pub type LocalOriginToLocation = (
SignedToAccountId32<RuntimeOrigin, AccountId, ThisNetwork>,
);
/// Type to convert the `StakingAdmin` origin to a Plurality `MultiLocation` value.
/// Type to convert the `StakingAdmin` origin to a Plurality `Location` value.
pub type StakingAdminToPlurality =
OriginToPluralityVoice<RuntimeOrigin, StakingAdmin, StakingAdminBodyId>;
/// Type to convert the `FellowshipAdmin` origin to a Plurality `MultiLocation` value.
/// Type to convert the `FellowshipAdmin` origin to a Plurality `Location` value.
pub type FellowshipAdminToPlurality =
OriginToPluralityVoice<RuntimeOrigin, FellowshipAdmin, FellowshipAdminBodyId>;
/// Type to convert the `Treasurer` origin to a Plurality `MultiLocation` value.
/// Type to convert the `Treasurer` origin to a Plurality `Location` value.
pub type TreasurerToPlurality = OriginToPluralityVoice<RuntimeOrigin, Treasurer, TreasurerBodyId>;
/// Type to convert a pallet `Origin` type value into a `MultiLocation` value which represents an
/// Type to convert a pallet `Origin` type value into a `Location` value which represents an
/// interior location of this chain for a destination chain.
pub type LocalPalletOriginToLocation = (
// GeneralAdmin origin to be used in XCM as a corresponding Plurality `MultiLocation` value.
// GeneralAdmin origin to be used in XCM as a corresponding Plurality `Location` value.
GeneralAdminToPlurality,
// StakingAdmin origin to be used in XCM as a corresponding Plurality `MultiLocation` value.
// StakingAdmin origin to be used in XCM as a corresponding Plurality `Location` value.
StakingAdminToPlurality,
// FellowshipAdmin origin to be used in XCM as a corresponding Plurality `MultiLocation` value.
// FellowshipAdmin origin to be used in XCM as a corresponding Plurality `Location` value.
FellowshipAdminToPlurality,
// `Treasurer` origin to be used in XCM as a corresponding Plurality `MultiLocation` value.
TreasurerToPlurality,