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

Commit

Permalink
Use new MultiLocation syntax everywhere (#570)
Browse files Browse the repository at this point in the history
* Use new MultiLocation syntax everywhere

* Make tests compile
  • Loading branch information
KiChjang authored Aug 12, 2021
1 parent 02bf5ac commit 906bf97
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 324 deletions.
604 changes: 319 additions & 285 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 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, 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};
pub use pallet::*;

Expand Down Expand Up @@ -245,7 +245,7 @@ pub mod pallet {
Ok(0)
},
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 {
Outcome::Error(XcmError::WeightLimitReached(required)) => Err((id, required)),
outcome => {
Expand Down
6 changes: 3 additions & 3 deletions 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, latest::{Xcm, Junction, Outcome, ExecuteXcm}};
use xcm::{VersionedXcm, latest::{Xcm, Outcome, Parent, ExecuteXcm}};
use frame_support::dispatch::Weight;
pub use pallet::*;

Expand Down Expand Up @@ -118,7 +118,7 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
Err(_) => Pallet::<T>::deposit_event(Event::InvalidFormat(id)),
Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)),
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();
Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome));
}
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)),
Ok(Ok(x)) => {
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();
Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome));
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
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 = (Parent, Parachain(sender.into()));
let location = (1, 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,7 +777,7 @@ 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.
X2(Parent, Parachain(id)) => {
MultiLocation { parents: 1, interior: X1(Parachain(id)) } => {
let versioned_xcm = T::VersionWrapper::wrap_version(&dest, msg)
.map_err(|()| XcmError::DestinationUnsupported)?;
let hash = T::Hashing::hash_of(&versioned_xcm);
Expand Down
4 changes: 2 additions & 2 deletions pallets/xcmp-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ impl cumulus_pallet_parachain_system::Config for Test {
}

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

Expand Down
6 changes: 3 additions & 3 deletions 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::latest::{Xcm, Error as XcmError, SendXcm, OriginKind, MultiLocation, Junction};
use xcm::latest::{Xcm, Error as XcmError, SendXcm, OriginKind, Junction};

pub use pallet::*;

Expand Down Expand Up @@ -101,7 +101,7 @@ pub mod pallet {
for (para, payload) in Targets::<T>::get().into_iter() {
let seq = PingCount::<T>::mutate(|seq| { *seq += 1; *seq });
match T::XcmSender::send_xcm(
MultiLocation::X2(Junction::Parent, Junction::Parachain(para.into())),
(1, Junction::Parachain(para.into())).into(),
Xcm::Transact {
origin_type: OriginKind::Native,
require_weight_at_most: 1_000,
Expand Down Expand Up @@ -163,7 +163,7 @@ pub mod pallet {

Self::deposit_event(Event::Pinged(para, seq, payload.clone()));
match T::XcmSender::send_xcm(
MultiLocation::X2(Junction::Parent, Junction::Parachain(para.into())),
(1, Junction::Parachain(para.into())).into(),
Xcm::Transact {
origin_type: OriginKind::Native,
require_weight_at_most: 1_000,
Expand Down
9 changes: 5 additions & 4 deletions polkadot-parachains/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
pub const RocLocation: MultiLocation = X1(Parent);
pub const RocLocation: MultiLocation = MultiLocation::parent();
pub const RococoNetwork: NetworkId = NetworkId::Polkadot;
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
Expand Down Expand Up @@ -317,12 +317,13 @@ parameter_types! {
// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.
pub UnitWeightCost: Weight = 1_000_000;
// 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! {
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, .. }) }
};
}

Expand Down
4 changes: 2 additions & 2 deletions polkadot-parachains/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
impl parachain_info::Config for Runtime {}

parameter_types! {
pub const RococoLocation: MultiLocation = X1(Parent);
pub const RococoLocation: MultiLocation = MultiLocation::parent();
pub const RococoNetwork: NetworkId = NetworkId::Polkadot;
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}
Expand All @@ -191,7 +191,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
);

match_type! {
pub type JustTheParent: impl Contains<MultiLocation> = { X1(Parent) };
pub type JustTheParent: impl Contains<MultiLocation> = { MultiLocation { parents:1, interior: Here } };
}

parameter_types! {
Expand Down
6 changes: 3 additions & 3 deletions polkadot-parachains/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
pub const KsmLocation: MultiLocation = X1(Parent);
pub const KsmLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
Expand Down Expand Up @@ -527,8 +527,8 @@ parameter_types! {

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

Expand Down
6 changes: 3 additions & 3 deletions polkadot-parachains/statemint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
pub const DotLocation: MultiLocation = X1(Parent);
pub const DotLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
Expand Down Expand Up @@ -495,8 +495,8 @@ parameter_types! {

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

Expand Down
6 changes: 3 additions & 3 deletions polkadot-parachains/westmint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl parachain_info::Config for Runtime {}
impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
pub const WestendLocation: MultiLocation = X1(Parent);
pub const WestendLocation: MultiLocation = MultiLocation::parent();
pub RelayNetwork: NetworkId = NetworkId::Named(b"Westend".to_vec());
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
Expand Down Expand Up @@ -493,8 +493,8 @@ parameter_types! {

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

Expand Down
19 changes: 9 additions & 10 deletions primitives/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ use xcm::{WrapVersion, latest::prelude::*};
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 {
if dest.contains_parents_only(1) {
// An upward message for the relay chain.
X1(Parent) => {
let versioned_xcm = W::wrap_version(&dest, msg)
.map_err(|()| XcmError::DestinationUnsupported)?;
let data = versioned_xcm.encode();
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()))?;
T::send_upward_message(data)
.map_err(|e| XcmError::SendFailed(e.into()))?;

Ok(())
}
Ok(())
} else {
// Anything else is unhandled. This includes a message this is meant for us.
_ => Err(XcmError::CannotReachDestination(dest, msg)),
Err(XcmError::CannotReachDestination(dest, msg))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use sc_executor::NativeExecutor;
use sc_network::{config::TransportConfig, multiaddr, NetworkService};
use sc_service::{
config::{
DatabaseConfig, KeepBlocks, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration,
DatabaseSource, KeepBlocks, KeystoreConfig, MultiaddrWithPeerId, NetworkConfiguration,
OffchainWorkerConfig, PruningMode, TransactionStorageMode, WasmExecutionMethod,
},
BasePath, ChainSpec, Configuration, Error as ServiceError, PartialComponents, Role,
Expand Down Expand Up @@ -600,7 +600,7 @@ pub fn node_config(
network: network_config,
keystore: KeystoreConfig::InMemory,
keystore_remote: Default::default(),
database: DatabaseConfig::RocksDb {
database: DatabaseSource::RocksDb {
path: root.join("db"),
cache_size: 128,
},
Expand Down

0 comments on commit 906bf97

Please sign in to comment.