Unverified Commit 71cc1b22 authored by thiolliere's avatar thiolliere Committed by GitHub
Browse files

change junction parachain id from named field to unnamed field (#2940)

* use unnamed field for parachain variant in junction

* remove outdated comment
parent 627b47d6
Pipeline #135936 failed with stages
in 28 minutes and 34 seconds
...@@ -27,7 +27,7 @@ pub struct ChildParachainRouter<T>(PhantomData<T>); ...@@ -27,7 +27,7 @@ pub struct ChildParachainRouter<T>(PhantomData<T>);
impl<T: configuration::Config + dmp::Config> SendXcm for ChildParachainRouter<T> { impl<T: configuration::Config + dmp::Config> SendXcm for ChildParachainRouter<T> {
fn send_xcm(dest: MultiLocation, msg: Xcm) -> Result { fn send_xcm(dest: MultiLocation, msg: Xcm) -> Result {
match dest { match dest {
MultiLocation::X1(Junction::Parachain { id }) => { MultiLocation::X1(Junction::Parachain(id)) => {
// Downward message passing. // Downward message passing.
let config = <configuration::Module<T>>::config(); let config = <configuration::Module<T>>::config();
<dmp::Module<T>>::queue_downward_message( <dmp::Module<T>>::queue_downward_message(
......
...@@ -69,7 +69,7 @@ impl<XcmExecutor: xcm::v0::ExecuteXcm<Call>, Call> UmpSink for XcmSink<XcmExecut ...@@ -69,7 +69,7 @@ impl<XcmExecutor: xcm::v0::ExecuteXcm<Call>, Call> UmpSink for XcmSink<XcmExecut
if let Ok(versioned_xcm_message) = VersionedXcm::decode(&mut msg) { if let Ok(versioned_xcm_message) = VersionedXcm::decode(&mut msg) {
match versioned_xcm_message { match versioned_xcm_message {
VersionedXcm::V0(xcm_message) => { VersionedXcm::V0(xcm_message) => {
let xcm_junction: Junction = Junction::Parachain { id: origin.into() }; let xcm_junction: Junction = Junction::Parachain(origin.into());
let xcm_location: MultiLocation = xcm_junction.into(); let xcm_location: MultiLocation = xcm_junction.into();
match XcmExecutor::execute_xcm(xcm_location, xcm_message, max_weight) { match XcmExecutor::execute_xcm(xcm_location, xcm_message, max_weight) {
Outcome::Complete(w) | Outcome::Incomplete(w, _) => Some(w), Outcome::Complete(w) | Outcome::Incomplete(w, _) => Some(w),
......
...@@ -603,13 +603,13 @@ pub type XcmRouter = ( ...@@ -603,13 +603,13 @@ pub type XcmRouter = (
use xcm::v0::{MultiAsset, MultiAsset::AllConcreteFungible, MultiLocation::{Null, X1}, Junction::Parachain}; use xcm::v0::{MultiAsset, MultiAsset::AllConcreteFungible, MultiLocation::{Null, X1}, Junction::Parachain};
parameter_types! { parameter_types! {
pub const RococoForTick: (MultiAsset, MultiLocation) = pub const RococoForTick: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain{id: 100})); (AllConcreteFungible { id: Null }, X1(Parachain(100)));
pub const RococoForTrick: (MultiAsset, MultiLocation) = pub const RococoForTrick: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain{id: 110})); (AllConcreteFungible { id: Null }, X1(Parachain(110)));
pub const RococoForTrack: (MultiAsset, MultiLocation) = pub const RococoForTrack: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain{id: 120})); (AllConcreteFungible { id: Null }, X1(Parachain(120)));
pub const RococoForStatemint: (MultiAsset, MultiLocation) = pub const RococoForStatemint: (MultiAsset, MultiLocation) =
(AllConcreteFungible { id: Null }, X1(Parachain{id: 1})); (AllConcreteFungible { id: Null }, X1(Parachain(1)));
} }
pub type TrustedTeleporters = ( pub type TrustedTeleporters = (
xcm_builder::Case<RococoForTick>, xcm_builder::Case<RococoForTick>,
...@@ -621,10 +621,10 @@ pub type TrustedTeleporters = ( ...@@ -621,10 +621,10 @@ pub type TrustedTeleporters = (
parameter_types! { parameter_types! {
pub AllowUnpaidFrom: Vec<MultiLocation> = pub AllowUnpaidFrom: Vec<MultiLocation> =
vec![ vec![
X1(Parachain{id: 100}), X1(Parachain(100)),
X1(Parachain{id: 110}), X1(Parachain(110)),
X1(Parachain{id: 120}), X1(Parachain(120)),
X1(Parachain{id: 1}) X1(Parachain(1))
]; ];
} }
......
...@@ -94,11 +94,7 @@ pub enum Junction { ...@@ -94,11 +94,7 @@ pub enum Junction {
/// An indexed parachain belonging to and operated by the context. /// An indexed parachain belonging to and operated by the context.
/// ///
/// Generally used when the context is a Polkadot Relay-chain. /// Generally used when the context is a Polkadot Relay-chain.
/// Parachain(#[codec(compact)] u32),
/// There is also `Parachain` which can be used in tests to avoid the faffy `{ id: ... }` syntax. Production
/// code should use this.
// TODO: parity-scale-codec#262: Change to be `Parachain(#[codec(compact)] u32)`
Parachain { #[codec(compact)] id: u32 },
/// A 32-byte identifier for an account of a specific network that is respected as a sovereign endpoint within /// A 32-byte identifier for an account of a specific network that is respected as a sovereign endpoint within
/// the context. /// the context.
/// ///
...@@ -148,7 +144,7 @@ impl Junction { ...@@ -148,7 +144,7 @@ impl Junction {
match self { match self {
Junction::Parent => false, Junction::Parent => false,
Junction::Parachain { .. } Junction::Parachain(..)
| Junction::AccountId32 { .. } | Junction::AccountId32 { .. }
| Junction::AccountIndex64 { .. } | Junction::AccountIndex64 { .. }
| Junction::AccountKey20 { .. } | Junction::AccountKey20 { .. }
......
...@@ -64,7 +64,7 @@ impl< ...@@ -64,7 +64,7 @@ impl<
AccountId: Clone, AccountId: Clone,
> Convert<MultiLocation, AccountId> for ChildParachainConvertsVia<ParaId, AccountId> { > Convert<MultiLocation, AccountId> for ChildParachainConvertsVia<ParaId, AccountId> {
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> { fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
if let &MultiLocation::X1(Junction::Parachain { id }) = location.borrow() { if let &MultiLocation::X1(Junction::Parachain(id)) = location.borrow() {
Ok(ParaId::from(id).into_account()) Ok(ParaId::from(id).into_account())
} else { } else {
Err(()) Err(())
...@@ -73,7 +73,7 @@ impl< ...@@ -73,7 +73,7 @@ impl<
fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> { fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
if let Some(id) = ParaId::try_from_account(who.borrow()) { if let Some(id) = ParaId::try_from_account(who.borrow()) {
Ok(Junction::Parachain { id: id.into() }.into()) Ok(Junction::Parachain(id.into()).into())
} else { } else {
Err(()) Err(())
} }
...@@ -87,7 +87,7 @@ impl< ...@@ -87,7 +87,7 @@ impl<
AccountId: Clone, AccountId: Clone,
> Convert<MultiLocation, AccountId> for SiblingParachainConvertsVia<ParaId, AccountId> { > Convert<MultiLocation, AccountId> for SiblingParachainConvertsVia<ParaId, AccountId> {
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> { fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
if let &MultiLocation::X2(Junction::Parent, Junction::Parachain { id }) = location.borrow() { if let &MultiLocation::X2(Junction::Parent, Junction::Parachain(id)) = location.borrow() {
Ok(ParaId::from(id).into_account()) Ok(ParaId::from(id).into_account())
} else { } else {
Err(()) Err(())
...@@ -96,7 +96,7 @@ impl< ...@@ -96,7 +96,7 @@ impl<
fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> { fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
if let Some(id) = ParaId::try_from_account(who.borrow()) { if let Some(id) = ParaId::try_from_account(who.borrow()) {
Ok([Junction::Parent, Junction::Parachain { id: id.into() }].into()) Ok([Junction::Parent, Junction::Parachain(id.into())].into())
} else { } else {
Err(()) Err(())
} }
......
...@@ -144,11 +144,11 @@ impl TransactAsset for TestAssetTransactor { ...@@ -144,11 +144,11 @@ impl TransactAsset for TestAssetTransactor {
pub fn to_account(l: MultiLocation) -> Result<u64, MultiLocation> { pub fn to_account(l: MultiLocation) -> Result<u64, MultiLocation> {
Ok(match l { Ok(match l {
// Siblings at 2000+id // Siblings at 2000+id
X2(Parent, Parachain { id }) => 2000 + id as u64, X2(Parent, Parachain(id)) => 2000 + id as u64,
// Accounts are their number // Accounts are their number
X1(AccountIndex64 { index, .. }) => index, X1(AccountIndex64 { index, .. }) => index,
// Children at 1000+id // Children at 1000+id
X1(Parachain { id }) => 1000 + id as u64, X1(Parachain(id)) => 1000 + id as u64,
// Self at 3000 // Self at 3000
Null => 3000, Null => 3000,
// Parent at 3000 // Parent at 3000
...@@ -160,11 +160,11 @@ pub fn to_account(l: MultiLocation) -> Result<u64, MultiLocation> { ...@@ -160,11 +160,11 @@ pub fn to_account(l: MultiLocation) -> Result<u64, MultiLocation> {
pub struct TestOriginConverter; pub struct TestOriginConverter;
impl ConvertOrigin<TestOrigin> for TestOriginConverter { impl ConvertOrigin<TestOrigin> for TestOriginConverter {
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<TestOrigin, MultiLocation> { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<TestOrigin, MultiLocation> {
use {OriginKind::*}; use OriginKind::*;
match (kind, origin) { match (kind, origin) {
(Superuser, _) => Ok(TestOrigin::Root), (Superuser, _) => Ok(TestOrigin::Root),
(SovereignAccount, l) => Ok(TestOrigin::Signed(to_account(l)?)), (SovereignAccount, l) => Ok(TestOrigin::Signed(to_account(l)?)),
(Native, X1(Parachain { id })) => Ok(TestOrigin::Parachain(id)), (Native, X1(Parachain(id))) => Ok(TestOrigin::Parachain(id)),
(Native, X1(Parent)) => Ok(TestOrigin::Relay), (Native, X1(Parent)) => Ok(TestOrigin::Relay),
(Native, X1(AccountIndex64 {index, ..})) => Ok(TestOrigin::Signed(index)), (Native, X1(AccountIndex64 {index, ..})) => Ok(TestOrigin::Signed(index)),
(_, origin) => Err(origin), (_, origin) => Err(origin),
...@@ -243,7 +243,7 @@ pub fn response(query_id: u64) -> Option<Response> { ...@@ -243,7 +243,7 @@ pub fn response(query_id: u64) -> Option<Response> {
} }
parameter_types! { parameter_types! {
pub TestAncestry: MultiLocation = X1(Parachain{id: 42}); pub TestAncestry: MultiLocation = X1(Parachain(42));
pub UnitWeightCost: Weight = 10; pub UnitWeightCost: Weight = 10;
} }
parameter_types! { parameter_types! {
......
...@@ -60,7 +60,7 @@ impl< ...@@ -60,7 +60,7 @@ impl<
> ConvertOrigin<Origin> for ChildSystemParachainAsSuperuser<ParaId, Origin> { > ConvertOrigin<Origin> for ChildSystemParachainAsSuperuser<ParaId, Origin> {
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
match (kind, origin) { match (kind, origin) {
(OriginKind::Superuser, MultiLocation::X1(Junction::Parachain { id })) (OriginKind::Superuser, MultiLocation::X1(Junction::Parachain(id)))
if ParaId::from(id).is_system() => if ParaId::from(id).is_system() =>
Ok(Origin::root()), Ok(Origin::root()),
(_, origin) => Err(origin), (_, origin) => Err(origin),
...@@ -75,7 +75,7 @@ impl< ...@@ -75,7 +75,7 @@ impl<
> ConvertOrigin<Origin> for SiblingSystemParachainAsSuperuser<ParaId, Origin> { > ConvertOrigin<Origin> for SiblingSystemParachainAsSuperuser<ParaId, Origin> {
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
match (kind, origin) { match (kind, origin) {
(OriginKind::Superuser, MultiLocation::X2(Junction::Parent, Junction::Parachain { id })) (OriginKind::Superuser, MultiLocation::X2(Junction::Parent, Junction::Parachain(id)))
if ParaId::from(id).is_system() => if ParaId::from(id).is_system() =>
Ok(Origin::root()), Ok(Origin::root()),
(_, origin) => Err(origin), (_, origin) => Err(origin),
...@@ -92,7 +92,7 @@ impl< ...@@ -92,7 +92,7 @@ impl<
> ConvertOrigin<Origin> for ChildParachainAsNative<ParachainOrigin, Origin> { > ConvertOrigin<Origin> for ChildParachainAsNative<ParachainOrigin, Origin> {
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
match (kind, origin) { match (kind, origin) {
(OriginKind::Native, MultiLocation::X1(Junction::Parachain { id })) (OriginKind::Native, MultiLocation::X1(Junction::Parachain(id)))
=> Ok(Origin::from(ParachainOrigin::from(id))), => Ok(Origin::from(ParachainOrigin::from(id))),
(_, origin) => Err(origin), (_, origin) => Err(origin),
} }
...@@ -108,7 +108,7 @@ impl< ...@@ -108,7 +108,7 @@ impl<
> ConvertOrigin<Origin> for SiblingParachainAsNative<ParachainOrigin, Origin> { > ConvertOrigin<Origin> for SiblingParachainAsNative<ParachainOrigin, Origin> {
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> { fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
match (kind, origin) { match (kind, origin) {
(OriginKind::Native, MultiLocation::X2(Junction::Parent, Junction::Parachain { id })) (OriginKind::Native, MultiLocation::X2(Junction::Parent, Junction::Parachain(id)))
=> Ok(Origin::from(ParachainOrigin::from(id))), => Ok(Origin::from(ParachainOrigin::from(id))),
(_, origin) => Err(origin), (_, origin) => Err(origin),
} }
......
...@@ -28,10 +28,10 @@ fn basic_setup_works() { ...@@ -28,10 +28,10 @@ fn basic_setup_works() {
&X1(Parent), &X1(Parent),
)); ));
assert_eq!(to_account(X1(Parachain{id:1})), Ok(1001)); assert_eq!(to_account(X1(Parachain(1))), Ok(1001));
assert_eq!(to_account(X1(Parachain{id:50})), Ok(1050)); assert_eq!(to_account(X1(Parachain(50))), Ok(1050));
assert_eq!(to_account(X2(Parent, Parachain{id:1})), Ok(2001)); assert_eq!(to_account(X2(Parent, Parachain(1))), Ok(2001));
assert_eq!(to_account(X2(Parent, Parachain{id:50})), Ok(2050)); assert_eq!(to_account(X2(Parent, Parachain(50))), Ok(2050));
assert_eq!(to_account(X1(AccountIndex64{index:1, network:Any})), Ok(1)); assert_eq!(to_account(X1(AccountIndex64{index:1, network:Any})), Ok(1));
assert_eq!(to_account(X1(AccountIndex64{index:42, network:Any})), Ok(42)); assert_eq!(to_account(X1(AccountIndex64{index:42, network:Any})), Ok(42));
assert_eq!(to_account(Null), Ok(3000)); assert_eq!(to_account(Null), Ok(3000));
...@@ -88,7 +88,7 @@ fn allow_unpaid_should_work() { ...@@ -88,7 +88,7 @@ fn allow_unpaid_should_work() {
AllowUnpaidFrom::set(vec![ X1(Parent) ]); AllowUnpaidFrom::set(vec![ X1(Parent) ]);
let r = AllowUnpaidExecutionFrom::<IsInVec<AllowUnpaidFrom>>::should_execute( let r = AllowUnpaidExecutionFrom::<IsInVec<AllowUnpaidFrom>>::should_execute(
&X1(Parachain { id: 1 }), &X1(Parachain(1)),
true, true,
&mut message, &mut message,
10, 10,
...@@ -116,7 +116,7 @@ fn allow_paid_should_work() { ...@@ -116,7 +116,7 @@ fn allow_paid_should_work() {
}; };
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute( let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&X1(Parachain { id: 1 }), &X1(Parachain(1)),
true, true,
&mut message, &mut message,
10, 10,
...@@ -150,7 +150,7 @@ fn allow_paid_should_work() { ...@@ -150,7 +150,7 @@ fn allow_paid_should_work() {
}; };
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute( let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&X1(Parachain { id: 1 }), &X1(Parachain(1)),
true, true,
&mut paying_message, &mut paying_message,
30, 30,
...@@ -191,12 +191,12 @@ fn paying_reserve_deposit_should_work() { ...@@ -191,12 +191,12 @@ fn paying_reserve_deposit_should_work() {
#[test] #[test]
fn transfer_should_work() { fn transfer_should_work() {
// we'll let them have message execution for free. // we'll let them have message execution for free.
AllowUnpaidFrom::set(vec![ X1(Parachain{id:1}) ]); AllowUnpaidFrom::set(vec![ X1(Parachain(1)) ]);
// Child parachain #1 owns 1000 tokens held by us in reserve. // Child parachain #1 owns 1000 tokens held by us in reserve.
add_asset(1001, ConcreteFungible { id: Null, amount: 1000 }); add_asset(1001, ConcreteFungible { id: Null, amount: 1000 });
// They want to transfer 100 of them to their sibling parachain #2 // They want to transfer 100 of them to their sibling parachain #2
let r = XcmExecutor::<TestConfig>::execute_xcm( let r = XcmExecutor::<TestConfig>::execute_xcm(
X1(Parachain{id:1}), X1(Parachain(1)),
Xcm::TransferAsset { Xcm::TransferAsset {
assets: vec![ ConcreteFungible { id: Null, amount: 100 } ], assets: vec![ ConcreteFungible { id: Null, amount: 100 } ],
dest: X1(AccountIndex64{index:3, network:Any}), dest: X1(AccountIndex64{index:3, network:Any}),
...@@ -211,7 +211,7 @@ fn transfer_should_work() { ...@@ -211,7 +211,7 @@ fn transfer_should_work() {
#[test] #[test]
fn reserve_transfer_should_work() { fn reserve_transfer_should_work() {
AllowUnpaidFrom::set(vec![ X1(Parachain{id:1}) ]); AllowUnpaidFrom::set(vec![ X1(Parachain(1)) ]);
// Child parachain #1 owns 1000 tokens held by us in reserve. // Child parachain #1 owns 1000 tokens held by us in reserve.
add_asset(1001, ConcreteFungible { id: Null, amount: 1000 }); add_asset(1001, ConcreteFungible { id: Null, amount: 1000 });
// The remote account owned by gav. // The remote account owned by gav.
...@@ -220,10 +220,10 @@ fn reserve_transfer_should_work() { ...@@ -220,10 +220,10 @@ fn reserve_transfer_should_work() {
// They want to transfer 100 of our native asset from sovereign account of parachain #1 into #2 // They want to transfer 100 of our native asset from sovereign account of parachain #1 into #2
// and let them know to hand it to account #3. // and let them know to hand it to account #3.
let r = XcmExecutor::<TestConfig>::execute_xcm( let r = XcmExecutor::<TestConfig>::execute_xcm(
X1(Parachain{id:1}), X1(Parachain(1)),
Xcm::TransferReserveAsset { Xcm::TransferReserveAsset {
assets: vec![ ConcreteFungible { id: Null, amount: 100 } ], assets: vec![ ConcreteFungible { id: Null, amount: 100 } ],
dest: X1(Parachain{id:2}), dest: X1(Parachain(2)),
effects: vec![ Order::DepositAsset { assets: vec![ All ], dest: three.clone() } ], effects: vec![ Order::DepositAsset { assets: vec![ All ], dest: three.clone() } ],
}, },
50, 50,
...@@ -232,7 +232,7 @@ fn reserve_transfer_should_work() { ...@@ -232,7 +232,7 @@ fn reserve_transfer_should_work() {
assert_eq!(assets(1002), vec![ ConcreteFungible { id: Null, amount: 100 } ]); assert_eq!(assets(1002), vec![ ConcreteFungible { id: Null, amount: 100 } ]);
assert_eq!(sent_xcm(), vec![( assert_eq!(sent_xcm(), vec![(
X1(Parachain { id: 2 }), X1(Parachain(2)),
Xcm::ReserveAssetDeposit { Xcm::ReserveAssetDeposit {
assets: vec![ ConcreteFungible { id: X1(Parent), amount: 100 } ], assets: vec![ ConcreteFungible { id: X1(Parent), amount: 100 } ],
effects: vec![ Order::DepositAsset { assets: vec![ All ], dest: three } ], effects: vec![ Order::DepositAsset { assets: vec![ All ], dest: three } ],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment