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>
This commit is contained in:
Gavin Wood
2021-08-06 21:13:33 +02:00
committed by Bastian Köcher
parent fd80849dde
commit e36689ffc8
12 changed files with 225 additions and 207 deletions
+3 -3
View File
@@ -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::*;
@@ -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
+1 -1
View File
@@ -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::*;
+11 -10
View File
@@ -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::*;
@@ -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 {
@@ -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))),
@@ -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)));
+4 -8
View File
@@ -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,
@@ -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;
}
@@ -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 {