git.delta.rocks / unique-network / refs/commits / cc3ebd788a7b

difftreelog

fix weight coeffs

Daniel Shiposha2022-11-28parent: #f461d40.patch.diff
in: master

3 files changed

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 parity_scale_codec::{Decode, Encode, MaxEncodedLen};27use scale_info::TypeInfo;28use sp_arithmetic::traits::{BaseArithmetic, Unsigned};29use smallvec::smallvec;3031pub use pallet::*;32use sp_core::U256;33use sp_runtime::Perbill;3435#[pallet]36mod pallet {37	use super::*;38	use frame_support::{39		traits::Get,40		pallet_prelude::{StorageValue, ValueQuery, DispatchResult, OptionQuery},41		BoundedVec,42	};43	use frame_system::{pallet_prelude::OriginFor, ensure_root};44	use xcm::v1::MultiLocation;4546	#[pallet::config]47	pub trait Config: frame_system::Config {48		#[pallet::constant]49		type DefaultWeightToFeeCoefficient: Get<u32>;5051		#[pallet::constant]52		type DefaultMinGasPrice: Get<u64>;5354		#[pallet::constant]55		type MaxXcmAllowedLocations: Get<u32>;56		#[pallet::constant]57		type AppPromotionDailyRate: Get<Perbill>;58		#[pallet::constant]59		type DayRelayBlocks: Get<Self::BlockNumber>;60	}6162	#[pallet::error]63	pub enum Error<T> {64		InconsistentConfiguration,65	}6667	#[pallet::storage]68	pub type WeightToFeeCoefficientOverride<T: Config> = StorageValue<69		Value = u32,70		QueryKind = ValueQuery,71		OnEmpty = T::DefaultWeightToFeeCoefficient,72	>;7374	#[pallet::storage]75	pub type MinGasPriceOverride<T: Config> =76		StorageValue<Value = u64, QueryKind = ValueQuery, OnEmpty = T::DefaultMinGasPrice>;7778	#[pallet::storage]79	pub type XcmAllowedLocationsOverride<T: Config> = StorageValue<80		Value = BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>,81		QueryKind = OptionQuery,82	>;8384	#[pallet::storage]85	pub type AppPromomotionConfigurationOverride<T: Config> =86		StorageValue<Value = AppPromotionConfiguration<T::BlockNumber>, QueryKind = ValueQuery>;8788	#[pallet::call]89	impl<T: Config> Pallet<T> {90		#[pallet::weight(T::DbWeight::get().writes(1))]91		pub fn set_weight_to_fee_coefficient_override(92			origin: OriginFor<T>,93			coeff: Option<u32>,94		) -> DispatchResult {95			ensure_root(origin)?;96			if let Some(coeff) = coeff {97				<WeightToFeeCoefficientOverride<T>>::set(coeff);98			} else {99				<WeightToFeeCoefficientOverride<T>>::kill();100			}101			Ok(())102		}103104		#[pallet::weight(T::DbWeight::get().writes(1))]105		pub fn set_min_gas_price_override(106			origin: OriginFor<T>,107			coeff: Option<u64>,108		) -> DispatchResult {109			ensure_root(origin)?;110			if let Some(coeff) = coeff {111				<MinGasPriceOverride<T>>::set(coeff);112			} else {113				<MinGasPriceOverride<T>>::kill();114			}115			Ok(())116		}117118		#[pallet::weight(T::DbWeight::get().writes(1))]119		pub fn set_xcm_allowed_locations(120			origin: OriginFor<T>,121			locations: Option<BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>>,122		) -> DispatchResult {123			ensure_root(origin)?;124			<XcmAllowedLocationsOverride<T>>::set(locations);125			Ok(())126		}127128		#[pallet::weight(T::DbWeight::get().writes(1))]129		pub fn set_app_promotion_configuration_override(130			origin: OriginFor<T>,131			mut configuration: AppPromotionConfiguration<T::BlockNumber>,132		) -> DispatchResult {133			ensure_root(origin)?;134			if configuration.interval_income.is_some() {135				return Err(<Error<T>>::InconsistentConfiguration.into());136			}137138			configuration.interval_income = configuration.recalculation_interval.map(|b| {139				Perbill::from_rational(b, T::DayRelayBlocks::get())140					* T::AppPromotionDailyRate::get()141			});142143			<AppPromomotionConfigurationOverride<T>>::set(configuration);144145			Ok(())146		}147	}148149	#[pallet::pallet]150	#[pallet::generate_store(pub(super) trait Store)]151	pub struct Pallet<T>(_);152}153154pub struct WeightToFee<T, B>(PhantomData<(T, B)>);155156impl<T, B> WeightToFeePolynomial for WeightToFee<T, B>157where158	T: Config,159	B: BaseArithmetic + From<u32> + Copy + Unsigned,160{161	type Balance = B;162163	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {164		smallvec!(WeightToFeeCoefficient {165			coeff_integer: <WeightToFeeCoefficientOverride<T>>::get().into(),166			coeff_frac: Perbill::zero(),167			negative: false,168			degree: 1,169		})170	}171}172173pub struct FeeCalculator<T>(PhantomData<T>);174impl<T: Config> fp_evm::FeeCalculator for FeeCalculator<T> {175	fn min_gas_price() -> (U256, Weight) {176		(177			<MinGasPriceOverride<T>>::get().into(),178			T::DbWeight::get().reads(1),179		)180	}181}182183#[derive(Encode, Decode, Clone, Debug, Default, TypeInfo, MaxEncodedLen, PartialEq, PartialOrd)]184pub struct AppPromotionConfiguration<BlockNumber> {185	/// In relay blocks.186	pub recalculation_interval: Option<BlockNumber>,187	/// In parachain blocks.188	pub pending_interval: Option<BlockNumber>,189	/// Value for `RecalculationInterval` based on 0.05% per 24h.190	pub interval_income: Option<Perbill>,191	/// Maximum allowable number of stakers calculated per call of the `app-promotion::PayoutStakers` extrinsic.192	pub max_stakers_per_calculation: Option<u8>,193}
after · 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 parity_scale_codec::{Decode, Encode, MaxEncodedLen};27use scale_info::TypeInfo;28use sp_arithmetic::{29	per_things::{Perbill, PerThing},30	traits::{BaseArithmetic, Unsigned},31};32use smallvec::smallvec;3334pub use pallet::*;35use sp_core::U256;3637#[pallet]38mod pallet {39	use super::*;40	use frame_support::{41		traits::Get,42		pallet_prelude::{StorageValue, ValueQuery, DispatchResult, OptionQuery},43		BoundedVec,44	};45	use frame_system::{pallet_prelude::OriginFor, ensure_root};46	use xcm::v1::MultiLocation;4748	#[pallet::config]49	pub trait Config: frame_system::Config {50		#[pallet::constant]51		type DefaultWeightToFeeCoefficient: Get<u64>;52		#[pallet::constant]53		type DefaultMinGasPrice: Get<u64>;5455		#[pallet::constant]56		type MaxXcmAllowedLocations: Get<u32>;57		#[pallet::constant]58		type AppPromotionDailyRate: Get<Perbill>;59		#[pallet::constant]60		type DayRelayBlocks: Get<Self::BlockNumber>;61	}6263	#[pallet::error]64	pub enum Error<T> {65		InconsistentConfiguration,66	}6768	#[pallet::storage]69	pub type WeightToFeeCoefficientOverride<T: Config> = StorageValue<70		Value = u64,71		QueryKind = ValueQuery,72		OnEmpty = T::DefaultWeightToFeeCoefficient,73	>;7475	#[pallet::storage]76	pub type MinGasPriceOverride<T: Config> =77		StorageValue<Value = u64, QueryKind = ValueQuery, OnEmpty = T::DefaultMinGasPrice>;7879	#[pallet::storage]80	pub type XcmAllowedLocationsOverride<T: Config> = StorageValue<81		Value = BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>,82		QueryKind = OptionQuery,83	>;8485	#[pallet::storage]86	pub type AppPromomotionConfigurationOverride<T: Config> =87		StorageValue<Value = AppPromotionConfiguration<T::BlockNumber>, QueryKind = ValueQuery>;8889	#[pallet::call]90	impl<T: Config> Pallet<T> {91		#[pallet::weight(T::DbWeight::get().writes(1))]92		pub fn set_weight_to_fee_coefficient_override(93			origin: OriginFor<T>,94			coeff: Option<u64>,95		) -> DispatchResult {96			ensure_root(origin)?;97			if let Some(coeff) = coeff {98				<WeightToFeeCoefficientOverride<T>>::set(coeff);99			} else {100				<WeightToFeeCoefficientOverride<T>>::kill();101			}102			Ok(())103		}104105		#[pallet::weight(T::DbWeight::get().writes(1))]106		pub fn set_min_gas_price_override(107			origin: OriginFor<T>,108			coeff: Option<u64>,109		) -> DispatchResult {110			ensure_root(origin)?;111			if let Some(coeff) = coeff {112				<MinGasPriceOverride<T>>::set(coeff);113			} else {114				<MinGasPriceOverride<T>>::kill();115			}116			Ok(())117		}118119		#[pallet::weight(T::DbWeight::get().writes(1))]120		pub fn set_xcm_allowed_locations(121			origin: OriginFor<T>,122			locations: Option<BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>>,123		) -> DispatchResult {124			ensure_root(origin)?;125			<XcmAllowedLocationsOverride<T>>::set(locations);126			Ok(())127		}128129		#[pallet::weight(T::DbWeight::get().writes(1))]130		pub fn set_app_promotion_configuration_override(131			origin: OriginFor<T>,132			mut configuration: AppPromotionConfiguration<T::BlockNumber>,133		) -> DispatchResult {134			ensure_root(origin)?;135			if configuration.interval_income.is_some() {136				return Err(<Error<T>>::InconsistentConfiguration.into());137			}138139			configuration.interval_income = configuration.recalculation_interval.map(|b| {140				Perbill::from_rational(b, T::DayRelayBlocks::get())141					* T::AppPromotionDailyRate::get()142			});143144			<AppPromomotionConfigurationOverride<T>>::set(configuration);145146			Ok(())147		}148	}149150	#[pallet::pallet]151	#[pallet::generate_store(pub(super) trait Store)]152	pub struct Pallet<T>(_);153}154155pub struct WeightToFee<T, B>(PhantomData<(T, B)>);156157impl<T, B> WeightToFeePolynomial for WeightToFee<T, B>158where159	T: Config,160	B: BaseArithmetic + From<u32> + From<u64> + Copy + Unsigned,161{162	type Balance = B;163164	fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {165		smallvec!(WeightToFeeCoefficient {166			coeff_integer: (<WeightToFeeCoefficientOverride<T>>::get() / Perbill::ACCURACY as u64)167				.into(),168			coeff_frac: Perbill::from_parts(169				(<WeightToFeeCoefficientOverride<T>>::get() % Perbill::ACCURACY as u64) as u32170			),171			negative: false,172			degree: 1,173		})174	}175}176177pub struct FeeCalculator<T>(PhantomData<T>);178impl<T: Config> fp_evm::FeeCalculator for FeeCalculator<T> {179	fn min_gas_price() -> (U256, Weight) {180		(181			<MinGasPriceOverride<T>>::get().into(),182			T::DbWeight::get().reads(1),183		)184	}185}186187#[derive(Encode, Decode, Clone, Debug, Default, TypeInfo, MaxEncodedLen, PartialEq, PartialOrd)]188pub struct AppPromotionConfiguration<BlockNumber> {189	/// In relay blocks.190	pub recalculation_interval: Option<BlockNumber>,191	/// In parachain blocks.192	pub pending_interval: Option<BlockNumber>,193	/// Value for `RecalculationInterval` based on 0.05% per 24h.194	pub interval_income: Option<Perbill>,195	/// Maximum allowable number of stakers calculated per call of the `app-promotion::PayoutStakers` extrinsic.196	pub max_stakers_per_calculation: Option<u8>,197}
modifiedprimitives/common/src/constants.rsdiffbeforeafterboth
--- a/primitives/common/src/constants.rs
+++ b/primitives/common/src/constants.rs
@@ -43,7 +43,7 @@
 pub const UNIQUE: Balance = 100 * CENTIUNIQUE;
 
 // Targeting 0.1 UNQ per transfer
