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

XCM v1 #2815

Merged
merged 87 commits into from
Aug 6, 2021
Merged

XCM v1 #2815

Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
3e15173
MultiAsset TWO
gavofyork Apr 4, 2021
12054df
Merge remote-tracking branch 'origin/master' into gav-multiasset-2
gavofyork Jul 29, 2021
ee80e03
Draft next MultiAsset API.
gavofyork Jul 30, 2021
2661b91
XCM core builds
gavofyork Jul 30, 2021
6fc030e
XCM Executor builds
gavofyork Jul 30, 2021
8017453
XCM Builder builds
gavofyork Jul 31, 2021
5445d06
API changes making their way throughout
gavofyork Aug 1, 2021
958d79a
Some TODOs
gavofyork Aug 1, 2021
7d47d21
Further build fixes
gavofyork Aug 1, 2021
bb5bf44
Basic compile builds
gavofyork Aug 1, 2021
acef319
First test fixed
gavofyork Aug 1, 2021
7d700b6
All executor tests fixed
gavofyork Aug 1, 2021
3e62aa3
Typo
gavofyork Aug 1, 2021
ca477f0
Optimize subsume_assets and add test
gavofyork Aug 1, 2021
3cc428f
Optimize checked_sub
gavofyork Aug 1, 2021
099aea7
XCM Builder first test fixed
gavofyork Aug 1, 2021
5158442
Fix builder tests
gavofyork Aug 2, 2021
6814aa8
Fix doc test
gavofyork Aug 2, 2021
529a931
fix some doc tests
gavofyork Aug 2, 2021
3e93d54
spelling
gavofyork Aug 2, 2021
f42b3ab
named fields for AllOf
gavofyork Aug 2, 2021
97051b2
Update xcm/src/v0/multiasset.rs
gavofyork Aug 3, 2021
84b79cf
Update xcm/src/v0/multiasset.rs
gavofyork Aug 3, 2021
1f98872
Update xcm/src/v0/multiasset.rs
gavofyork Aug 3, 2021
0cc61de
Update xcm/src/v0/multiasset.rs
gavofyork Aug 3, 2021
4f57497
Merge branch 'master' into gav-multiasset-2-reformat
gavofyork Aug 3, 2021
723990c
Reformat
gavofyork Aug 3, 2021
9e2e009
Move to XCM version 1
gavofyork Aug 3, 2021
00ca37b
Spelling
gavofyork Aug 3, 2021
768c96a
warnings
gavofyork Aug 3, 2021
2936419
Replace some more v0->v1s
gavofyork Aug 3, 2021
015fff2
warnings
gavofyork Aug 3, 2021
b5fe03e
format
gavofyork Aug 3, 2021
608a212
Add max_assets param
gavofyork Aug 3, 2021
dee3be5
building
gavofyork Aug 3, 2021
a6eaaa2
test fixes
gavofyork Aug 3, 2021
f58a659
tests
gavofyork Aug 3, 2021
8a78100
another test
gavofyork Aug 3, 2021
6eb75ad
final test
gavofyork Aug 3, 2021
9d0b9f9
tests
gavofyork Aug 4, 2021
b5b63c8
Rename Null -> Here
gavofyork Aug 4, 2021
e9dbc72
Introduce
gavofyork Aug 4, 2021
36ccb47
More ergonomics
gavofyork Aug 4, 2021
de33d7d
More ergonomics
gavofyork Aug 4, 2021
7ff0493
test fix
gavofyork Aug 4, 2021
d43d987
Merge branch 'gav-multiasset-2' into gav-max-assets
gavofyork Aug 4, 2021
84c44f8
test fixes
gavofyork Aug 4, 2021
7d52b93
docs
gavofyork Aug 4, 2021
51c7d05
BuyExecution includes
gavofyork Aug 4, 2021
851b00e
Fix XCM extrinsics
gavofyork Aug 4, 2021
20bb714
fmt
gavofyork Aug 4, 2021
3f85ebd
Make Vec<MultiAsset>/MultiAssets conversions safe
gavofyork Aug 4, 2021
61a2231
More MultiAssets conversion safety
gavofyork Aug 4, 2021
7646446
Merge remote-tracking branch 'origin/master' into gav-multiasset-2
gavofyork Aug 4, 2021
8644265
spelling
gavofyork Aug 4, 2021
1e75953
fix doc test
gavofyork Aug 4, 2021
669dcb0
Apply suggestions from code review
gavofyork Aug 5, 2021
767bdb5
Apply suggestions from code review
gavofyork Aug 5, 2021
ec2c1e9
fmt
gavofyork Aug 5, 2021
740f6f3
Add v0, remove VersionedMultiAsset
gavofyork Aug 5, 2021
9f8606d
Remove VersionedMultiLocation
gavofyork Aug 5, 2021
1c4a89a
Update xcm/src/v1/order.rs
gavofyork Aug 5, 2021
d3fb090
Update xcm/src/v1/mod.rs
gavofyork Aug 5, 2021
a5c2bde
XCM v0 backwards compatibility
gavofyork Aug 5, 2021
2d0479a
Merge branch 'gav-multiasset-2' of github.com:paritytech/polkadot int…
gavofyork Aug 5, 2021
7130ed7
Full compatibility
gavofyork Aug 5, 2021
efa012d
fmt
gavofyork Aug 5, 2021
a0658e1
Merge branch 'master' into gav-multiasset-2
gavofyork Aug 5, 2021
e33710b
Update xcm/pallet-xcm/src/lib.rs
shawntabrizi Aug 5, 2021
a31887c
Merge branch 'master' into gav-multiasset-2
gavofyork Aug 5, 2021
fe59886
Update xcm/src/v0/order.rs
gavofyork Aug 5, 2021
d2bd1e0
Tweaks to versioning system
gavofyork Aug 6, 2021
089d90c
Merge branch 'gav-multiasset-2' of github.com:paritytech/polkadot int…
gavofyork Aug 6, 2021
d9ff88c
Fixes
gavofyork Aug 6, 2021
b40668e
fmt
gavofyork Aug 6, 2021
53baf5f
Update xcm/xcm-executor/src/assets.rs
gavofyork Aug 6, 2021
0309b2d
Update xcm/xcm-executor/src/assets.rs
gavofyork Aug 6, 2021
0383e58
Grumbles
gavofyork Aug 6, 2021
277f705
Merge branch 'gav-multiasset-2' of github.com:paritytech/polkadot int…
gavofyork Aug 6, 2021
3eee7b3
Update xcm/src/v1/multiasset.rs
gavofyork Aug 6, 2021
c61cd59
fmt
gavofyork Aug 6, 2021
ac31e7e
Merge branch 'gav-multiasset-2' of github.com:paritytech/polkadot int…
gavofyork Aug 6, 2021
0547932
Update xcm/src/v1/multiasset.rs
gavofyork Aug 6, 2021
18dca5f
Update xcm/src/v1/multiasset.rs
gavofyork Aug 6, 2021
48e3eba
Merge branch 'gav-multiasset-2' of github.com:paritytech/polkadot int…
gavofyork Aug 6, 2021
04e32dc
Fixes
gavofyork Aug 6, 2021
c234c51
Formatting
gavofyork Aug 6, 2021
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
21 changes: 11 additions & 10 deletions runtime/common/src/xcm_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,30 @@
use parity_scale_codec::Encode;
use runtime_parachains::{configuration, dmp};
use sp_std::marker::PhantomData;
use xcm::opaque::{
v0::{Error, Junction, MultiLocation, Result, SendXcm, Xcm},
VersionedXcm,
};
use xcm::opaque::v1::{Error, Junction, MultiLocation, Result, SendXcm, Xcm};

/// XCM sender for relay chain. It only sends downward message.
pub struct ChildParachainRouter<T>(PhantomData<T>);
pub struct ChildParachainRouter<T, W>(PhantomData<(T, W)>);

impl<T: configuration::Config + dmp::Config> SendXcm for ChildParachainRouter<T> {
impl<T: configuration::Config + dmp::Config, W: xcm::WrapVersion> SendXcm
for ChildParachainRouter<T, W>
{
fn send_xcm(dest: MultiLocation, msg: Xcm) -> Result {
match dest {
match &dest {
MultiLocation::X1(Junction::Parachain(id)) => {
// Downward message passing.
let versioned_xcm =
W::wrap_version(&dest, msg).map_err(|()| Error::DestinationUnsupported)?;
let config = <configuration::Pallet<T>>::config();
<dmp::Pallet<T>>::queue_downward_message(
&config,
id.into(),
VersionedXcm::from(msg).encode(),
(*id).into(),
versioned_xcm.encode(),
)
.map_err(Into::<Error>::into)?;
Ok(())
},
d => Err(Error::CannotReachDestination(d, msg)),
_ => Err(Error::CannotReachDestination(dest, msg)),
}
}
}
75 changes: 9 additions & 66 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ use sp_staking::SessionIndex;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use static_assertions::const_assert;
use xcm::v0::{
BodyId,
Junction::Parachain,
MultiAsset::{self, AllConcreteFungible},
MultiLocation::{self, Null, X1},
NetworkId, Xcm,
};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
BackingToPlurality, ChildParachainAsNative, ChildParachainConvertsVia,
Expand Down Expand Up @@ -1205,14 +1199,14 @@ impl auctions::Config for Runtime {

parameter_types! {
/// The location of the KSM token, from the context of this chain. Since this token is native to this
/// chain, we make it synonymous with it and thus it is the `Null` location, which means "equivalent to
/// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to
/// the context".
pub const KsmLocation: MultiLocation = MultiLocation::Null;
pub const KsmLocation: MultiLocation = MultiLocation::Here;
/// The Kusama network ID. This is named.
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
/// Our XCM location ancestry - i.e. what, if anything, `Parent` means evaluated in our context. Since
/// Kusama is a top-level relay-chain, there is no ancestry.
pub const Ancestry: MultiLocation = MultiLocation::Null;
pub const Ancestry: MultiLocation = MultiLocation::Here;
/// The check account, which holds any native assets that have been teleported out and not back in (yet).
pub CheckAccount: AccountId = XcmPallet::check_account();
}
Expand Down Expand Up @@ -1264,12 +1258,12 @@ parameter_types! {
/// individual routers.
pub type XcmRouter = (
// Only one router so far - use DMP to communicate with child parachains.
xcm_sender::ChildParachainRouter<Runtime>,
xcm_sender::ChildParachainRouter<Runtime, xcm::AlwaysRelease>,
);

parameter_types! {
pub const KusamaForStatemint: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain(1000)));
pub const Kusama: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(KsmLocation::get()) });
pub const KusamaForStatemint: (MultiAssetFilter, MultiLocation) = (Kusama::get(), X1(Parachain(1000)));
}
pub type TrustedTeleporters = (xcm_builder::Case<KusamaForStatemint>,);

