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

Some late fixes for XCMv3 #5237

Merged
merged 17 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions runtime/kusama/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,7 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
// XCM Executor does not currently support alias origin operations
Weight::MAX.ref_time()
}
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> XCMWeight {
XcmGeneric::<Runtime>::unpaid_execution().ref_time()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
pub(crate) fn set_fees_mode() -> Weight {
Weight::from_ref_time(3_599_000 as u64)
}
pub(crate) fn unpaid_execution() -> Weight {
Weight::from_ref_time(3_111_000 as u64)
}
}
6 changes: 3 additions & 3 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use xcm_builder::{
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, BackingToPlurality,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds,
MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents, WeightInfoBounds,
};

parameter_types! {
Expand All @@ -47,7 +47,7 @@ parameter_types! {
/// Since Kusama is a top-level relay-chain with its own consensus, it's just our network ID.
pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into();
/// The check account, which holds any native assets that have been teleported out and not back in (yet).
pub CheckAccount: AccountId = XcmPallet::check_account();
pub CheckAccount: (AccountId, MintLocation) = (XcmPallet::check_account(), MintLocation::Local);
}

/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to determine
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 @@ -30,8 +30,8 @@ use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, BackingToPlurality, ChildParachainAsNative,
ChildParachainConvertsVia, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds,
IsConcrete, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents,
IsConcrete, MintLocation, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
};

parameter_types! {
Expand All @@ -44,7 +44,7 @@ parameter_types! {
/// Our location in the universe of consensus systems.
pub const UniversalLocation: InteriorMultiLocation = X1(GlobalConsensus(ThisNetwork::get()));
/// The check account, which holds any native assets that have been teleported out and not back in (yet).
pub CheckAccount: AccountId = XcmPallet::check_account();
pub CheckAccount: (AccountId, MintLocation) = (XcmPallet::check_account(), MintLocation::Local);
}

/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to determine
Expand Down
3 changes: 3 additions & 0 deletions runtime/rococo/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,7 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for RococoXcmWeight<RuntimeCall> {
// XCM Executor does not currently support alias origin operations
Weight::MAX.ref_time()
}
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> XCMWeight {
XcmGeneric::<Runtime>::unpaid_execution().ref_time()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
pub(crate) fn set_fees_mode() -> Weight {
Weight::from_ref_time(3_721_000 as u64)
}
pub(crate) fn unpaid_execution() -> Weight {
Weight::from_ref_time(3_111_000 as u64)
}
}
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,16 +31,16 @@ use xcm_builder::{
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, BackingToPlurality,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds,
MintLocation, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents, WeightInfoBounds,
};
use xcm_executor::XcmExecutor;

parameter_types! {
pub const TokenLocation: MultiLocation = Here.into_location();
pub const ThisNetwork: NetworkId = NetworkId::Rococo;
pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into();
pub CheckAccount: AccountId = XcmPallet::check_account();
pub CheckAccount: (AccountId, MintLocation) = (XcmPallet::check_account(), MintLocation::Local);
}

pub type LocationConverter =
Expand Down
3 changes: 3 additions & 0 deletions runtime/westend/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,7 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
// XCM Executor does not currently support alias origin operations
Weight::MAX.ref_time()
}
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> XCMWeight {
XcmGeneric::<Runtime>::unpaid_execution().ref_time()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,7 @@ impl<T: frame_system::Config> WeightInfo<T> {
pub(crate) fn set_fees_mode() -> Weight {
Weight::from_ref_time(3_721_000 as u64)
}
pub(crate) fn unpaid_execution() -> Weight {
Weight::from_ref_time(3_111_000 as u64)
}
}
4 changes: 2 additions & 2 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,
CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, MintLocation,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds,
};
Expand All @@ -40,7 +40,7 @@ parameter_types! {
pub const TokenLocation: MultiLocation = Here.into_location();
pub const ThisNetwork: NetworkId = Westend;
pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into();
pub CheckAccount: AccountId = XcmPallet::check_account();
pub CheckAccount: (AccountId, MintLocation) = (XcmPallet::check_account(), MintLocation::Local);
}

