Use new MultiLocation syntax everywhere (#570)

* Use new MultiLocation syntax everywhere

* Make tests compile
This commit is contained in:
Keith Yeung
2021-08-12 11:26:49 +02:00
committed by GitHub
parent 02bf5acf6c
commit 906bf97321
13 changed files with 358 additions and 324 deletions
Generated
+319 -285
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -26,7 +26,7 @@ use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use cumulus_primitives_core::DmpMessageHandler; use cumulus_primitives_core::DmpMessageHandler;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use sp_runtime::RuntimeDebug; use sp_runtime::RuntimeDebug;
use xcm::{VersionedXcm, latest::{Xcm, Junction, Outcome, ExecuteXcm, Error as XcmError}}; use xcm::{VersionedXcm, latest::{Xcm, Outcome, Parent, ExecuteXcm, Error as XcmError}};
use frame_support::{traits::EnsureOrigin, dispatch::Weight, weights::constants::WEIGHT_PER_MILLIS}; use frame_support::{traits::EnsureOrigin, dispatch::Weight, weights::constants::WEIGHT_PER_MILLIS};
pub use pallet::*; pub use pallet::*;
@@ -245,7 +245,7 @@ pub mod pallet {
Ok(0) Ok(0)
}, },
Ok(Ok(x)) => { Ok(Ok(x)) => {
let outcome = T::XcmExecutor::execute_xcm(Junction::Parent.into(), x, limit); let outcome = T::XcmExecutor::execute_xcm(Parent.into(), x, limit);
match outcome { match outcome {
Outcome::Error(XcmError::WeightLimitReached(required)) => Err((id, required)), Outcome::Error(XcmError::WeightLimitReached(required)) => Err((id, required)),
outcome => { outcome => {
+3 -3
View File
@@ -25,7 +25,7 @@ use cumulus_primitives_core::{ParaId, DmpMessageHandler};
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber; use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use sp_runtime::traits::BadOrigin; use sp_runtime::traits::BadOrigin;
use xcm::{VersionedXcm, latest::{Xcm, Junction, Outcome, ExecuteXcm}}; use xcm::{VersionedXcm, latest::{Xcm, Outcome, Parent, ExecuteXcm}};
use frame_support::dispatch::Weight; use frame_support::dispatch::Weight;
pub use pallet::*; pub use pallet::*;
@@ -118,7 +118,7 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
Err(_) => Pallet::<T>::deposit_event(Event::InvalidFormat(id)), Err(_) => Pallet::<T>::deposit_event(Event::InvalidFormat(id)),
Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)), Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)),
Ok(Ok(x)) => { Ok(Ok(x)) => {
let outcome = T::XcmExecutor::execute_xcm(Junction::Parent.into(), x, limit); let outcome = T::XcmExecutor::execute_xcm(Parent.into(), x, limit);
used += outcome.weight_used(); used += outcome.weight_used();
Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome)); Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome));
} }
@@ -149,7 +149,7 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)), Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)),
Ok(Ok(x)) => { Ok(Ok(x)) => {
let weight_limit = limit.saturating_sub(used); let weight_limit = limit.saturating_sub(used);
let outcome = T::XcmExecutor::execute_xcm(Junction::Parent.into(), x, weight_limit); let outcome = T::XcmExecutor::execute_xcm(Parent.into(), x, weight_limit);
used += outcome.weight_used(); used += outcome.weight_used();
Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome)); Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome));
} }
+2 -2
View File
@@ -351,7 +351,7 @@ impl<T: Config> Pallet<T> {
log::debug!("Processing XCMP-XCM: {:?}", &hash); log::debug!("Processing XCMP-XCM: {:?}", &hash);
let (result, event) = match Xcm::<T::Call>::try_from(xcm) { let (result, event) = match Xcm::<T::Call>::try_from(xcm) {
Ok(xcm) => { Ok(xcm) => {
let location = (Parent, Parachain(sender.into())); let location = (1, Parachain(sender.into()));
match T::XcmExecutor::execute_xcm(location.into(), xcm, max_weight) { match T::XcmExecutor::execute_xcm(location.into(), xcm, max_weight) {
Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)), Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)),
Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))), Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))),
@@ -777,7 +777,7 @@ impl<T: Config> SendXcm for Pallet<T> {
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> Result<(), XcmError> { fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> Result<(), XcmError> {
match &dest { match &dest {
// An HRMP message for a sibling parachain. // An HRMP message for a sibling parachain.
X2(Parent, Parachain(id)) => { MultiLocation { parents: 1, interior: X1(Parachain(id)) } => {
let versioned_xcm = T::VersionWrapper::wrap_version(&dest, msg) let versioned_xcm = T::VersionWrapper::wrap_version(&dest, msg)
.map_err(|()| XcmError::DestinationUnsupported)?; .map_err(|()| XcmError::DestinationUnsupported)?;
let hash = T::Hashing::hash_of(&versioned_xcm); let hash = T::Hashing::hash_of(&versioned_xcm);
+2 -2
View File
@@ -104,8 +104,8 @@ impl cumulus_pallet_parachain_system::Config for Test {
} }
parameter_types! { parameter_types! {
pub const RelayChain: MultiLocation = X1(Parent); pub const RelayChain: MultiLocation = MultiLocation::parent();
pub Ancestry: MultiLocation = X1(Parachain(1u32.into())); pub Ancestry: MultiLocation = X1(Parachain(1u32.into())).into();
pub UnitWeightCost: Weight = 1_000_000; pub UnitWeightCost: Weight = 1_000_000;
} }
+3 -3
View File
@@ -23,7 +23,7 @@ use sp_runtime::traits::Saturating;
use frame_system::Config as SystemConfig; use frame_system::Config as SystemConfig;
use cumulus_primitives_core::ParaId; use cumulus_primitives_core::ParaId;
use cumulus_pallet_xcm::{Origin as CumulusOrigin, ensure_sibling_para}; use cumulus_pallet_xcm::{Origin as CumulusOrigin, ensure_sibling_para};
use xcm::latest::{Xcm, Error as XcmError, SendXcm, OriginKind, MultiLocation, Junction}; use xcm::latest::{Xcm, Error as XcmError, SendXcm, OriginKind, Junction};
pub use pallet::*; pub use pallet::*;
@@ -101,7 +101,7 @@ pub mod pallet {
for (para, payload) in Targets::<T>::get().into_iter() { for (para, payload) in Targets::<T>::get().into_iter() {
let seq = PingCount::<T>::mutate(|seq| { *seq += 1; *seq }); let seq = PingCount::<T>::mutate(|seq| { *seq += 1; *seq });
match T::XcmSender::send_xcm( match T::XcmSender::send_xcm(
MultiLocation::X2(Junction::Parent, Junction::Parachain(para.into())), (1, Junction::Parachain(para.into())).into(),
Xcm::Transact { Xcm::Transact {
origin_type: OriginKind::Native, origin_type: OriginKind::Native,
require_weight_at_most: 1_000, require_weight_at_most: 1_000,
@@ -163,7 +163,7 @@ pub mod pallet {
Self::deposit_event(Event::Pinged(para, seq, payload.clone())); Self::deposit_event(Event::Pinged(para, seq, payload.clone()));
match T::XcmSender::send_xcm( match T::XcmSender::send_xcm(
MultiLocation::X2(Junction::Parent, Junction::Parachain(para.into())), (1, Junction::Parachain(para.into())).into(),
Xcm::Transact { Xcm::Transact {
origin_type: OriginKind::Native, origin_type: OriginKind::Native,
require_weight_at_most: 1_000, require_weight_at_most: 1_000,
+5 -4
View File
@@ -257,10 +257,10 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {}
parameter_types! { parameter_types! {
pub const RocLocation: MultiLocation = X1(Parent); pub const RocLocation: MultiLocation = MultiLocation::parent();
pub const RococoNetwork: NetworkId = NetworkId::Polkadot; pub const RococoNetwork: NetworkId = NetworkId::Polkadot;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = X1(Parachain(ParachainInfo::parachain_id().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 /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
@@ -317,12 +317,13 @@ parameter_types! {
// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate. // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.
pub UnitWeightCost: Weight = 1_000_000; pub UnitWeightCost: Weight = 1_000_000;
// One ROC buys 1 second of weight. // One ROC buys 1 second of weight.
pub const WeightPrice: (MultiLocation, u128) = (X1(Parent), ROC); pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), ROC);
} }
match_type! { match_type! {
pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = { pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {
X1(Parent) | X2(Parent, Plurality { id: BodyId::Unit, .. }) MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }
}; };
} }
+2 -2
View File
@@ -172,7 +172,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
impl parachain_info::Config for Runtime {} impl parachain_info::Config for Runtime {}
parameter_types! { parameter_types! {
pub const RococoLocation: MultiLocation = X1(Parent); pub const RococoLocation: MultiLocation = MultiLocation::parent();
pub const RococoNetwork: NetworkId = NetworkId::Polkadot; pub const RococoNetwork: NetworkId = NetworkId::Polkadot;
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
} }
@@ -191,7 +191,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
); );
match_type! { match_type! {
pub type JustTheParent: impl Contains<MultiLocation> = { X1(Parent) }; pub type JustTheParent: impl Contains<MultiLocation> = { MultiLocation { parents:1, interior: Here } };
} }
parameter_types! { parameter_types! {
+3 -3
View File
@@ -464,7 +464,7 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {}
parameter_types! { parameter_types! {
pub const KsmLocation: MultiLocation = X1(Parent); pub const KsmLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
@@ -527,8 +527,8 @@ parameter_types! {
match_type! { match_type! {
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = { pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
X1(Parent) | MultiLocation { parents: 1, interior: Here } |
X2(Parent, Plurality { id: BodyId::Executive, .. }) MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
}; };
} }
+3 -3
View File
@@ -432,7 +432,7 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {}
parameter_types! { parameter_types! {
pub const DotLocation: MultiLocation = X1(Parent); pub const DotLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: NetworkId = NetworkId::Polkadot; pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
@@ -495,8 +495,8 @@ parameter_types! {
match_type! { match_type! {
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = { pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
X1(Parent) | MultiLocation { parents: 1, interior: Here } |
X2(Parent, Plurality { id: BodyId::Executive, .. }) MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
}; };
} }
+3 -3
View File
@@ -431,7 +431,7 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {}
parameter_types! { parameter_types! {
pub const WestendLocation: MultiLocation = X1(Parent); pub const WestendLocation: MultiLocation = MultiLocation::parent();
pub RelayNetwork: NetworkId = NetworkId::Named(b"Westend".to_vec()); pub RelayNetwork: NetworkId = NetworkId::Named(b"Westend".to_vec());
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
@@ -493,8 +493,8 @@ parameter_types! {
match_type! { match_type! {
pub type ParentOrParentsPlurality: impl Contains<MultiLocation> = { pub type ParentOrParentsPlurality: impl Contains<MultiLocation> = {
X1(Parent) | MultiLocation { parents: 1, interior: Here } |
X2(Parent, Plurality { .. }) MultiLocation { parents: 1, interior: X1(Plurality { .. }) }
}; };
} }
+9 -10
View File
@@ -34,20 +34,19 @@ use xcm::{WrapVersion, latest::prelude::*};
pub struct ParentAsUmp<T, W>(PhantomData<(T, W)>); pub struct ParentAsUmp<T, W>(PhantomData<(T, W)>);
impl<T: UpwardMessageSender, W: WrapVersion> SendXcm for ParentAsUmp<T, W> { impl<T: UpwardMessageSender, W: WrapVersion> SendXcm for ParentAsUmp<T, W> {
fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> Result<(), XcmError> { fn send_xcm(dest: MultiLocation, msg: Xcm<()>) -> Result<(), XcmError> {
match &dest { if dest.contains_parents_only(1) {
// An upward message for the relay chain. // An upward message for the relay chain.
X1(Parent) => { let versioned_xcm = W::wrap_version(&dest, msg)
let versioned_xcm = W::wrap_version(&dest, msg) .map_err(|()| XcmError::DestinationUnsupported)?;
.map_err(|()| XcmError::DestinationUnsupported)?; let data = versioned_xcm.encode();
let data = versioned_xcm.encode();
T::send_upward_message(data) T::send_upward_message(data)
.map_err(|e| XcmError::SendFailed(e.into()))?; .map_err(|e| XcmError::SendFailed(e.into()))?;
Ok(()) Ok(())
} } else {
// Anything else is unhandled. This includes a message this is meant for us. // Anything else is unhandled. This includes a message this is meant for us.
_ => Err(XcmError::CannotReachDestination(dest, msg)), Err(XcmError::CannotReachDestination(dest, msg))
} }
} }
} }
+2 -2
View File
@@ -36,7 +36,7 @@ pub use sc_executor::NativeExecutor;
use sc_network::{config::TransportConfig, multiaddr, NetworkService}; use sc_network::{config::TransportConfig, multiaddr, NetworkService};
use sc_service::{ use sc_service::{
config::{ config::{
DatabaseConfig, KeepBlocks, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration, DatabaseSource, KeepBlocks, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration,
OffchainWorkerConfig, PruningMode, TransactionStorageMode, WasmExecutionMethod, OffchainWorkerConfig, PruningMode, TransactionStorageMode, WasmExecutionMethod,
}, },
BasePath, ChainSpec, Configuration, Error as ServiceError, PartialComponents, Role, BasePath, ChainSpec, Configuration, Error as ServiceError, PartialComponents, Role,
@@ -600,7 +600,7 @@ pub fn node_config(
network: network_config, network: network_config,
keystore: KeystoreConfig::InMemory, keystore: KeystoreConfig::InMemory,
keystore_remote: Default::default(), keystore_remote: Default::default(),
database: DatabaseConfig::RocksDb { database: DatabaseSource::RocksDb {
path: root.join("db"), path: root.join("db"),
cache_size: 128, cache_size: 128,
}, },