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

Commit 6283c1f

Browse files
gavofyorkbkchr
andauthored
Support XCM v1 (Companion to #2815) (#561)
* support for XCM v1 * Fixes * Fix. * Use `xcm::latest` * Bump Polkadot Co-authored-by: Bastian Köcher <info@kchr.de>
1 parent 4f93668 commit 6283c1f

File tree

12 files changed

+313
-306
lines changed

12 files changed

+313
-306
lines changed

Cargo.lock

+257-257
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/dmp-queue/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
2626
use cumulus_primitives_core::DmpMessageHandler;
2727
use codec::{Encode, Decode};
2828
use sp_runtime::RuntimeDebug;
29-
use xcm::{VersionedXcm, v0::{Xcm, Junction, Outcome, ExecuteXcm, Error as XcmError}};
29+
use xcm::{VersionedXcm, latest::{Xcm, Junction, Outcome, ExecuteXcm, Error as XcmError}};
3030
use frame_support::{traits::EnsureOrigin, dispatch::Weight, weights::constants::WEIGHT_PER_MILLIS};
3131
pub use pallet::*;
3232

@@ -341,11 +341,11 @@ mod tests {
341341
use sp_runtime::{testing::Header, traits::{IdentityLookup, BlakeTwo256}};
342342
use sp_runtime::DispatchError::BadOrigin;
343343
use sp_version::RuntimeVersion;
344-
use xcm::v0::{MultiLocation, OriginKind};
344+
use xcm::latest::{MultiLocation, OriginKind};
345345

346346
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
347347
type Block = frame_system::mocking::MockBlock<Test>;
348-
type Xcm = xcm::v0::Xcm<Call>;
348+
type Xcm = xcm::latest::Xcm<Call>;
349349

350350
frame_support::construct_runtime!(
351351
pub enum Test where

pallets/xcm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use cumulus_primitives_core::{ParaId, DmpMessageHandler};
2525
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
2626
use codec::{Encode, Decode};
2727
use sp_runtime::traits::BadOrigin;
28-
use xcm::{VersionedXcm, v0::{Xcm, Junction, Outcome, ExecuteXcm}};
28+
use xcm::{VersionedXcm, latest::{Xcm, Junction, Outcome, ExecuteXcm}};
2929
use frame_support::dispatch::Weight;
3030
pub use pallet::*;
3131

pallets/xcmp-queue/src/lib.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,8 @@ use rand_chacha::{
4242
ChaChaRng,
4343
};
4444
use sp_runtime::{traits::Hash, RuntimeDebug};
45-
use sp_std::{convert::TryFrom, prelude::*};
46-
use xcm::{
47-
v0::{Error as XcmError, ExecuteXcm, Junction, MultiLocation, Outcome, SendXcm, Xcm},
48-
VersionedXcm,
49-
};
45+
use sp_std::{prelude::*, convert::TryFrom};
46+
use xcm::{latest::prelude::*, WrapVersion, VersionedXcm};
5047

5148
pub use pallet::*;
5249

@@ -69,6 +66,9 @@ pub mod pallet {
6966

7067
/// Information on the avaialble XCMP channels.
7168
type ChannelInfo: GetChannelInfo;
69+
70+
/// Means of converting an `Xcm` into a `VersionedXcm`.
71+
type VersionWrapper: WrapVersion;
7272
}
7373

7474
impl Default for QueueConfigData {
@@ -351,7 +351,7 @@ impl<T: Config> Pallet<T> {
351351
log::debug!("Processing XCMP-XCM: {:?}", &hash);
352352
let (result, event) = match Xcm::<T::Call>::try_from(xcm) {
353353
Ok(xcm) => {
354-
let location = (Junction::Parent, Junction::Parachain(sender.into()));
354+
let location = (Parent, Parachain(sender.into()));
355355
match T::XcmExecutor::execute_xcm(location.into(), xcm, max_weight) {
356356
Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)),
357357
Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))),
@@ -777,13 +777,14 @@ impl<T: Config> SendXcm for Pallet<T> {
777777
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> Result<(), XcmError> {
778778
match &dest {
779779
// An HRMP message for a sibling parachain.
780-
MultiLocation::X2(Junction::Parent, Junction::Parachain(id)) => {
781-
let msg = VersionedXcm::<()>::from(msg);
782-
let hash = T::Hashing::hash_of(&msg);
780+
X2(Parent, Parachain(id)) => {
781+
let versioned_xcm = T::VersionWrapper::wrap_version(&dest, msg)
782+
.map_err(|()| XcmError::DestinationUnsupported)?;
783+
let hash = T::Hashing::hash_of(&versioned_xcm);
783784
Self::send_fragment(
784785
(*id).into(),
785786
XcmpMessageFormat::ConcatenatedVersionedXcm,
786-
msg,
787+
versioned_xcm,
787788
)
788789
.map_err(|e| XcmError::SendFailed(<&'static str>::from(e)))?;
789790
Self::deposit_event(Event::XcmpMessageSent(Some(hash)));

pallets/xcmp-queue/src/mock.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ use super::*;
1717
use crate as xcmp_queue;
1818
use sp_core::H256;
1919
use frame_support::parameter_types;
20-
use sp_runtime::{
21-
traits::{BlakeTwo256, IdentityLookup},
22-
testing::{Header},
23-
};
20+
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
2421
use xcm_builder::{
2522
FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, CurrencyAdapter,
2623
ParentIsDefault,
@@ -107,10 +104,8 @@ impl cumulus_pallet_parachain_system::Config for Test {
107104
}
108105

109106
parameter_types! {
110-
pub const RelayChain: MultiLocation = MultiLocation::X1(Junction::Parent);
111-
pub Ancestry: MultiLocation = MultiLocation::X1(
112-
Junction::Parachain(1u32.into())
113-
);
107+
pub const RelayChain: MultiLocation = X1(Parent);
108+
pub Ancestry: MultiLocation = X1(Parachain(1u32.into()));
114109
pub UnitWeightCost: Weight = 1_000_000;
115110
}
116111

@@ -157,6 +152,7 @@ impl Config for Test {
157152
type Event = Event;
158153
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
159154
type ChannelInfo = ParachainSystem;
155+
type VersionWrapper = ();
160156
}
161157

162158
pub fn new_test_ext() -> sp_io::TestExternalities {

polkadot-parachains/pallets/ping/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use sp_runtime::traits::Saturating;
2323
use frame_system::Config as SystemConfig;
2424
use cumulus_primitives_core::ParaId;
2525
use cumulus_pallet_xcm::{Origin as CumulusOrigin, ensure_sibling_para};
26-
use xcm::v0::{Xcm, Error as XcmError, SendXcm, OriginKind, MultiLocation, Junction};
26+
use xcm::latest::{Xcm, Error as XcmError, SendXcm, OriginKind, MultiLocation, Junction};
2727

2828
pub use pallet::*;
2929

polkadot-parachains/rococo/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub use sp_runtime::{Perbill, Permill};
5656
// XCM imports
5757
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
5858
use polkadot_parachain::primitives::Sibling;
59-
use xcm::v0::{BodyId, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId, Xcm};
59+
use xcm::latest::prelude::*;
6060
use xcm_builder::{
6161
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
6262
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
@@ -356,7 +356,7 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RococoNe
356356
/// queues.
357357
pub type XcmRouter = (
358358
// Two routers - use UMP to communicate with the relay chain:
359-
cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,
359+
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
360360
// ..and XCMP to communicate with the sibling chains.
361361
XcmpQueue,
362362
);
@@ -371,6 +371,7 @@ impl pallet_xcm::Config for Runtime {
371371
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
372372
type XcmReserveTransferFilter = ();
373373
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
374+
type LocationInverter = LocationInverter<Ancestry>;
374375
}
375376

376377
impl cumulus_pallet_xcm::Config for Runtime {
@@ -382,6 +383,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
382383
type Event = Event;
383384
type XcmExecutor = XcmExecutor<XcmConfig>;
384385
type ChannelInfo = ParachainSystem;
386+
type VersionWrapper = ();
385387
}
386388

387389
impl cumulus_pallet_dmp_queue::Config for Runtime {

polkadot-parachains/shell/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub use sp_runtime::BuildStorage;
5151
pub use sp_runtime::{Perbill, Permill};
5252

5353
// XCM imports
54-
use xcm::v0::{Junction::*, MultiLocation, MultiLocation::*, NetworkId};
54+
use xcm::latest::prelude::*;
5555
use xcm_builder::{
5656
AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter, ParentAsSuperuser,
5757
ParentIsDefault, SovereignSignedViaLocation,

polkadot-parachains/statemine/src/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub use sp_runtime::BuildStorage;
6868
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
6969
use polkadot_parachain::primitives::Sibling;
7070
use polkadot_runtime_common::{BlockHashCount, RocksDbWeight, SlowAdjustingFeeUpdate};
71-
use xcm::v0::{BodyId, Junction, MultiAsset, MultiLocation, NetworkId, Xcm};
71+
use xcm::latest::prelude::*;
7272
use xcm_builder::{
7373
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
7474
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
@@ -464,10 +464,10 @@ impl parachain_info::Config for Runtime {}
464464
impl cumulus_pallet_aura_ext::Config for Runtime {}
465465

466466
parameter_types! {
467-
pub const KsmLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
467+
pub const KsmLocation: MultiLocation = X1(Parent);
468468
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
469469
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
470-
pub Ancestry: MultiLocation = Junction::Parachain(ParachainInfo::parachain_id().into()).into();
470+
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
471471
}
472472

473473
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
@@ -527,8 +527,8 @@ parameter_types! {
527527

528528
match_type! {
529529
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
530-
MultiLocation::X1(Junction::Parent) |
531-
MultiLocation::X2(Junction::Parent, Junction::Plurality { id: BodyId::Executive, .. })
530+
X1(Parent) |
531+
X2(Parent, Plurality { id: BodyId::Executive, .. })
532532
};
533533
}
534534

@@ -566,7 +566,7 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNet
566566
/// queues.
567567
pub type XcmRouter = (
568568
// Two routers - use UMP to communicate with the relay chain:
569-
cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,
569+
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
570570
// ..and XCMP to communicate with the sibling chains.
571571
XcmpQueue,
572572
);
@@ -581,6 +581,7 @@ impl pallet_xcm::Config for Runtime {
581581
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
582582
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>;
583583
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
584+
type LocationInverter = LocationInverter<Ancestry>;
584585
}
585586

586587
impl cumulus_pallet_xcm::Config for Runtime {
@@ -592,6 +593,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
592593
type Event = Event;
593594
type XcmExecutor = XcmExecutor<XcmConfig>;
594595
type ChannelInfo = ParachainSystem;
596+
type VersionWrapper = ();
595597
}
596598

597599
impl cumulus_pallet_dmp_queue::Config for Runtime {

polkadot-parachains/statemint/src/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub use sp_runtime::BuildStorage;
6868
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
6969
use polkadot_parachain::primitives::Sibling;
7070
use polkadot_runtime_common::{BlockHashCount, RocksDbWeight, SlowAdjustingFeeUpdate};
71-
use xcm::v0::{BodyId, Junction, MultiAsset, MultiLocation, NetworkId, Xcm};
71+
use xcm::latest::prelude::*;
7272
use xcm_builder::{
7373
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
7474
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
@@ -432,10 +432,10 @@ impl parachain_info::Config for Runtime {}
432432
impl cumulus_pallet_aura_ext::Config for Runtime {}
433433

434434
parameter_types! {
435-
pub const DotLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
435+
pub const DotLocation: MultiLocation = X1(Parent);
436436
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
437437
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
438-
pub Ancestry: MultiLocation = Junction::Parachain(ParachainInfo::parachain_id().into()).into();
438+
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
439439
}
440440

441441
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
@@ -495,8 +495,8 @@ parameter_types! {
495495

496496
match_type! {
497497
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
498-
MultiLocation::X1(Junction::Parent) |
499-
MultiLocation::X2(Junction::Parent, Junction::Plurality { id: BodyId::Executive, .. })
498+
X1(Parent) |
499+
X2(Parent, Plurality { id: BodyId::Executive, .. })
500500
};
501501
}
502502

@@ -534,7 +534,7 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNet
534534
/// queues.
535535
pub type XcmRouter = (
536536
// Two routers - use UMP to communicate with the relay chain:
537-
cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,
537+
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
538538
// ..and XCMP to communicate with the sibling chains.
539539
XcmpQueue,
540540
);
@@ -549,6 +549,7 @@ impl pallet_xcm::Config for Runtime {
549549
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
550550
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>;
551551
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
552+
type LocationInverter = LocationInverter<Ancestry>;
552553
}
553554

554555
impl cumulus_pallet_xcm::Config for Runtime {
@@ -560,6 +561,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
560561
type Event = Event;
561562
type XcmExecutor = XcmExecutor<XcmConfig>;
562563
type ChannelInfo = ParachainSystem;
564+
type VersionWrapper = ();
563565
}
564566

565567
impl cumulus_pallet_dmp_queue::Config for Runtime {

polkadot-parachains/westmint/src/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub use sp_runtime::BuildStorage;
6868
use pallet_xcm::XcmPassthrough;
6969
use polkadot_parachain::primitives::Sibling;
7070
use polkadot_runtime_common::{BlockHashCount, RocksDbWeight, SlowAdjustingFeeUpdate};
71-
use xcm::v0::{Junction, MultiAsset, MultiLocation, NetworkId, Xcm};
71+
use xcm::latest::prelude::*;
7272
use xcm_builder::{
7373
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
7474
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
@@ -431,10 +431,10 @@ impl parachain_info::Config for Runtime {}
431431
impl cumulus_pallet_aura_ext::Config for Runtime {}
432432

433433
parameter_types! {
434-
pub const WestendLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
434+
pub const WestendLocation: MultiLocation = X1(Parent);
435435
pub RelayNetwork: NetworkId = NetworkId::Named(b"Westend".to_vec());
436436
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
437-
pub Ancestry: MultiLocation = Junction::Parachain(ParachainInfo::parachain_id().into()).into();
437+
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
438438
}
439439

440440
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
@@ -493,8 +493,8 @@ parameter_types! {
493493

494494
match_type! {
495495
pub type ParentOrParentsPlurality: impl Contains<MultiLocation> = {
496-
MultiLocation::X1(Junction::Parent) |
497-
MultiLocation::X2(Junction::Parent, Junction::Plurality { .. })
496+
X1(Parent) |
497+
X2(Parent, Plurality { .. })
498498
};
499499
}
500500

@@ -532,7 +532,7 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNet
532532
/// queues.
533533
pub type XcmRouter = (
534534
// Two routers - use UMP to communicate with the relay chain:
535-
cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,
535+
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
536536
// ..and XCMP to communicate with the sibling chains.
537537
XcmpQueue,
538538
);
@@ -547,6 +547,7 @@ impl pallet_xcm::Config for Runtime {
547547
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
548548
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>;
549549
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
550+
type LocationInverter = LocationInverter<Ancestry>;
550551
}
551552

552553
impl cumulus_pallet_xcm::Config for Runtime {
@@ -558,6 +559,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
558559
type Event = Event;
559560
type XcmExecutor = XcmExecutor<XcmConfig>;
560561
type ChannelInfo = ParachainSystem;
562+
type VersionWrapper = ();
561563
}
562564

563565
impl cumulus_pallet_dmp_queue::Config for Runtime {

primitives/utility/src/lib.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use sp_std::marker::PhantomData;
2323
use codec::Encode;
2424
use cumulus_primitives_core::UpwardMessageSender;
25-
use xcm::{VersionedXcm, v0::{Xcm, MultiLocation, Junction, SendXcm, Error as XcmError}};
25+
use xcm::{WrapVersion, latest::prelude::*};
2626

2727
/// Xcm router which recognises the `Parent` destination and handles it by sending the message into
2828
/// the given UMP `UpwardMessageSender` implementation. Thus this essentially adapts an
@@ -31,13 +31,15 @@ use xcm::{VersionedXcm, v0::{Xcm, MultiLocation, Junction, SendXcm, Error as Xcm
3131
/// NOTE: This is a pretty dumb "just send it" router; we will probably want to introduce queuing
3232
/// to UMP eventually and when we do, the pallet which implements the queuing will be responsible
3333
/// for the `SendXcm` implementation.
34-
pub struct ParentAsUmp<T>(PhantomData<T>);
35-
impl<T: UpwardMessageSender> SendXcm for ParentAsUmp<T> {
34+
pub struct ParentAsUmp<T, W>(PhantomData<(T, W)>);
35+
impl<T: UpwardMessageSender, W: WrapVersion> SendXcm for ParentAsUmp<T, W> {
3636
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> Result<(), XcmError> {
3737
match &dest {
3838
// An upward message for the relay chain.
39-
MultiLocation::X1(Junction::Parent) => {
40-
let data = VersionedXcm::<()>::from(msg).encode();
39+
MultiLocation::X1(Parent) => {
40+
let versioned_xcm = W::wrap_version(&dest, msg)
41+
.map_err(|()| XcmError::DestinationUnsupported)?;
42+
let data = versioned_xcm.encode();
4143

4244
T::send_upward_message(data)
4345
.map_err(|e| XcmError::SendFailed(e.into()))?;

0 commit comments

Comments
 (0)