From 64ecfc595eff547d20e956d5744117573e6263f7 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 06 Sep 2022 12:48:22 +0000 Subject: [PATCH] refactor: rename local xcm_config to xcm_barrier --- --- a/runtime/common/config/xcm/mod.rs +++ b/runtime/common/config/xcm/mod.rs @@ -33,7 +33,7 @@ use sp_std::{marker::PhantomData, vec::Vec}; use crate::{ Runtime, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue, - xcm_config::Barrier, + xcm_barrier::Barrier, }; use up_common::types::AccountId; --- a/runtime/opal/src/lib.rs +++ b/runtime/opal/src/lib.rs @@ -35,7 +35,7 @@ #[path = "../../common/mod.rs"] mod runtime_common; -pub mod xcm_config; +pub mod xcm_barrier; #[cfg(test)] mod tests; --- a/runtime/opal/src/tests/xcm.rs +++ b/runtime/opal/src/tests/xcm.rs @@ -15,7 +15,7 @@ // along with Unique Network. If not, see . use logtest::Logger; -use crate::{runtime_common::tests::xcm::*, xcm_config::Barrier}; +use crate::{runtime_common::tests::xcm::*, xcm_barrier::Barrier}; const OPAL_PARA_ID: u32 = 2095; // Same as Quartz --- /dev/null +++ b/runtime/opal/src/xcm_barrier.rs @@ -0,0 +1,63 @@ +// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. +// This file is part of Unique Network. + +// Unique Network is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Unique Network is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Unique Network. If not, see . + +use frame_support::{ + {match_types, weights::Weight}, + traits::Everything, +}; +use xcm::{ + latest::Xcm, + v1::{BodyId, Junction::*, Junctions::*, MultiLocation}, +}; +use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit}; +use xcm_executor::traits::ShouldExecute; + +use crate::runtime_common::config::xcm::{DenyThenTry, DenyTransact}; + +match_types! { + pub type ParentOrParentsUnitPlurality: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) } + }; +} + +/// Execution barrier that just takes `max_weight` from `weight_credit`. +/// +/// Useful to allow XCM execution by local chain users via extrinsics. +/// E.g. `pallet_xcm::reserve_asset_transfer` to transfer a reserve asset +/// out of the local chain to another one. +pub struct AllowAllDebug; +impl ShouldExecute for AllowAllDebug { + fn should_execute( + _origin: &MultiLocation, + _message: &mut Xcm, + _max_weight: Weight, + _weight_credit: &mut Weight, + ) -> Result<(), ()> { + Ok(()) + } +} + +pub type Barrier = DenyThenTry< + DenyTransact, + ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + AllowUnpaidExecutionFrom, + // ^^^ Parent & its unit plurality gets free execution + AllowAllDebug, + ), +>; --- a/runtime/opal/src/xcm_config.rs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. -// This file is part of Unique Network. - -// Unique Network is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Unique Network is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Unique Network. If not, see . - -use frame_support::{ - {match_types, weights::Weight}, - traits::Everything, -}; -use xcm::{ - latest::Xcm, - v1::{BodyId, Junction::*, Junctions::*, MultiLocation}, -}; -use xcm_builder::{AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, TakeWeightCredit}; -use xcm_executor::traits::ShouldExecute; - -use crate::runtime_common::config::xcm::{DenyThenTry, DenyTransact}; - -match_types! { - pub type ParentOrParentsUnitPlurality: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) } - }; -} - -/// Execution barrier that just takes `max_weight` from `weight_credit`. -/// -/// Useful to allow XCM execution by local chain users via extrinsics. -/// E.g. `pallet_xcm::reserve_asset_transfer` to transfer a reserve asset -/// out of the local chain to another one. -pub struct AllowAllDebug; -impl ShouldExecute for AllowAllDebug { - fn should_execute( - _origin: &MultiLocation, - _message: &mut Xcm, - _max_weight: Weight, - _weight_credit: &mut Weight, - ) -> Result<(), ()> { - Ok(()) - } -} - -pub type Barrier = DenyThenTry< - DenyTransact, - ( - TakeWeightCredit, - AllowTopLevelPaidExecutionFrom, - AllowUnpaidExecutionFrom, - // ^^^ Parent & its unit plurality gets free execution - AllowAllDebug, - ), ->; --- a/runtime/quartz/src/lib.rs +++ b/runtime/quartz/src/lib.rs @@ -35,7 +35,7 @@ #[path = "../../common/mod.rs"] mod runtime_common; -pub mod xcm_config; +pub mod xcm_barrier; #[cfg(test)] mod tests; --- /dev/null +++ b/runtime/quartz/src/xcm_barrier.rs @@ -0,0 +1,84 @@ +// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. +// This file is part of Unique Network. + +// Unique Network is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Unique Network is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Unique Network. If not, see . + +use frame_support::{match_types, parameter_types, traits::Get}; +use sp_std::{vec, vec::Vec}; +use xcm::v1::{BodyId, Junction::*, Junctions::*, MultiLocation}; +use xcm_builder::{ + AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowUnpaidExecutionFrom, TakeWeightCredit, +}; + +use crate::{ + ParachainInfo, PolkadotXcm, + runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation}, +}; + +match_types! { + pub type ParentOrParentsExecutivePlurality: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } + }; + pub type ParentOrSiblings: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(_) } + }; +} + +parameter_types! { + pub QuartzAllowedLocations: Vec = vec![ + // Self location + MultiLocation { + parents: 0, + interior: Here, + }, + // Parent location + MultiLocation { + parents: 1, + interior: Here, + }, + // Karura/Acala location + MultiLocation { + parents: 1, + interior: X1(Parachain(2000)), + }, + // Moonriver location + MultiLocation { + parents: 1, + interior: X1(Parachain(2023)), + }, + // Self parachain address + MultiLocation { + parents: 1, + interior: X1(Parachain(ParachainInfo::get().into())), + }, + ]; +} + +pub type Barrier = DenyThenTry< + ( + DenyTransact, + DenyExchangeWithUnknownLocation, + ), + ( + TakeWeightCredit, + // Parent and its exec plurality get free execution + AllowUnpaidExecutionFrom, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), +>; --- a/runtime/quartz/src/xcm_config.rs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. -// This file is part of Unique Network. - -// Unique Network is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Unique Network is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Unique Network. If not, see . - -use frame_support::{match_types, parameter_types, traits::Get}; -use sp_std::{vec, vec::Vec}; -use xcm::v1::{BodyId, Junction::*, Junctions::*, MultiLocation}; -use xcm_builder::{ - AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowUnpaidExecutionFrom, TakeWeightCredit, -}; - -use crate::{ - ParachainInfo, PolkadotXcm, - runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation}, -}; - -match_types! { - pub type ParentOrParentsExecutivePlurality: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } - }; - pub type ParentOrSiblings: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(_) } - }; -} - -parameter_types! { - pub QuartzAllowedLocations: Vec = vec![ - // Self location - MultiLocation { - parents: 0, - interior: Here, - }, - // Parent location - MultiLocation { - parents: 1, - interior: Here, - }, - // Karura/Acala location - MultiLocation { - parents: 1, - interior: X1(Parachain(2000)), - }, - // Moonriver location - MultiLocation { - parents: 1, - interior: X1(Parachain(2023)), - }, - // Self parachain address - MultiLocation { - parents: 1, - interior: X1(Parachain(ParachainInfo::get().into())), - }, - ]; -} - -pub type Barrier = DenyThenTry< - ( - DenyTransact, - DenyExchangeWithUnknownLocation, - ), - ( - TakeWeightCredit, - // Parent and its exec plurality get free execution - AllowUnpaidExecutionFrom, - // Expected responses are OK. - AllowKnownQueryResponses, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, - ), ->; --- a/runtime/unique/src/lib.rs +++ b/runtime/unique/src/lib.rs @@ -35,7 +35,7 @@ #[path = "../../common/mod.rs"] mod runtime_common; -pub mod xcm_config; +pub mod xcm_barrier; #[cfg(test)] mod tests; --- /dev/null +++ b/runtime/unique/src/xcm_barrier.rs @@ -0,0 +1,84 @@ +// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. +// This file is part of Unique Network. + +// Unique Network is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Unique Network is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Unique Network. If not, see . + +use frame_support::{match_types, parameter_types, traits::Get}; +use sp_std::{vec, vec::Vec}; +use xcm::v1::{BodyId, Junction::*, Junctions::*, MultiLocation}; +use xcm_builder::{ + AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowUnpaidExecutionFrom, TakeWeightCredit, +}; + +use crate::{ + ParachainInfo, PolkadotXcm, + runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation}, +}; + +match_types! { + pub type ParentOrParentsExecutivePlurality: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } + }; + pub type ParentOrSiblings: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(_) } + }; +} + +parameter_types! { + pub UniqueAllowedLocations: Vec = vec![ + // Self location + MultiLocation { + parents: 0, + interior: Here, + }, + // Parent location + MultiLocation { + parents: 1, + interior: Here, + }, + // Karura/Acala location + MultiLocation { + parents: 1, + interior: X1(Parachain(2000)), + }, + // Moonbeam location + MultiLocation { + parents: 1, + interior: X1(Parachain(2004)), + }, + // Self parachain address + MultiLocation { + parents: 1, + interior: X1(Parachain(ParachainInfo::get().into())), + }, + ]; +} + +pub type Barrier = DenyThenTry< + ( + DenyTransact, + DenyExchangeWithUnknownLocation, + ), + ( + TakeWeightCredit, + // Parent and its exec plurality get free execution + AllowUnpaidExecutionFrom, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), +>; --- a/runtime/unique/src/xcm_config.rs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. -// This file is part of Unique Network. - -// Unique Network is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Unique Network is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Unique Network. If not, see . - -use frame_support::{match_types, parameter_types, traits::Get}; -use sp_std::{vec, vec::Vec}; -use xcm::v1::{BodyId, Junction::*, Junctions::*, MultiLocation}; -use xcm_builder::{ - AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowUnpaidExecutionFrom, TakeWeightCredit, -}; - -use crate::{ - ParachainInfo, PolkadotXcm, - runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation}, -}; - -match_types! { - pub type ParentOrParentsExecutivePlurality: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } - }; - pub type ParentOrSiblings: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(_) } - }; -} - -parameter_types! { - pub UniqueAllowedLocations: Vec = vec![ - // Self location - MultiLocation { - parents: 0, - interior: Here, - }, - // Parent location - MultiLocation { - parents: 1, - interior: Here, - }, - // Karura/Acala location - MultiLocation { - parents: 1, - interior: X1(Parachain(2000)), - }, - // Moonbeam location - MultiLocation { - parents: 1, - interior: X1(Parachain(2004)), - }, - // Self parachain address - MultiLocation { - parents: 1, - interior: X1(Parachain(ParachainInfo::get().into())), - }, - ]; -} - -pub type Barrier = DenyThenTry< - ( - DenyTransact, - DenyExchangeWithUnknownLocation, - ), - ( - TakeWeightCredit, - // Parent and its exec plurality get free execution - AllowUnpaidExecutionFrom, - // Expected responses are OK. - AllowKnownQueryResponses, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, - ), ->; -- gitstuff