Expand Down Expand Up @@ -1317,65 +1311,14 @@ pub type LocalOriginToLocation = (
SignedToAccountId32<Origin, AccountId, KusamaNetwork>,
);

pub struct OnlyWithdrawTeleportForAccounts;
impl frame_support::traits::Contains<(MultiLocation, Xcm<Call>)>
for OnlyWithdrawTeleportForAccounts
{
fn contains((ref origin, ref msg): &(MultiLocation, Xcm<Call>)) -> bool {
use xcm::v0::{
Junction::{AccountId32, Plurality},
MultiAsset::{All, ConcreteFungible},
Order::{BuyExecution, DepositAsset, InitiateTeleport},
Xcm::WithdrawAsset,
};
match origin {
// Root and council are are allowed to execute anything.
Null | X1(Plurality { .. }) => true,
X1(AccountId32 { .. }) => {
// An account ID trying to send a message. We ensure that it's sensible.
// This checks that it's of the form:
// WithdrawAsset {
// assets: [ ConcreteFungible { id: Null } ],
// effects: [ BuyExecution, InitiateTeleport {
// assets: All,
// dest: Parachain,
// effects: [ BuyExecution, DepositAssets {
// assets: All,
// dest: AccountId32,
// } ]
// } ]
// }
matches!(msg, WithdrawAsset { ref assets, ref effects }
if assets.len() == 1
&& matches!(assets[0], ConcreteFungible { id: Null, .. })
&& effects.len() == 2
&& matches!(effects[0], BuyExecution { .. })
&& matches!(effects[1], InitiateTeleport { ref assets, dest: X1(Parachain(..)), ref effects }
if assets.len() == 1
&& matches!(assets[0], All)
&& effects.len() == 2
&& matches!(effects[0], BuyExecution { .. })
&& matches!(effects[1], DepositAsset { ref assets, dest: X1(AccountId32{..}) }
if assets.len() == 1
&& matches!(assets[0], All)
)
)
)
},
// Nobody else is allowed to execute anything.
_ => false,
}
}
}

impl pallet_xcm::Config for Runtime {
type Event = Event;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
// Anyone can execute XCM messages locally...
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
// ...but they must match our filter, which requires them to be a simple withdraw + teleport.
type XcmExecuteFilter = OnlyWithdrawTeleportForAccounts;
// ...but they must match our filter, which rejects all.
type XcmExecuteFilter = ();
Comment on lines +1320 to +1321
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the plan is to disable any xcm until both the relay chain and statemine are updated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I just saw no point maintaining the ability to manually execute transfers when there are dispatchables which do it for you. We can open up this filter as needed in the future.

type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use frame_support::pallet_prelude::*;
use primitives::v1::{DownwardMessage, Hash, Id as ParaId, InboundDownwardMessage};
use sp_runtime::traits::{BlakeTwo256, Hash as HashT, SaturatedConversion};
use sp_std::{fmt, prelude::*};
use xcm::v0::Error as XcmError;
use xcm::latest::Error as XcmError;

pub use pallet::*;

Expand Down
6 changes: 3 additions & 3 deletions runtime/parachains/src/hrmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ impl<T: Config> Pallet<T> {

let notification_bytes = {
use parity_scale_codec::Encode as _;
use xcm::opaque::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v1::Xcm, VersionedXcm};

VersionedXcm::from(Xcm::HrmpNewChannelOpenRequest {
sender: u32::from(origin),
Expand Down Expand Up @@ -1066,7 +1066,7 @@ impl<T: Config> Pallet<T> {

let notification_bytes = {
use parity_scale_codec::Encode as _;
use xcm::opaque::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v1::Xcm, VersionedXcm};

VersionedXcm::from(Xcm::HrmpChannelAccepted { recipient: u32::from(origin) }).encode()
};
Expand Down Expand Up @@ -1106,7 +1106,7 @@ impl<T: Config> Pallet<T> {
let config = <configuration::Pallet<T>>::config();
let notification_bytes = {
use parity_scale_codec::Encode as _;
use xcm::opaque::{v0::Xcm, VersionedXcm};
use xcm::opaque::{v1::Xcm, VersionedXcm};

VersionedXcm::from(Xcm::HrmpChannelClosing {
initiator: u32::from(origin),
Expand Down
6 changes: 3 additions & 3 deletions runtime/parachains/src/ump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_std::{
marker::PhantomData,
prelude::*,
};
use xcm::v0::Outcome;
use xcm::latest::Outcome;

pub use pallet::*;

Expand Down Expand Up @@ -78,14 +78,14 @@ pub type MessageId = [u8; 32];
/// and will be forwarded to the XCM Executor.
pub struct XcmSink<XcmExecutor, Config>(PhantomData<(XcmExecutor, Config)>);

impl<XcmExecutor: xcm::v0::ExecuteXcm<C::Call>, C: Config> UmpSink for XcmSink<XcmExecutor, C> {
impl<XcmExecutor: xcm::latest::ExecuteXcm<C::Call>, C: Config> UmpSink for XcmSink<XcmExecutor, C> {
fn process_upward_message(
origin: ParaId,
data: &[u8],
max_weight: Weight,
) -> Result<Weight, (MessageId, Weight)> {
use xcm::{
v0::{Error as XcmError, Junction, MultiLocation, Xcm},
latest::{Error as XcmError, Junction, MultiLocation, Xcm},
VersionedXcm,
};

Expand Down
82 changes: 11 additions & 71 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use polkadot_parachain::primitives::Id as ParaId;

use constants::{currency::*, fee::*, time::*};
use frame_support::traits::InstanceFilter;
use xcm::v0::{BodyId, MultiLocation, NetworkId, Xcm};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, BackingToPlurality, ChildParachainAsNative, ChildParachainConvertsVia,
ChildSystemParachainAsSuperuser, CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds,
Expand Down Expand Up @@ -583,9 +583,9 @@ impl parachains_paras::Config for Runtime {
}

parameter_types! {
pub const RocLocation: MultiLocation = MultiLocation::Null;
pub const RocLocation: MultiLocation = MultiLocation::Here;
pub const RococoNetwork: NetworkId = NetworkId::Polkadot;
pub const Ancestry: MultiLocation = MultiLocation::Null;
pub const Ancestry: MultiLocation = MultiLocation::Here;
pub CheckAccount: AccountId = XcmPallet::check_account();
}

Expand Down Expand Up @@ -620,24 +620,15 @@ parameter_types! {
/// individual routers.
pub type XcmRouter = (
// Only one router so far - use DMP to communicate with child parachains.
xcm_sender::ChildParachainRouter<Runtime>,
xcm_sender::ChildParachainRouter<Runtime, xcm::AlwaysRelease>,
);

use xcm::v0::{
Junction::Parachain,
MultiAsset,
MultiAsset::AllConcreteFungible,
MultiLocation::{Null, X1},
};
parameter_types! {
pub const RococoForTick: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain(100)));
pub const RococoForTrick: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain(110)));
pub const RococoForTrack: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain(120)));
pub const RococoForStatemint: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain(1001)));
pub const Rococo: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(RocLocation::get()) });
pub const RococoForTick: (MultiAssetFilter, MultiLocation) = (Rococo::get(), X1(Parachain(100)));
pub const RococoForTrick: (MultiAssetFilter, MultiLocation) = (Rococo::get(), X1(Parachain(110)));
pub const RococoForTrack: (MultiAssetFilter, MultiLocation) = (Rococo::get(), X1(Parachain(120)));
pub const RococoForStatemint: (MultiAssetFilter, MultiLocation) = (Rococo::get(), X1(Parachain(1001)));
}
pub type TrustedTeleporters = (
xcm_builder::Case<RococoForTick>,
Expand Down Expand Up @@ -692,65 +683,14 @@ pub type LocalOriginToLocation = (
SignedToAccountId32<Origin, AccountId, RococoNetwork>,
);

pub struct OnlyWithdrawTeleportForAccounts;
impl frame_support::traits::Contains<(MultiLocation, Xcm<Call>)>
for OnlyWithdrawTeleportForAccounts
{
fn contains((ref origin, ref msg): &(MultiLocation, Xcm<Call>)) -> bool {
use xcm::v0::{
Junction::{AccountId32, Plurality},
MultiAsset::{All, ConcreteFungible},
Order::{BuyExecution, DepositAsset, InitiateTeleport},
Xcm::WithdrawAsset,
};
match origin {
// Root and collective are allowed to execute anything.
Null | X1(Plurality { .. }) => true,
X1(AccountId32 { .. }) => {
// An account ID trying to send a message. We ensure that it's sensible.
// This checks that it's of the form:
// WithdrawAsset {
// assets: [ ConcreteFungible { id: Null } ],
// effects: [ BuyExecution, InitiateTeleport {
// assets: All,
// dest: Parachain,
// effects: [ BuyExecution, DepositAssets {
// assets: All,
// dest: AccountId32,
// } ]
// } ]
// }
matches!(msg, WithdrawAsset { ref assets, ref effects }
if assets.len() == 1
&& matches!(assets[0], ConcreteFungible { id: Null, .. })
&& effects.len() == 2
&& matches!(effects[0], BuyExecution { .. })
&& matches!(effects[1], InitiateTeleport { ref assets, dest: X1(Parachain(..)), ref effects }
if assets.len() == 1
&& matches!(assets[0], All)
&& effects.len() == 2
&& matches!(effects[0], BuyExecution { .. })
&& matches!(effects[1], DepositAsset { ref assets, dest: X1(AccountId32{..}) }
if assets.len() == 1
&& matches!(assets[0], All)
)
)
)
},
// Nobody else is allowed to execute anything.
_ => false,
}
}
}

impl pallet_xcm::Config for Runtime {
type Event = Event;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
// Anyone can execute XCM messages locally...
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
// ...but they must match our filter, which requires them to be a simple withdraw + teleport.
type XcmExecuteFilter = OnlyWithdrawTeleportForAccounts;
// ...but they must match our filter, which right now rejects everything.
type XcmExecuteFilter = ();
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>;
Expand Down
2 changes: 1 addition & 1 deletion runtime/westend/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub mod fee {
use frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
};
use primitives::v0::Balance;
use primitives::v1::Balance;
use runtime_common::ExtrinsicBaseWeight;
use smallvec::smallvec;
pub use sp_runtime::Perbill;
Expand Down
Loading