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

Remove InvertLocation trait #5092

Merged
merged 3 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove InvertLocation trait
  • Loading branch information
gavofyork committed Mar 12, 2022
commit 87c29c7b1e6f4541c5d919f2215f29543d9fbbf4
6 changes: 3 additions & 3 deletions bridges/bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use polkadot_parachain::primitives::Sibling;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, NativeAsset,
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
Expand Down Expand Up @@ -372,7 +372,7 @@ impl Config for XcmConfig {
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAsset;
type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of UNIT
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
type Trader = UsingComponents<IdentityFee<Balance>, RelayLocation, AccountId, Balances, ()>;
Expand Down Expand Up @@ -406,7 +406,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Origin = Origin;
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
Expand Down
6 changes: 3 additions & 3 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use xcm_builder::{
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, BackingToPlurality,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents,
};
use xcm_executor::XcmExecutor;
Expand Down Expand Up @@ -142,7 +142,7 @@ impl xcm_executor::Config for XcmConfig {
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
type IsTeleporter = TrustedTeleporters;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
// The weight trader piggybacks on the existing transaction-fee conversion logic.
Expand Down Expand Up @@ -192,7 +192,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Origin = Origin;
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
Expand Down
6 changes: 3 additions & 3 deletions runtime/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, BackingToPlurality, ChildParachainAsNative,
ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds,
IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32,
IsConcrete, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
};
use xcm_executor::XcmExecutor;
Expand Down Expand Up @@ -134,7 +134,7 @@ impl xcm_executor::Config for XcmConfig {
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
type IsTeleporter = TrustedTeleporters;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
// The weight trader piggybacks on the existing transaction-fee conversion logic.
Expand Down Expand Up @@ -184,7 +184,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Nothing;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Origin = Origin;
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
Expand Down
6 changes: 3 additions & 3 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, BackingToPlurality,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsConcrete,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents,
};
use xcm_executor::XcmExecutor;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl xcm_executor::Config for XcmConfig {
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
type IsTeleporter = TrustedTeleporters;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type Trader =
Expand Down Expand Up @@ -172,7 +172,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Origin = Origin;
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
Expand Down
3 changes: 2 additions & 1 deletion runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ parameter_types! {
pub const BaseXcmWeight: frame_support::weights::Weight = 1_000;
pub const AnyNetwork: Option<xcm::latest::NetworkId> = None;
pub const MaxInstructions: u32 = 100;
pub const UniversalLocation: xcm::latest::InteriorMultiLocation = xcm::latest::Junctions::Here;
}

pub type LocalOriginToLocation = xcm_builder::SignedToAccountId32<Origin, AccountId, AnyNetwork>;
Expand All @@ -530,7 +531,7 @@ impl pallet_xcm::Config for Runtime {
// is `XcmExecutor`, which will be used in unit tests located in xcm-executor.
type Event = Event;
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type LocationInverter = xcm_config::InvertNothing;
type UniversalLocation = UniversalLocation;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type Weigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type XcmRouter = xcm_config::DoNothingRouter;
Expand Down
16 changes: 3 additions & 13 deletions runtime/test-runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ use frame_support::{
use xcm::latest::prelude::*;
use xcm_builder::{AllowUnpaidExecutionFrom, FixedWeightBounds, SignedToAccountId32};
use xcm_executor::{
traits::{TransactAsset, UniversalLocation, WeightTrader},
traits::{TransactAsset, WeightTrader},
Assets,
};

parameter_types! {
pub const OurNetwork: NetworkId = NetworkId::Polkadot;
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 16;
pub const UniversalLocation: xcm::latest::InteriorMultiLocation = xcm::latest::Junctions::Here;
}

/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location
Expand Down Expand Up @@ -79,17 +80,6 @@ impl WeightTrader for DummyWeightTrader {
}
}

pub struct InvertNothing;
impl UniversalLocation for InvertNothing {
fn invert_location(_: &MultiLocation) -> sp_std::result::Result<MultiLocation, ()> {
Ok(Here.into())
}

fn universal_location() -> InteriorMultiLocation {
Here
}
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type Call = super::Call;
Expand All @@ -98,7 +88,7 @@ impl xcm_executor::Config for XcmConfig {
type OriginConverter = pallet_xcm::XcmPassthrough<super::Origin>;
type IsReserve = ();
type IsTeleporter = ();
type LocationInverter = InvertNothing;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<super::BaseXcmWeight, super::Call, MaxInstructions>;
type Trader = DummyWeightTrader;
Expand Down
6 changes: 3 additions & 3 deletions runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ChildParachainAsNative,
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, LocationInverter,
CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds,
};
Expand Down Expand Up @@ -107,7 +107,7 @@ impl xcm_executor::Config for XcmConfig {
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
type IsTeleporter = TrustedTeleporters;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = WeightInfoBounds<weights::xcm::WestendXcmWeight<Call>, Call, MaxInstructions>;
type Trader =
Expand Down Expand Up @@ -144,7 +144,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = WeightInfoBounds<weights::xcm::WestendXcmWeight<Call>, Call, MaxInstructions>;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Origin = Origin;
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
Expand Down
2 changes: 1 addition & 1 deletion xcm/pallet-xcm-benchmarks/src/fungible/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl xcm_executor::Config for XcmConfig {
type OriginConverter = ();
type IsReserve = TrustedReserves;
type IsTeleporter = TrustedTeleporters;
type LocationInverter = xcm_builder::LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = AllowUnpaidExecutionFrom<Everything>;
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
type Trader = xcm_builder::FixedRateOfFungible<WeightPrice, ()>;
Expand Down
2 changes: 1 addition & 1 deletion xcm/pallet-xcm-benchmarks/src/generic/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl xcm_executor::Config for XcmConfig {
type OriginConverter = AlwaysSignedByDefault<Origin>;
type IsReserve = AllAssetLocationsPass;
type IsTeleporter = ();
type LocationInverter = xcm_builder::LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = AllowUnpaidExecutionFrom<Everything>;
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
type Trader = xcm_builder::FixedRateOfFungible<WeightPrice, ()>;
Expand Down
20 changes: 10 additions & 10 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub use pallet::*;
use sp_runtime::traits::{AccountIdConversion, BlakeTwo256, BlockNumberProvider, Hash};
use xcm_executor::{
traits::{
ClaimAssets, DropAssets, MatchesFungible, OnResponse, UniversalLocation,
ClaimAssets, DropAssets, MatchesFungible, OnResponse,
VersionChangeNotifier, WeightBounds,
},
Assets,
Expand All @@ -69,7 +69,7 @@ pub mod pallet {
};
use frame_system::Config as SysConfig;
use sp_core::H256;
use xcm_executor::traits::{MatchesFungible, UniversalLocation, WeightBounds};
use xcm_executor::traits::{MatchesFungible, WeightBounds};

parameter_types! {
/// An implementation of `Get<u32>` which just returns the latest XCM version which we can
Expand Down Expand Up @@ -125,8 +125,8 @@ pub mod pallet {
/// Means of measuring the weight consumed by an XCM message locally.
type Weigher: WeightBounds<<Self as SysConfig>::Call>;

/// Means of inverting a location.
type LocationInverter: UniversalLocation;
/// This chain's Universal Location.
type UniversalLocation: Get<InteriorMultiLocation>;

/// The outer `Origin` type.
type Origin: From<Origin> + From<<Self as SysConfig>::Origin>;
Expand Down Expand Up @@ -983,12 +983,12 @@ impl<T: Config> Pallet<T> {
let value = (origin_location, assets.into_inner());
ensure!(T::XcmReserveTransferFilter::contains(&value), Error::<T>::Filtered);
let (origin_location, assets) = value;
let ancestry = T::LocationInverter::universal_location().into();
let context = T::UniversalLocation::get();
let fees = assets
.get(fee_asset_item as usize)
.ok_or(Error::<T>::Empty)?
.clone()
.reanchored(&dest, &ancestry)
.reanchored(&dest, context)
.map_err(|_| Error::<T>::CannotReanchor)?;
let max_assets = assets.len() as u32;
let assets: MultiAssets = assets.into();
Expand Down Expand Up @@ -1041,12 +1041,12 @@ impl<T: Config> Pallet<T> {
let value = (origin_location, assets.into_inner());
ensure!(T::XcmTeleportFilter::contains(&value), Error::<T>::Filtered);
let (origin_location, assets) = value;
let ancestry = T::LocationInverter::universal_location().into();
let context = T::UniversalLocation::get();
let fees = assets
.get(fee_asset_item as usize)
.ok_or(Error::<T>::Empty)?
.clone()
.reanchored(&dest, &ancestry)
.reanchored(&dest, context)
.map_err(|_| Error::<T>::CannotReanchor)?;
let max_assets = assets.len() as u32;
let assets: MultiAssets = assets.into();
Expand Down Expand Up @@ -1333,7 +1333,7 @@ impl<T: Config> Pallet<T> {
timeout: T::BlockNumber,
) -> Result<QueryId, XcmError> {
let responder = responder.into();
let destination = T::LocationInverter::invert_location(&responder)
let destination = T::UniversalLocation::get().invert_target(&responder)
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
let query_id = Self::new_query(responder, timeout, Here);
let response_info = QueryResponseInfo { destination, query_id, max_weight: 0 };
Expand Down Expand Up @@ -1371,7 +1371,7 @@ impl<T: Config> Pallet<T> {
timeout: T::BlockNumber,
) -> Result<(), XcmError> {
let responder = responder.into();
let destination = T::LocationInverter::invert_location(&responder)
let destination = T::UniversalLocation::get().invert_target(&responder)
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
let notify: <T as Config>::Call = notify.into();
let max_weight = notify.get_dispatch_info().weight;
Expand Down
6 changes: 3 additions & 3 deletions xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, Case, ChildParachainAsNative, ChildParachainConvertsVia,
ChildSystemParachainAsSuperuser, CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible,
FixedWeightBounds, IsConcrete, LocationInverter, SignedAccountId32AsNative,
FixedWeightBounds, IsConcrete, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
};
use xcm_executor::XcmExecutor;
Expand Down Expand Up @@ -285,7 +285,7 @@ impl xcm_executor::Config for XcmConfig {
type OriginConverter = LocalOriginConverter;
type IsReserve = ();
type IsTeleporter = Case<TrustedAssets>;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type Trader = FixedRateOfFungible<CurrencyPerSecond, ()>;
Expand Down Expand Up @@ -318,7 +318,7 @@ impl pallet_xcm::Config for Test {
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type LocationInverter = LocationInverter<UniversalLocation>;
type UniversalLocation = UniversalLocation;
type Origin = Origin;
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
Expand Down
13 changes: 13 additions & 0 deletions xcm/src/v3/junctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ impl Junctions {
self.for_each_mut(Junction::remove_network_id);
}

/// Treating `self` as the universal context, return the location of the local consensus system
/// from the point of view of the given `location`.
pub fn invert_target(mut self, location: &MultiLocation) -> Result<MultiLocation, ()> {
let mut junctions = Self::Here;
for _ in 0..location.parent_count() {
junctions = junctions
.pushed_with(self.take_first().unwrap_or(Junction::OnlyChild))
.map_err(|_| ())?;
}
let parents = location.interior().len() as u8;
Ok(MultiLocation::new(parents, junctions))
}

/// Execute a function `f` on every junction. We use this since we cannot implement a mutable
/// `Iterator` without unsafe code.
pub fn for_each_mut(&mut self, mut x: impl FnMut(&mut Junction)) {
Expand Down
Loading