-pub const WEIGHT_TO_FEE_COEFF: u32 = /*<weight2fee>*/175_199_920/*</weight2fee>*/;
+pub const WEIGHT_TO_FEE_COEFF: u64 = /*<weight2fee>*/78_389_100_150_858_528/*</weight2fee>*/;
 
 // Targeting 0.15 UNQ per transfer via ETH
 pub const MIN_GAS_PRICE: u64 = /*<mingasprice>*/1_014_919_410_810/*</mingasprice>*/;
@@ -60,5 +60,5 @@
 	.set_proof_size(MAX_POV_SIZE as u64);
 
 parameter_types! {
-	pub const TransactionByteFee: Balance = 501 * MICROUNIQUE;
+	pub const TransactionByteFee: Balance = 501 * MICROUNIQUE / 2;
 }
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -25,7 +25,7 @@
 	},
 	Runtime, RuntimeEvent, RuntimeCall, Balances,
 };
-use frame_support::traits::{ConstU32, ConstU64};
+use frame_support::traits::ConstU64;
 use up_common::{
 	types::{AccountId, Balance, BlockNumber},
 	constants::*,
@@ -104,7 +104,7 @@
 	pub const DayRelayBlocks: BlockNumber = RELAY_DAYS;
 }
 impl pallet_configuration::Config for Runtime {
-	type DefaultWeightToFeeCoefficient = ConstU32<{ up_common::constants::WEIGHT_TO_FEE_COEFF }>;
+	type DefaultWeightToFeeCoefficient = ConstU64<{ up_common::constants::WEIGHT_TO_FEE_COEFF }>;
 	type DefaultMinGasPrice = ConstU64<{ up_common::constants::MIN_GAS_PRICE }>;
 	type MaxXcmAllowedLocations = ConstU32<16>;
 	type AppPromotionDailyRate = AppPromotionDailyRate;