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
before · pallets/configuration/src/lib.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/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::marker::PhantomData;2021use frame_support::{22	pallet,23	weights::{WeightToFeePolynomial, WeightToFeeCoefficients, WeightToFeeCoefficient, Weight},24	traits::Get,25};26use sp_arithmetic::traits::{BaseArithmetic, Unsigned};27use smallvec::smallvec;2829pub use pallet::*;30use sp_core::U256;31use sp_runtime::Perbill;3233#[pallet]34mod pallet {35	use super::*;36	use frame_support::{37		traits::Get,38		pallet_prelude::{StorageValue, ValueQuery, DispatchResult},39	};40	use frame_system::{pallet_prelude::OriginFor, ensure_root};4142	#[pallet::config]43	pub trait Config: frame_system::Config {44		#[pallet::constant]45		type DefaultWeightToFeeCoefficient: Get<u32>;46		#[pallet::constant]47		type DefaultMinGasPrice: Get<u64>;48	}4950	#[pallet::storage]51	pub type WeightToFeeCoefficientOverride<T: Config> = StorageValue<52		Value = u32,53		QueryKind = ValueQuery,54		OnEmpty = T::DefaultWeightToFeeCoefficient,55	>;5657	#[pallet::storage]58	pub type MinGasPriceOverride<T: Config> =59		StorageValue<Value = u64, QueryKind = ValueQuery, OnEmpty = T::DefaultMinGasPrice>;6061	#[pallet::call]62	impl<T: Config> Pallet<T> {63		#[pallet::weight(T::DbWeight::get().writes(1))]64		pub fn set_weight_to_fee_coefficient_override(65			origin: OriginFor<T>,66			coeff: Option<u32>,67		) -> DispatchResult {68			let _sender = ensure_root(origin)?;69			if let Some(coeff) = coeff {70				<WeightToFeeCoefficientOverride<T>>::set(coeff);71			} else {72				<WeightToFeeCoefficientOverride<T>>::kill();73			}74			Ok(())75		}7677		#[pallet::weight(T::DbWeight::get().writes(1))]78		pub fn set_min_gas_price_override(79			origin: OriginFor<T>,80			coeff: Option<u64>,81		) -> DispatchResult {82			let _sender = ensure_root(origin)?;83			if let Some(coeff) = coeff {84				<MinGasPriceOverride<T>>::set(coeff);85			} else {86				<MinGasPriceOverride<T>>::kill();87			}88			Ok(())89		}90	}9192	#[pallet::pallet]93	#[pallet::generate_store(pub(super) trait Store)]94	pub struct Pallet<T>(_);95}9697pub struct WeightToFee<T, B>(PhantomData<(T, B)>);9899impl<T, B> WeightToFeePolynomial for WeightToFee<T, B>100where101	T: Config,102	B: BaseArithmetic + From<u32> + Copy + Unsigned,103{104	type Balance = B;105106	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {107		smallvec!(WeightToFeeCoefficient {108			coeff_integer: <WeightToFeeCoefficientOverride<T>>::get().into(),109			coeff_frac: Perbill::zero(),110			negative: false,111			degree: 1,112		})113	}114}115116pub struct FeeCalculator<T>(PhantomData<T>);117impl<T: Config> fp_evm::FeeCalculator for FeeCalculator<T> {118	fn min_gas_price() -> (U256, Weight) {119		(120			<MinGasPriceOverride<T>>::get().into(),121			T::DbWeight::get().reads(1),122		)123	}124}
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
--- a/runtime/common/mod.rs
+++ b/runtime/common/mod.rs
@@ -21,6 +21,7 @@
 pub mod instance;
 pub mod maintenance;
 pub mod runtime_apis;
+pub mod xcm;
 
 #[cfg(feature = "scheduler")]
 pub 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,