pub type LocationConverter =
Expand Down
4 changes: 3 additions & 1 deletion xcm/pallet-xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ sp-io = { default-features = false, branch = "master", git = "https://github.com
xcm-executor = { path = "../xcm-executor", default-features = false }
frame-benchmarking = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" }
xcm = { path = "..", default-features = false }
xcm-builder = { path = "../xcm-builder", default-features = false }
log = "0.4.17"

[dev-dependencies]
pallet-balances = { branch = "master", git = "https://github.com/paritytech/substrate" }
pallet-assets = { branch = "master", git = "https://github.com/paritytech/substrate" }
sp-core = { branch = "master", git = "https://github.com/paritytech/substrate" }
sp-tracing = { branch = "master", git = "https://github.com/paritytech/substrate" }
xcm-builder = { path = "../xcm-builder" }
xcm = { path = ".." }
# temp
pallet-xcm = { path = "../pallet-xcm" }
Expand All @@ -43,10 +43,12 @@ std = [
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm-builder/std",
"xcm-executor/std"
]
runtime-benchmarks = [
"xcm/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
Expand Down
6 changes: 3 additions & 3 deletions xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ benchmarks_instance_pallet! {
let (trusted_teleporter, teleportable_asset) = T::TrustedTeleporter::get()
.ok_or(BenchmarkError::Skip)?;

if let Some(checked_account) = T::CheckedAccount::get() {
if let Some((checked_account, _)) = T::CheckedAccount::get() {
T::TransactAsset::mint_into(
&checked_account,
<
Expand Down Expand Up @@ -223,7 +223,7 @@ benchmarks_instance_pallet! {
holding.push(asset.clone());

// Checked account starts at zero
assert!(T::CheckedAccount::get().map_or(true, |c| T::TransactAsset::balance(&c).is_zero()));
assert!(T::CheckedAccount::get().map_or(true, |(c, _)| T::TransactAsset::balance(&c).is_zero()));

let mut executor = new_executor::<T>(Default::default());
executor.set_holding(holding.into());
Expand All @@ -236,7 +236,7 @@ benchmarks_instance_pallet! {
}: {
executor.bench_process(xcm)?;
} verify {
if let Some(checked_account) = T::CheckedAccount::get() {
if let Some((checked_account, _)) = T::CheckedAccount::get() {
// teleport checked account should have received some asset.
assert!(!T::TransactAsset::balance(&checked_account).is_zero());
}
Expand Down
8 changes: 4 additions & 4 deletions xcm/pallet-xcm-benchmarks/src/fungible/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_runtime::{
BuildStorage,
};
use xcm::latest::prelude::*;
use xcm_builder::AllowUnpaidExecutionFrom;
use xcm_builder::{AllowUnpaidExecutionFrom, MintLocation};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -123,7 +123,7 @@ pub type AssetTransactor = xcm_builder::CurrencyAdapter<
MatchAnyFungible,
AccountIdConverter,
u64,
CheckedAccount,
CheckingAccount,
>;

parameter_types! {
Expand Down Expand Up @@ -179,7 +179,7 @@ impl crate::Config for Test {
pub type TrustedTeleporters = (xcm_builder::Case<TeleportConcreteFungible>,);

parameter_types! {
pub const CheckedAccount: Option<u64> = Some(100);
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((
ChildTeleporter::get(),
Expand All @@ -193,7 +193,7 @@ parameter_types! {

impl xcm_balances_benchmark::Config for Test {
type TransactAsset = Balances;
type CheckedAccount = CheckedAccount;
type CheckedAccount = CheckingAccount;
type TrustedTeleporter = TrustedTeleporter;

fn get_multi_asset() -> MultiAsset {
Expand Down
2 changes: 1 addition & 1 deletion xcm/pallet-xcm-benchmarks/src/fungible/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub mod pallet {
type TransactAsset: frame_support::traits::fungible::Mutate<Self::AccountId>;

/// The account used to check assets being teleported.
type CheckedAccount: Get<Option<Self::AccountId>>;
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)>>;
Expand Down
15 changes: 9 additions & 6 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ use sp_runtime::{
RuntimeDebug,
};
use sp_std::{boxed::Box, marker::PhantomData, prelude::*, result::Result, vec};
use xcm::{latest::{QueryResponseInfo, Weight as XcmWeight}, prelude::*};
use xcm::{
latest::{QueryResponseInfo, Weight as XcmWeight},
prelude::*,
};
use xcm_executor::traits::{Convert, ConvertOrigin};

use frame_support::{
Expand Down Expand Up @@ -779,8 +782,8 @@ pub mod pallet {
origin_location,
message,
hash,
max_weight.ref_time(),
max_weight.ref_time(),
max_weight, //.ref_time(),
max_weight, //.ref_time(),
);
let result = Ok(Some(outcome.weight_used().saturating_add(100_000_000)).into());
Self::deposit_event(Event::Attempted(outcome));
Expand Down Expand Up @@ -1341,7 +1344,7 @@ impl<T: Config> Pallet<T> {
let responder = responder.into();
let destination = T::UniversalLocation::get()
.invert_target(&responder)
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
.map_err(|()| XcmError::LocationNotInvertible)?;
let query_id = Self::new_query(responder, timeout, Here);
let response_info = QueryResponseInfo { destination, query_id, max_weight: 0 };
let report_error = Xcm(vec![ReportError(response_info)]);
Expand Down Expand Up @@ -1380,7 +1383,7 @@ impl<T: Config> Pallet<T> {
let responder = responder.into();
let destination = T::UniversalLocation::get()
.invert_target(&responder)
.map_err(|()| XcmError::MultiLocationNotInvertible)?;
.map_err(|()| XcmError::LocationNotInvertible)?;
let notify: <T as Config>::RuntimeCall = notify.into();
let max_weight = notify.get_dispatch_info().weight.ref_time();
let query_id = Self::new_notify_query(responder, notify, timeout, Here);
Expand Down Expand Up @@ -1479,7 +1482,7 @@ impl<T: Config> xcm_executor::traits::Enact for LockTicket<T> {
None => {
locks
.try_push((self.amount, self.unlocker.clone().into()))
.map_err(|()| UnexpectedState)?;
.map_err(|(_balance, _location)| UnexpectedState)?;
},
}
LockedFungibles::<T>::insert(&self.sovereign_account, locks);
Expand Down
4 changes: 2 additions & 2 deletions xcm/src/v2/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl TryFrom<NewError> for Error {
Unimplemented => Self::Unimplemented,
UntrustedReserveLocation => Self::UntrustedReserveLocation,
UntrustedTeleportLocation => Self::UntrustedTeleportLocation,
MultiLocationFull => Self::MultiLocationFull,
MultiLocationNotInvertible => Self::MultiLocationNotInvertible,
LocationFull => Self::MultiLocationFull,
LocationNotInvertible => Self::MultiLocationNotInvertible,
BadOrigin => Self::BadOrigin,
InvalidLocation => Self::InvalidLocation,
AssetNotFound => Self::AssetNotFound,
Expand Down
30 changes: 30 additions & 0 deletions xcm/src/v3/junctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,36 @@ impl Junctions {
}
}

/// Extract the network ID and the interior consensus location, treating this value as a
/// universal location.
///
/// This will return an `Err` if the first item is not a `GlobalConsensus`, which would indicate
/// that this value is not a universal location.
pub fn split_global(self) -> Result<(NetworkId, Junctions), ()> {
match self.split_first() {
(location, Some(Junction::GlobalConsensus(network))) => Ok((network, location)),
_ => return Err(()),
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// Treat `self` as a universal location and the context of `relative`, returning the universal
/// location of relative.
///
/// This will return an error if `relative` has as many (or more) parents than there are
/// junctions in `self`, implying that relative refers into a different global consensus.
pub fn within_global(mut self, relative: MultiLocation) -> Result<Self, ()> {
if self.len() <= relative.parents as usize {
return Err(())
}
for _ in 0..relative.parents {
self.take_last();
}
for j in relative.interior {
self.push(j).map_err(|_| ())?;
}
Ok(self)
}

/// Consumes `self` and returns how `viewer` would address it locally.
pub fn relative_to(mut self, viewer: &Junctions) -> MultiLocation {
let mut i = 0;
Expand Down
16 changes: 16 additions & 0 deletions xcm/src/v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,18 @@ pub enum Instruction<Call> {
///
/// Errors: If the existing state would not allow such a change.
AliasOrigin(MultiLocation),

/// A directive to indicate that the origin expects free execution of the message.
///
/// At execution time, this instruction just does a check on the Origin register.
/// However, at the barrier stage messages starting with this instruction can be disregarded if
/// the origin is not acceptable for free execution or the `weight_limit` is `Limited` and
/// insufficient.
///
/// Kind: *Indication*
///
/// Errors: If the given origin is `Some` and not equal to the current Origin register.
UnpaidExecution { weight_limit: WeightLimit, check_origin: Option<MultiLocation> },
}

impl<Call> Xcm<Call> {
Expand Down Expand Up @@ -1060,6 +1072,8 @@ impl<Call> Instruction<Call> {
SetTopic(topic) => SetTopic(topic),
ClearTopic => ClearTopic,
AliasOrigin(location) => AliasOrigin(location),
UnpaidExecution { weight_limit, check_origin } =>
UnpaidExecution { weight_limit, check_origin },
}
}
}
Expand Down Expand Up @@ -1126,6 +1140,8 @@ impl<Call, W: XcmWeightInfo<Call>> GetWeight<W> for Instruction<Call> {
SetTopic(topic) => W::set_topic(topic),
ClearTopic => W::clear_topic(),
AliasOrigin(location) => W::alias_origin(location),
UnpaidExecution { weight_limit, check_origin } =>
W::unpaid_execution(weight_limit, check_origin),
}
}
}
Expand Down
Loading