From c01be68d96680748777f119b18fa5ef23cf9b4ad Mon Sep 17 00:00:00 2001 From: Herry Ho <45537372+herryho@users.noreply.github.com> Date: Mon, 23 Aug 2021 10:19:40 +0800 Subject: [PATCH] add FeeMultiplierUpdate (#249) --- Cargo.lock | 1 + runtime/asgard/src/lib.rs | 11 +++++++---- runtime/bifrost/src/lib.rs | 10 +++++++--- runtime/common/Cargo.toml | 2 ++ runtime/common/src/lib.rs | 20 +++++++++++++++++++- runtime/dev/src/lib.rs | 11 +++++++---- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 518ac087c..392203404 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -846,6 +846,7 @@ dependencies = [ "orml-tokens", "orml-traits", "pallet-collator-selection", + "pallet-transaction-payment", "pallet-xcm", "parachain-info", "parity-scale-codec", diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index 5f19e2810..f31b440c0 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -72,9 +72,12 @@ use xcm_support::Get; /// Constant values used within the runtime. pub mod constants; use bifrost_flexible_fee::fee_dealer::{FeeDealer, FixedCurrencyFeeRate}; -use bifrost_runtime_common::xcm_impl::{ - BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, - BifrostFilteredAssets, BifrostXcmTransactFilter, +use bifrost_runtime_common::{ + xcm_impl::{ + BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, + BifrostFilteredAssets, BifrostXcmTransactFilter, + }, + SlowAdjustingFeeUpdate, }; use codec::{Decode, Encode}; use constants::{currency::*, time::*}; @@ -638,7 +641,7 @@ impl pallet_tips::Config for Runtime { } impl pallet_transaction_payment::Config for Runtime { - type FeeMultiplierUpdate = (); + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; type OnChargeTransaction = FlexibleFee; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index aa9486eb0..2a75c3cd4 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -63,8 +63,12 @@ use static_assertions::const_assert; /// Constant values used within the runtime. pub mod constants; use bifrost_flexible_fee::fee_dealer::{FeeDealer, FixedCurrencyFeeRate}; -use bifrost_runtime_common::xcm_impl::{ - BifrostAssetMatcher, BifrostCurrencyIdConvert, BifrostFilteredAssets, BifrostXcmTransactFilter, +use bifrost_runtime_common::{ + xcm_impl::{ + BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, + BifrostFilteredAssets, BifrostXcmTransactFilter, + }, + SlowAdjustingFeeUpdate, }; use constants::{currency::*, time::*}; use cumulus_primitives_core::ParaId as CumulusParaId; @@ -522,7 +526,7 @@ impl pallet_tips::Config for Runtime { } impl pallet_transaction_payment::Config for Runtime { - type FeeMultiplierUpdate = (); + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; type OnChargeTransaction = FlexibleFee; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index c61c9a6a0..01a19632d 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -33,6 +33,7 @@ frame-support = { version = "3.0.0", default-features = false } frame-system = { version = "3.0.0", default-features = false } frame-system-rpc-runtime-api = { version = "3.0.0", default-features = false } max-encoded-len = { version = "3.0.0", default-features = false } +pallet-transaction-payment = { version = "3.0.0", default-features = false } # Cumulus dependencies cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.8" } @@ -100,4 +101,5 @@ std = [ "xcm-support/std", "zenlink-protocol/std", "zenlink-protocol-runtime-api/std", + "pallet-transaction-payment/std" ] diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 42fc4a302..6e07f4986 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -17,8 +17,10 @@ // along with this program. If not, see . #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::sp_runtime::offchain::storage_lock::BlockNumberProvider; +use frame_support::{parameter_types, sp_runtime::offchain::storage_lock::BlockNumberProvider}; use node_primitives::BlockNumber; +use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; +use sp_runtime::{FixedPointNumber, Perquintill}; pub mod xcm_impl; @@ -35,3 +37,19 @@ impl BlockNumberProvider .unwrap_or_default() } } + +parameter_types! { + /// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less + /// than this will decrease the weight and more will increase. + pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25); + /// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to + /// change the fees more rapidly. + pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000); + /// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure + /// that combined with `AdjustmentVariable`, we can recover from the minimum. + /// See `multiplier_can_grow_from_zero`. + pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128); +} + +pub type SlowAdjustingFeeUpdate = + TargetedFeeAdjustment; diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index d7de0c2e6..4f78ac50f 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -77,9 +77,12 @@ use xcm_support::Get; /// Constant values used within the runtime. pub mod constants; use bifrost_flexible_fee::fee_dealer::{FeeDealer, FixedCurrencyFeeRate}; -use bifrost_runtime_common::xcm_impl::{ - BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, - BifrostFilteredAssets, BifrostXcmTransactFilter, +use bifrost_runtime_common::{ + xcm_impl::{ + BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert, + BifrostFilteredAssets, BifrostXcmTransactFilter, + }, + SlowAdjustingFeeUpdate, }; use codec::{Decode, Encode}; use constants::{currency::*, time::*}; @@ -640,7 +643,7 @@ impl pallet_tips::Config for Runtime { } impl pallet_transaction_payment::Config for Runtime { - type FeeMultiplierUpdate = (); + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; type OnChargeTransaction = FlexibleFee; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee;