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

Support XCM v1 (Companion to #2815) #561

Merged
6 commits merged into from
Aug 6, 2021
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
514 changes: 257 additions & 257 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use cumulus_primitives_core::DmpMessageHandler;
use codec::{Encode, Decode};
use sp_runtime::RuntimeDebug;
use xcm::{VersionedXcm, v0::{Xcm, Junction, Outcome, ExecuteXcm, Error as XcmError}};
use xcm::{VersionedXcm, latest::{Xcm, Junction, Outcome, ExecuteXcm, Error as XcmError}};
use frame_support::{traits::EnsureOrigin, dispatch::Weight, weights::constants::WEIGHT_PER_MILLIS};
pub use pallet::*;

Expand Down Expand Up @@ -341,11 +341,11 @@ mod tests {
use sp_runtime::{testing::Header, traits::{IdentityLookup, BlakeTwo256}};
use sp_runtime::DispatchError::BadOrigin;
use sp_version::RuntimeVersion;
use xcm::v0::{MultiLocation, OriginKind};
use xcm::latest::{MultiLocation, OriginKind};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type Xcm = xcm::v0::Xcm<Call>;
type Xcm = xcm::latest::Xcm<Call>;

frame_support::construct_runtime!(
pub enum Test where
Expand Down
2 changes: 1 addition & 1 deletion pallets/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use cumulus_primitives_core::{ParaId, DmpMessageHandler};
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use codec::{Encode, Decode};
use sp_runtime::traits::BadOrigin;
use xcm::{VersionedXcm, v0::{Xcm, Junction, Outcome, ExecuteXcm}};
use xcm::{VersionedXcm, latest::{Xcm, Junction, Outcome, ExecuteXcm}};
use frame_support::dispatch::Weight;
pub use pallet::*;

Expand Down
21 changes: 11 additions & 10 deletions pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ use rand_chacha::{
ChaChaRng,
};
use sp_runtime::{traits::Hash, RuntimeDebug};
use sp_std::{convert::TryFrom, prelude::*};
use xcm::{
v0::{Error as XcmError, ExecuteXcm, Junction, MultiLocation, Outcome, SendXcm, Xcm},
VersionedXcm,
};
use sp_std::{prelude::*, convert::TryFrom};
use xcm::{latest::prelude::*, WrapVersion, VersionedXcm};

pub use pallet::*;

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

/// Information on the avaialble XCMP channels.
type ChannelInfo: GetChannelInfo;

/// Means of converting an `Xcm` into a `VersionedXcm`.
type VersionWrapper: WrapVersion;
}

impl Default for QueueConfigData {
Expand Down Expand Up @@ -351,7 +351,7 @@ impl<T: Config> Pallet<T> {
log::debug!("Processing XCMP-XCM: {:?}", &hash);
let (result, event) = match Xcm::<T::Call>::try_from(xcm) {
Ok(xcm) => {
let location = (Junction::Parent, Junction::Parachain(sender.into()));
let location = (Parent, Parachain(sender.into()));
match T::XcmExecutor::execute_xcm(location.into(), xcm, max_weight) {
Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)),
Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))),
Expand Down Expand Up @@ -777,13 +777,14 @@ impl<T: Config> SendXcm for Pallet<T> {
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> Result<(), XcmError> {
match &dest {
// An HRMP message for a sibling parachain.
MultiLocation::X2(Junction::Parent, Junction::Parachain(id)) => {
let msg = VersionedXcm::<()>::from(msg);
let hash = T::Hashing::hash_of(&msg);
X2(Parent, Parachain(id)) => {
let versioned_xcm = T::VersionWrapper::wrap_version(&dest, msg)
.map_err(|()| XcmError::DestinationUnsupported)?;
let hash = T::Hashing::hash_of(&versioned_xcm);
Self::send_fragment(
(*id).into(),
XcmpMessageFormat::ConcatenatedVersionedXcm,
msg,
versioned_xcm,
)
.map_err(|e| XcmError::SendFailed(<&'static str>::from(e)))?;
Self::deposit_event(Event::XcmpMessageSent(Some(hash)));
Expand Down
12 changes: 4 additions & 8 deletions pallets/xcmp-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ use super::*;
use crate as xcmp_queue;
use sp_core::H256;
use frame_support::parameter_types;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
testing::{Header},
};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use xcm_builder::{
FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, CurrencyAdapter,
ParentIsDefault,
Expand Down Expand Up @@ -107,10 +104,8 @@ impl cumulus_pallet_parachain_system::Config for Test {
}

parameter_types! {
pub const RelayChain: MultiLocation = MultiLocation::X1(Junction::Parent);
pub Ancestry: MultiLocation = MultiLocation::X1(
Junction::Parachain(1u32.into())
);
pub const RelayChain: MultiLocation = X1(Parent);
pub Ancestry: MultiLocation = X1(Parachain(1u32.into()));
pub UnitWeightCost: Weight = 1_000_000;
}

Expand Down Expand Up @@ -157,6 +152,7 @@ impl Config for Test {
type Event = Event;
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
type ChannelInfo = ParachainSystem;
type VersionWrapper = ();
}

pub fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
2 changes: 1 addition & 1 deletion polkadot-parachains/pallets/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sp_runtime::traits::Saturating;
use frame_system::Config as SystemConfig;
use cumulus_primitives_core::ParaId;
use cumulus_pallet_xcm::{Origin as CumulusOrigin, ensure_sibling_para};
use xcm::v0::{Xcm, Error as XcmError, SendXcm, OriginKind, MultiLocation, Junction};
use xcm::latest::{Xcm, Error as XcmError, SendXcm, OriginKind, MultiLocation, Junction};

pub use pallet::*;

Expand Down
6 changes: 4 additions & 2 deletions polkadot-parachains/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub use sp_runtime::{Perbill, Permill};
// XCM imports
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
use polkadot_parachain::primitives::Sibling;
use xcm::v0::{BodyId, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId, Xcm};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
Expand Down Expand Up @@ -356,7 +356,7 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RococoNe
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
Expand All @@ -371,6 +371,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type XcmReserveTransferFilter = ();
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
type LocationInverter = LocationInverter<Ancestry>;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand All @@ -382,6 +383,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type ChannelInfo = ParachainSystem;
type VersionWrapper = ();
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion polkadot-parachains/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};

// XCM imports
use xcm::v0::{Junction::*, MultiLocation, MultiLocation::*, NetworkId};
use xcm::latest::prelude::*;
use xcm_builder::{
AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter, ParentAsSuperuser,
ParentIsDefault, SovereignSignedViaLocation,
Expand Down
14 changes: 8 additions & 6 deletions polkadot-parachains/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub use sp_runtime::BuildStorage;
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::{BlockHashCount, RocksDbWeight, SlowAdjustingFeeUpdate};
use xcm::v0::{BodyId, Junction, MultiAsset, MultiLocation, NetworkId, Xcm};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
Expand Down Expand Up @@ -464,10 +464,10 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
pub const KsmLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
pub const KsmLocation: MultiLocation = X1(Parent);
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Junction::Parachain(ParachainInfo::parachain_id().into()).into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}

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

match_type! {
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
MultiLocation::X1(Junction::Parent) |
MultiLocation::X2(Junction::Parent, Junction::Plurality { id: BodyId::Executive, .. })
X1(Parent) |
X2(Parent, Plurality { id: BodyId::Executive, .. })
};
}

Expand Down Expand Up @@ -566,7 +566,7 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNet
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
Expand All @@ -581,6 +581,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
type LocationInverter = LocationInverter<Ancestry>;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand All @@ -592,6 +593,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type ChannelInfo = ParachainSystem;
type VersionWrapper = ();
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
Expand Down
14 changes: 8 additions & 6 deletions polkadot-parachains/statemint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub use sp_runtime::BuildStorage;
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::{BlockHashCount, RocksDbWeight, SlowAdjustingFeeUpdate};
use xcm::v0::{BodyId, Junction, MultiAsset, MultiLocation, NetworkId, Xcm};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
Expand Down Expand Up @@ -432,10 +432,10 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
pub const DotLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
pub const DotLocation: MultiLocation = X1(Parent);
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Junction::Parachain(ParachainInfo::parachain_id().into()).into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}

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

match_type! {
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
MultiLocation::X1(Junction::Parent) |
MultiLocation::X2(Junction::Parent, Junction::Plurality { id: BodyId::Executive, .. })
X1(Parent) |
X2(Parent, Plurality { id: BodyId::Executive, .. })
};
}

Expand Down Expand Up @@ -534,7 +534,7 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNet
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
Expand All @@ -549,6 +549,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
type LocationInverter = LocationInverter<Ancestry>;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand All @@ -560,6 +561,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type ChannelInfo = ParachainSystem;
type VersionWrapper = ();
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
Expand Down
14 changes: 8 additions & 6 deletions polkadot-parachains/westmint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub use sp_runtime::BuildStorage;
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::{BlockHashCount, RocksDbWeight, SlowAdjustingFeeUpdate};
use xcm::v0::{Junction, MultiAsset, MultiLocation, NetworkId, Xcm};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,
Expand Down Expand Up @@ -431,10 +431,10 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
pub const WestendLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
pub const WestendLocation: MultiLocation = X1(Parent);
pub RelayNetwork: NetworkId = NetworkId::Named(b"Westend".to_vec());
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Junction::Parachain(ParachainInfo::parachain_id().into()).into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}

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

match_type! {
pub type ParentOrParentsPlurality: impl Contains<MultiLocation> = {
MultiLocation::X1(Junction::Parent) |
MultiLocation::X2(Junction::Parent, Junction::Plurality { .. })
X1(Parent) |
X2(Parent, Plurality { .. })
};
}

Expand Down Expand Up @@ -532,7 +532,7 @@ pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNet
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
Expand All @@ -547,6 +547,7 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type XcmReserveTransferFilter = All<(MultiLocation, Vec<MultiAsset>)>;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
type LocationInverter = LocationInverter<Ancestry>;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand All @@ -558,6 +559,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type ChannelInfo = ParachainSystem;
type VersionWrapper = ();
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
Expand Down
12 changes: 7 additions & 5 deletions primitives/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use sp_std::marker::PhantomData;
use codec::Encode;
use cumulus_primitives_core::UpwardMessageSender;
use xcm::{VersionedXcm, v0::{Xcm, MultiLocation, Junction, SendXcm, Error as XcmError}};
use xcm::{WrapVersion, latest::prelude::*};

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

T::send_upward_message(data)
.map_err(|e| XcmError::SendFailed(e.into()))?;
Expand Down