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
Prev Previous commit
Formatting
  • Loading branch information
gavofyork committed Mar 12, 2022
commit 39b55c6859a0a5ea595281833b316afc76bc8eb2
4 changes: 2 additions & 2 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use xcm_builder::{
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, BackingToPlurality,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents,
};
use xcm_executor::XcmExecutor;

Expand Down
4 changes: 2 additions & 2 deletions runtime/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, BackingToPlurality, ChildParachainAsNative,
ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds,
IsConcrete, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
IsConcrete, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents,
};
use xcm_executor::XcmExecutor;

Expand Down
9 changes: 5 additions & 4 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ pub use pallet::*;
use sp_runtime::traits::{AccountIdConversion, BlakeTwo256, BlockNumberProvider, Hash};
use xcm_executor::{
traits::{
ClaimAssets, DropAssets, MatchesFungible, OnResponse,
VersionChangeNotifier, WeightBounds,
ClaimAssets, DropAssets, MatchesFungible, OnResponse, VersionChangeNotifier, WeightBounds,
},
Assets,
};
Expand Down Expand Up @@ -1333,7 +1332,8 @@ impl<T: Config> Pallet<T> {
timeout: T::BlockNumber,
) -> Result<QueryId, XcmError> {
let responder = responder.into();
let destination = T::UniversalLocation::get().invert_target(&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,8 @@ impl<T: Config> Pallet<T> {
timeout: T::BlockNumber,
) -> Result<(), XcmError> {
let responder = responder.into();
let destination = T::UniversalLocation::get().invert_target(&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
4 changes: 2 additions & 2 deletions xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, Case, ChildParachainAsNative, ChildParachainConvertsVia,
ChildSystemParachainAsSuperuser, CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible,
FixedWeightBounds, IsConcrete, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
FixedWeightBounds, IsConcrete, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit,
};
use xcm_executor::XcmExecutor;

Expand Down
16 changes: 16 additions & 0 deletions xcm/src/v3/junctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,22 @@ xcm_procedural::impl_conversion_functions_for_junctions_v3!();
mod tests {
use super::{super::prelude::*, *};

#[test]
fn inverting_works() {
let context: InteriorMultiLocation = (Parachain(1000), PalletInstance(42)).into();
let target = (Parent, PalletInstance(69)).into();
let expected = (Parent, PalletInstance(42)).into();
let inverted = context.invert_target(&target).unwrap();
assert_eq!(inverted, expected);

let context: InteriorMultiLocation =
(Parachain(1000), PalletInstance(42), GeneralIndex(1)).into();
let target = (Parent, Parent, PalletInstance(69), GeneralIndex(2)).into();
let expected = (Parent, Parent, PalletInstance(42), GeneralIndex(1)).into();
let inverted = context.invert_target(&target).unwrap();
assert_eq!(inverted, expected);
}

#[test]
fn relative_to_works() {
use Junctions::*;
Expand Down
24 changes: 20 additions & 4 deletions xcm/src/v3/multiasset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ impl AssetId {

/// Mutate the asset to represent the same value from the perspective of a new `target`
/// location. The local chain's location is provided in `context`.
pub fn reanchor(&mut self, target: &MultiLocation, context: InteriorMultiLocation) -> Result<(), ()> {
pub fn reanchor(
&mut self,
target: &MultiLocation,
context: InteriorMultiLocation,
) -> Result<(), ()> {
if let AssetId::Concrete(ref mut l) = self {
l.reanchor(target, context)?;
}
Expand Down Expand Up @@ -624,7 +628,11 @@ impl MultiAssets {

/// Mutate the location of the asset identifier if concrete, giving it the same location
/// relative to a `target` context. The local context is provided as `context`.
pub fn reanchor(&mut self, target: &MultiLocation, context: InteriorMultiLocation) -> Result<(), ()> {
pub fn reanchor(
&mut self,
target: &MultiLocation,
context: InteriorMultiLocation,
) -> Result<(), ()> {
self.0.iter_mut().try_for_each(|i| i.reanchor(target, context.clone()))
}

Expand Down Expand Up @@ -704,7 +712,11 @@ impl WildMultiAsset {

/// Mutate the asset to represent the same value from the perspective of a new `target`
/// location. The local chain's location is provided in `context`.
pub fn reanchor(&mut self, target: &MultiLocation, context: InteriorMultiLocation) -> Result<(), ()> {
pub fn reanchor(
&mut self,
target: &MultiLocation,
context: InteriorMultiLocation,
) -> Result<(), ()> {
use WildMultiAsset::*;
match self {
AllOf { ref mut id, .. } | AllOfCounted { ref mut id, .. } =>
Expand Down Expand Up @@ -789,7 +801,11 @@ impl MultiAssetFilter {

/// Mutate the location of the asset identifier if concrete, giving it the same location
/// relative to a `target` context. The local context is provided as `context`.
pub fn reanchor(&mut self, target: &MultiLocation, context: InteriorMultiLocation) -> Result<(), ()> {
pub fn reanchor(
&mut self,
target: &MultiLocation,
context: InteriorMultiLocation,
) -> Result<(), ()> {
match self {
MultiAssetFilter::Definite(ref mut assets) => assets.reanchor(target, context),
MultiAssetFilter::Wild(ref mut wild) => wild.reanchor(target, context),
Expand Down
21 changes: 5 additions & 16 deletions xcm/src/v3/multilocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ impl MultiLocation {
/// The context of `self` is provided as `context`.
///
/// Does not modify `self` in case of overflow.
pub fn reanchor(&mut self, target: &MultiLocation, context: InteriorMultiLocation) -> Result<(), ()> {
pub fn reanchor(
&mut self,
target: &MultiLocation,
context: InteriorMultiLocation,
) -> Result<(), ()> {
// TODO: https://github.com/paritytech/polkadot/issues/4489 Optimize this.

// 1. Use our `context` to figure out how the `target` would address us.
Expand Down Expand Up @@ -506,21 +510,6 @@ mod tests {
assert_eq!(x, MultiLocation { parents: 0, interior: OnlyChild.into() });
}

#[test]
fn inverted_works() {
let context = (Parachain(1000), PalletInstance(42)).into();
let target: MultiLocation = (Parent, PalletInstance(69)).into();
let expected = (Parent, PalletInstance(42)).into();
let inverted = context.invert_target(target).unwrap();
assert_eq!(inverted, expected);

let context = (Parachain(1000), PalletInstance(42), GeneralIndex(1)).into();
let target: MultiLocation = (Parent, Parent, PalletInstance(69), GeneralIndex(2)).into();
let expected = (Parent, Parent, PalletInstance(42), GeneralIndex(1)).into();
let inverted = context.invert_target(target).unwrap();
assert_eq!(inverted, expected);
}

#[test]
fn simplify_basic_works() {
let mut location: MultiLocation =
Expand Down
4 changes: 3 additions & 1 deletion xcm/xcm-builder/src/universal_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ fn ensure_is_remote(
/// that the message sending cannot be abused in any way.
///
/// This is only useful when the local chain has bridging capabilities.
pub struct LocalUnpaidExporter<Exporter, UniversalLocation>(PhantomData<(Exporter, UniversalLocation)>);
pub struct LocalUnpaidExporter<Exporter, UniversalLocation>(
PhantomData<(Exporter, UniversalLocation)>,
);
impl<Exporter: ExportXcm, UniversalLocation: Get<InteriorMultiLocation>> SendXcm
for LocalUnpaidExporter<Exporter, UniversalLocation>
{
Expand Down
4 changes: 2 additions & 2 deletions xcm/xcm-builder/tests/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds,
IsChildSystemParachain, IsConcrete, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
IsChildSystemParachain, IsConcrete, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit,
};

pub type AccountId = AccountId32;
Expand Down
2 changes: 1 addition & 1 deletion xcm/xcm-executor/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sp_std::{
use xcm::latest::{
AssetId, AssetInstance,
Fungibility::{Fungible, NonFungible},
MultiAsset, MultiAssetFilter, MultiAssets, MultiLocation, InteriorMultiLocation,
InteriorMultiLocation, MultiAsset, MultiAssetFilter, MultiAssets, MultiLocation,
WildFungibility::{Fungible as WildFungible, NonFungible as WildNonFungible},
WildMultiAsset::{All, AllCounted, AllOf, AllOfCounted},
};
Expand Down
3 changes: 1 addition & 2 deletions xcm/xcm-executor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

use crate::traits::{
AssetExchange, AssetLock, ClaimAssets, ConvertOrigin, DropAssets, ExportXcm, FeeManager,
OnResponse, ShouldExecute, TransactAsset, VersionChangeNotifier,
WeightBounds, WeightTrader,
OnResponse, ShouldExecute, TransactAsset, VersionChangeNotifier, WeightBounds, WeightTrader,
};
use frame_support::{
dispatch::{Dispatchable, Parameter},
Expand Down
2 changes: 1 addition & 1 deletion xcm/xcm-executor/src/traits/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ impl<O> ConvertOrigin<O> for Tuple {
);
Err(origin)
}
}
}
8 changes: 3 additions & 5 deletions xcm/xcm-executor/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
//! Various traits used in configuring the executor.

mod conversion;
pub use conversion::{
Convert, ConvertOrigin, Decoded, Encoded, Identity, JustTry,
};
pub use conversion::{Convert, ConvertOrigin, Decoded, Encoded, Identity, JustTry};
mod drop_assets;
pub use drop_assets::{ClaimAssets, DropAssets};
mod asset_lock;
Expand Down Expand Up @@ -51,7 +49,7 @@ pub mod prelude {
export_xcm, validate_export, AssetExchange, AssetLock, ClaimAssets, Convert, ConvertOrigin,
Decoded, DropAssets, Enact, Encoded, Error, ExportXcm, FeeManager, FeeReason, Identity,
JustTry, LockError, MatchesFungible, MatchesFungibles, MatchesNonFungible,
MatchesNonFungibles, OnResponse, ShouldExecute, TransactAsset,
VersionChangeNotifier, WeightBounds, WeightTrader,
MatchesNonFungibles, OnResponse, ShouldExecute, TransactAsset, VersionChangeNotifier,
WeightBounds, WeightTrader,
};
}
5 changes: 2 additions & 3 deletions xcm/xcm-simulator/example/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ use xcm::{latest::prelude::*, VersionedXcm};
use xcm_builder::{
Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId,
CurrencyAdapter as XcmCurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds,
IsConcrete, NativeAsset, NonFungiblesAdapter, ParentIsPreset,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation,
IsConcrete, NativeAsset, NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
};
use xcm_executor::{
traits::{Convert, JustTry},
Expand Down
4 changes: 2 additions & 2 deletions xcm/xcm-simulator/example/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use xcm_builder::{
Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
ConvertedConcreteId, CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible,
FixedWeightBounds, IsConcrete, NonFungiblesAdapter,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
FixedWeightBounds, IsConcrete, NonFungiblesAdapter, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation,
};
use xcm_executor::{traits::JustTry, Config, XcmExecutor};

Expand Down
6 changes: 3 additions & 3 deletions xcm/xcm-simulator/fuzzer/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ use polkadot_parachain::primitives::{
use xcm::{latest::prelude::*, VersionedXcm};
use xcm_builder::{
AccountId32Aliases, AllowUnpaidExecutionFrom, CurrencyAdapter as XcmCurrencyAdapter,
EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, IsConcrete,
NativeAsset, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation,
EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, IsConcrete, NativeAsset,
ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation,
};
use xcm_executor::{Config, XcmExecutor};

Expand Down