git.delta.rocks / unique-network / refs/commits / 44d02634621c

difftreelog

feat add overridable xcm allowed locations

Daniel Shiposha2022-12-12parent: #489f7f3.patch.diff
in: master

8 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5934,6 +5934,7 @@
  "sp-core",
  "sp-runtime",
  "sp-std",
+ "xcm",
 ]
 
 [[package]]
modifiedpallets/configuration/Cargo.tomldiffbeforeafterboth
--- a/pallets/configuration/Cargo.toml
+++ b/pallets/configuration/Cargo.toml
@@ -18,6 +18,7 @@
 sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
 fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.30-2" }
 smallvec = "1.6.1"
+xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" }
 
 [features]
 default = ["std"]
modifiedpallets/configuration/src/lib.rsdiffbeforeafterboth
--- a/pallets/configuration/src/lib.rs
+++ b/pallets/configuration/src/lib.rs
@@ -35,16 +35,21 @@
 	use super::*;
 	use frame_support::{
 		traits::Get,
-		pallet_prelude::{StorageValue, ValueQuery, DispatchResult},
+		pallet_prelude::{StorageValue, ValueQuery, DispatchResult, OptionQuery}, BoundedVec,
 	};
 	use frame_system::{pallet_prelude::OriginFor, ensure_root};
+	use xcm::v1::MultiLocation;
 
 	#[pallet::config]
 	pub trait Config: frame_system::Config {
 		#[pallet::constant]
 		type DefaultWeightToFeeCoefficient: Get<u32>;
+
 		#[pallet::constant]
 		type DefaultMinGasPrice: Get<u64>;
+
+		#[pallet::constant]
+		type MaxOverridedAllowedLocations: Get<u32>;
 	}
 
 	#[pallet::storage]
@@ -58,6 +63,12 @@
 	pub type MinGasPriceOverride<T: Config> =
 		StorageValue<Value = u64, QueryKind = ValueQuery, OnEmpty = T::DefaultMinGasPrice>;
 
+	#[pallet::storage]
+	pub type XcmAllowedLocationsOverride<T: Config> = StorageValue<
+		Value = BoundedVec<MultiLocation, T::MaxOverridedAllowedLocations>,
+		QueryKind = OptionQuery,
+	>;
+
 	#[pallet::call]
 	impl<T: Config> Pallet<T> {
 		#[pallet::weight(T::DbWeight::get().writes(1))]
@@ -87,6 +98,16 @@
 			}
 			Ok(())
 		}
