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
21pub mod instance;21pub mod instance;
22pub mod maintenance;22pub mod maintenance;
23pub mod runtime_apis;23pub mod runtime_apis;
24pub mod xcm;
2425
25#[cfg(feature = "scheduler")]26#[cfg(feature = "scheduler")]
26pub mod scheduler;27pub mod scheduler;
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,