+
+		#[pallet::weight(T::DbWeight::get().writes(1))]
+		pub fn set_xcm_allowed_locations(
+			origin: OriginFor<T>,
+			locations: Option<BoundedVec<MultiLocation, T::MaxOverridedAllowedLocations>>,
+		) -> DispatchResult {
+			let _sender = ensure_root(origin)?;
+			<XcmAllowedLocationsOverride<T>>::set(locations);
+			Ok(())
+		}
 	}
 
 	#[pallet::pallet]
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -102,6 +102,7 @@
 impl pallet_configuration::Config for Runtime {
 	type DefaultWeightToFeeCoefficient = ConstU32<{ up_common::constants::WEIGHT_TO_FEE_COEFF }>;
 	type DefaultMinGasPrice = ConstU64<{ up_common::constants::MIN_GAS_PRICE }>;
+	type MaxOverridedAllowedLocations = ConstU32<16>;
 }
 
 impl pallet_maintenance::Config for Runtime {
modifiedruntime/common/mod.rsdiffbeforeafterboth
before · runtime/common/mod.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617pub mod config;18pub mod construct_runtime;19pub mod dispatch;20pub mod ethereum;21pub mod instance;22pub mod maintenance;23pub mod runtime_apis;2425#[cfg(feature = "scheduler")]26pub mod scheduler;2728pub mod sponsoring;29pub mod weights;3031#[cfg(test)]32pub mod tests;3334use sp_core::H160;35use frame_support::traits::{Currency, OnUnbalanced, Imbalance};36use sp_runtime::{37	generic,38	traits::{BlakeTwo256, BlockNumberProvider},39	impl_opaque_keys,40};41use sp_std::vec::Vec;4243#[cfg(feature = "std")]44use sp_version::NativeVersion;4546use crate::{47	Runtime, RuntimeCall, Balances, Treasury, Aura, Signature, AllPalletsWithSystem,48	InherentDataExt,49};50use up_common::types::{AccountId, BlockNumber};5152#[macro_export]53macro_rules! unsupported {54	() => {55		pallet_common::unsupported!($crate::Runtime)56	};57}5859/// The address format for describing accounts.60pub type Address = sp_runtime::MultiAddress<AccountId, ()>;61/// Block header type as expected by this runtime.62pub type Header = generic::Header<BlockNumber, BlakeTwo256>;63/// Block type as expected by this runtime.64pub type Block = generic::Block<Header, UncheckedExtrinsic>;65/// A Block signed with a Justification66pub type SignedBlock = generic::SignedBlock<Block>;67/// BlockId type as expected by this runtime.68pub type BlockId = generic::BlockId<Block>;6970impl_opaque_keys! {71	pub struct SessionKeys {72		pub aura: Aura,73	}74}7576/// The version information used to identify this runtime when compiled natively.77#[cfg(feature = "std")]78pub fn native_version() -> NativeVersion {79	NativeVersion {80		runtime_version: crate::VERSION,81		can_author_with: Default::default(),82	}83}8485pub type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;8687pub type SignedExtra = (88	frame_system::CheckSpecVersion<Runtime>,89	frame_system::CheckTxVersion<Runtime>,90	frame_system::CheckGenesis<Runtime>,91	frame_system::CheckEra<Runtime>,92	frame_system::CheckNonce<Runtime>,93	frame_system::CheckWeight<Runtime>,94	maintenance::CheckMaintenance,95	ChargeTransactionPayment,96	//pallet_contract_helpers::ContractHelpersExtension<Runtime>,97	pallet_ethereum::FakeTransactionFinalizer<Runtime>,98);99100/// Unchecked extrinsic type as expected by this runtime.101pub type UncheckedExtrinsic =102	fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;103104/// Extrinsic type that has already been checked.105pub type CheckedExtrinsic =106	fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;107108/// Executive: handles dispatch to the various modules.109pub type Executive = frame_executive::Executive<110	Runtime,111	Block,112	frame_system::ChainContext<Runtime>,113	Runtime,114	AllPalletsWithSystem,115>;116117type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;118119pub struct DealWithFees;120impl OnUnbalanced<NegativeImbalance> for DealWithFees {121	fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {122		if let Some(fees) = fees_then_tips.next() {123			// for fees, 100% to treasury124			let mut split = fees.ration(100, 0);125			if let Some(tips) = fees_then_tips.next() {126				// for tips, if any, 100% to treasury127				tips.ration_merge_into(100, 0, &mut split);128			}129			Treasury::on_unbalanced(split.0);130			// Author::on_unbalanced(split.1);131		}132	}133}134135pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);136137impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider138	for RelayChainBlockNumberProvider<T>139{140	type BlockNumber = BlockNumber;141142	fn current_block_number() -> Self::BlockNumber {143		cumulus_pallet_parachain_system::Pallet::<T>::validation_data()144			.map(|d| d.relay_parent_number)145			.unwrap_or_default()146	}147}148149pub(crate) struct CheckInherents;150151impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {152	fn check_inherents(153		block: &Block,154		relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,155	) -> sp_inherents::CheckInherentsResult {156		let relay_chain_slot = relay_state_proof157			.read_slot()158			.expect("Could not read the relay chain slot from the proof");159160		let inherent_data =161			cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(162				relay_chain_slot,163				sp_std::time::Duration::from_secs(6),164			)165			.create_inherent_data()166			.expect("Could not create the timestamp inherent data");167168		inherent_data.check_extrinsics(block)169	}170}171172#[derive(codec::Encode, codec::Decode)]173pub enum XCMPMessage<XAccountId, XBalance> {174	/// Transfer tokens to the given account from the Parachain account.175	TransferToken(XAccountId, XBalance),176}
after · runtime/common/mod.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617pub mod config;18pub mod construct_runtime;19pub mod dispatch;20pub mod ethereum;21pub mod instance;22pub mod maintenance;23pub mod runtime_apis;24pub mod xcm;2526#[cfg(feature = "scheduler")]27pub mod scheduler;2829pub mod sponsoring;30pub mod weights;3132#[cfg(test)]33pub mod tests;3435use sp_core::H160;36use frame_support::traits::{Currency, OnUnbalanced, Imbalance};37use sp_runtime::{38	generic,39	traits::{BlakeTwo256, BlockNumberProvider},40	impl_opaque_keys,41};42use sp_std::vec::Vec;4344#[cfg(feature = "std")]45use sp_version::NativeVersion;4647use crate::{48	Runtime, RuntimeCall, Balances, Treasury, Aura, Signature, AllPalletsWithSystem,49	InherentDataExt,50};51use up_common::types::{AccountId, BlockNumber};5253#[macro_export]54macro_rules! unsupported {55	() => {56		pallet_common::unsupported!($crate::Runtime)57	};58}5960/// The address format for describing accounts.61pub type Address = sp_runtime::MultiAddress<AccountId, ()>;62/// Block header type as expected by this runtime.63pub type Header = generic::Header<BlockNumber, BlakeTwo256>;64/// Block type as expected by this runtime.65pub type Block = generic::Block<Header, UncheckedExtrinsic>;66/// A Block signed with a Justification67pub type SignedBlock = generic::SignedBlock<Block>;68/// BlockId type as expected by this runtime.69pub type BlockId = generic::BlockId<Block>;7071impl_opaque_keys! {72	pub struct SessionKeys {73		pub aura: Aura,74	}75}7677/// The version information used to identify this runtime when compiled natively.78#[cfg(feature = "std")]79pub fn native_version() -> NativeVersion {80	NativeVersion {81		runtime_version: crate::VERSION,82		can_author_with: Default::default(),83	}84}8586pub type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;8788pub type SignedExtra = (89	frame_system::CheckSpecVersion<Runtime>,90	frame_system::CheckTxVersion<Runtime>,91	frame_system::CheckGenesis<Runtime>,92	frame_system::CheckEra<Runtime>,93	frame_system::CheckNonce<Runtime>,94	frame_system::CheckWeight<Runtime>,95	maintenance::CheckMaintenance,96	ChargeTransactionPayment,97	//pallet_contract_helpers::ContractHelpersExtension<Runtime>,98	pallet_ethereum::FakeTransactionFinalizer<Runtime>,99);100101/// Unchecked extrinsic type as expected by this runtime.102pub type UncheckedExtrinsic =103	fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;104105/// Extrinsic type that has already been checked.106pub type CheckedExtrinsic =107	fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;108109/// Executive: handles dispatch to the various modules.110pub type Executive = frame_executive::Executive<111	Runtime,112	Block,113	frame_system::ChainContext<Runtime>,114	Runtime,115	AllPalletsWithSystem,116>;117118type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;119120pub struct DealWithFees;121impl OnUnbalanced<NegativeImbalance> for DealWithFees {122	fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {123		if let Some(fees) = fees_then_tips.next() {124			// for fees, 100% to treasury125			let mut split = fees.ration(100, 0);126			if let Some(tips) = fees_then_tips.next() {127				// for tips, if any, 100% to treasury128				tips.ration_merge_into(100, 0, &mut split);129			}130			Treasury::on_unbalanced(split.0);131			// Author::on_unbalanced(split.1);132		}133	}134}135136pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);137138impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider139	for RelayChainBlockNumberProvider<T>140{141	type BlockNumber = BlockNumber;142143	fn current_block_number() -> Self::BlockNumber {144		cumulus_pallet_parachain_system::Pallet::<T>::validation_data()145			.map(|d| d.relay_parent_number)146			.unwrap_or_default()147	}148}149150pub(crate) struct CheckInherents;151152impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {153	fn check_inherents(154		block: &Block,155		relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,156	) -> sp_inherents::CheckInherentsResult {157		let relay_chain_slot = relay_state_proof158			.read_slot()159			.expect("Could not read the relay chain slot from the proof");160161		let inherent_data =162			cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(163				relay_chain_slot,164				sp_std::time::Duration::from_secs(6),165			)166			.create_inherent_data()167			.expect("Could not create the timestamp inherent data");168169		inherent_data.check_extrinsics(block)170	}171}172173#[derive(codec::Encode, codec::Decode)]174pub enum XCMPMessage<XAccountId, XBalance> {175	/// Transfer tokens to the given account from the Parachain account.176	TransferToken(XAccountId, XBalance),177}
addedruntime/common/xcm.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/common/xcm.rs
@@ -0,0 +1,36 @@
+// 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 <http://www.gnu.org/licenses/>.
+
+use sp_std::{vec::Vec, marker::PhantomData};
+use xcm::v1::MultiLocation;
+use frame_support::traits::Get;
+
+pub struct OverridableAllowedLocations<T, L>(PhantomData<(T, L)>)
+where
+    T: pallet_configuration::Config,
+    L: Get<Vec<MultiLocation>>;
+
+impl<T, L> Get<Vec<MultiLocation>> for OverridableAllowedLocations<T, L>
+where
+    T: pallet_configuration::Config,
+    L: Get<Vec<MultiLocation>>
+{
+    fn get() -> Vec<MultiLocation> {
+        <pallet_configuration::XcmAllowedLocationsOverride<T>>::get()
+            .map(|bounded| bounded.into_inner())
+            .unwrap_or_else(|| L::get())
+    }
+}
modifiedruntime/quartz/src/xcm_barrier.rsdiffbeforeafterboth
--- a/runtime/quartz/src/xcm_barrier.rs
+++ b/runtime/quartz/src/xcm_barrier.rs
@@ -26,8 +26,11 @@
 };
 
 use crate::{
-	ParachainInfo, PolkadotXcm,
-	runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation},
+	Runtime, ParachainInfo, PolkadotXcm,
+	runtime_common::{
+		config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation},
+		xcm::OverridableAllowedLocations,
+	}
 };
 
 match_types! {
@@ -38,7 +41,7 @@
 }
 
 parameter_types! {
-	pub QuartzAllowedLocations: Vec<MultiLocation> = vec![
+	pub QuartzDefaultAllowedLocations: Vec<MultiLocation> = vec![
 		// Self location
 		MultiLocation {
 			parents: 0,
@@ -70,7 +73,9 @@
 pub type Barrier = DenyThenTry<
 	(
 		DenyTransact,
-		DenyExchangeWithUnknownLocation<QuartzAllowedLocations>,
+		DenyExchangeWithUnknownLocation<
+			OverridableAllowedLocations<Runtime, QuartzDefaultAllowedLocations>
+		>,
 	),
 	(
 		TakeWeightCredit,
modifiedruntime/unique/src/xcm_barrier.rsdiffbeforeafterboth
--- a/runtime/unique/src/xcm_barrier.rs
+++ b/runtime/unique/src/xcm_barrier.rs
@@ -26,8 +26,11 @@
 };
 
 use crate::{
-	ParachainInfo, PolkadotXcm,
-	runtime_common::config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation},
+	Runtime, ParachainInfo, PolkadotXcm,
+	runtime_common::{
+		config::xcm::{DenyThenTry, DenyTransact, DenyExchangeWithUnknownLocation},
+		xcm::OverridableAllowedLocations,
+	}
 };
 
 match_types! {
@@ -38,7 +41,7 @@
 }
 
 parameter_types! {
-	pub UniqueAllowedLocations: Vec<MultiLocation> = vec![
+	pub UniqueDefaultAllowedLocations: Vec<MultiLocation> = vec![
 		// Self location
 		MultiLocation {
 			parents: 0,
@@ -70,7 +73,9 @@
 pub type Barrier = DenyThenTry<
 	(
 		DenyTransact,
-		DenyExchangeWithUnknownLocation<UniqueAllowedLocations>,
+		DenyExchangeWithUnknownLocation<
+			OverridableAllowedLocations<Runtime, UniqueDefaultAllowedLocations>
+		>,
 	),
 	(
 		TakeWeightCredit,