From 2cbddd0b85e0293d0eeda859807ddf70cee29067 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 8 Sep 2022 16:42:32 +0000 Subject: [PATCH 1/8] fix: FeeMultiplierUpdate --- bin/node-template/runtime/src/lib.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index e28a3bb2adb9d..8cc89d6a26cd0 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -38,10 +38,10 @@ pub use frame_support::{ pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; -use pallet_transaction_payment::CurrencyAdapter; +use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -pub use sp_runtime::{Perbill, Permill}; +pub use sp_runtime::{Perbill, Permill, Perquintill, FixedPointNumber}; /// Import the template pallet. pub use pallet_template; @@ -251,13 +251,32 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; } +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(75, 1000_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`](https://github.com/paritytech/polkadot/blob/87d6cfc7c0531d888898c9bbd1a1e299538a546b/runtime/polkadot/src/lib.rs#L2296-L2307). + pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 10u128); +} + +/// Parameterized slow adjusting fee updated based on +/// https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism +pub type SlowAdjustingFeeUpdate = + TargetedFeeAdjustment; + + impl pallet_transaction_payment::Config for Runtime { type Event = Event; type OnChargeTransaction = CurrencyAdapter; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; type LengthToFee = IdentityFee; - type FeeMultiplierUpdate = (); + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; } impl pallet_sudo::Config for Runtime { From 13016527bdbc53d9484642d6b52430550c0efc55 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 8 Sep 2022 17:11:35 +0000 Subject: [PATCH 2/8] fix: cargo fmt --- bin/node-template/runtime/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 8cc89d6a26cd0..a7f44c57aa8cd 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -41,7 +41,7 @@ pub use pallet_timestamp::Call as TimestampCall; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -pub use sp_runtime::{Perbill, Permill, Perquintill, FixedPointNumber}; +pub use sp_runtime::{FixedPointNumber, Perbill, Permill, Perquintill}; /// Import the template pallet. pub use pallet_template; @@ -269,7 +269,6 @@ parameter_types! { pub type SlowAdjustingFeeUpdate = TargetedFeeAdjustment; - impl pallet_transaction_payment::Config for Runtime { type Event = Event; type OnChargeTransaction = CurrencyAdapter; From 96b6ad80a4cd4d856cf5a830889858c4dd4c385b Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 8 Sep 2022 17:15:52 +0000 Subject: [PATCH 3/8] fix: rustdoc --- bin/node-template/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index a7f44c57aa8cd..8a2b31ce9c8cb 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -265,7 +265,7 @@ parameter_types! { } /// Parameterized slow adjusting fee updated based on -/// https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism +/// pub type SlowAdjustingFeeUpdate = TargetedFeeAdjustment; From 7c5e1f1a8235ca287ac1d8dc6716bffdc3e5252e Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Fri, 9 Sep 2022 10:53:48 +0000 Subject: [PATCH 4/8] Revert "fix: rustdoc" This reverts commit 96b6ad80a4cd4d856cf5a830889858c4dd4c385b. --- bin/node-template/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 8a2b31ce9c8cb..a7f44c57aa8cd 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -265,7 +265,7 @@ parameter_types! { } /// Parameterized slow adjusting fee updated based on -/// +/// https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism pub type SlowAdjustingFeeUpdate = TargetedFeeAdjustment; From cf6789eb99981cd94d4abdc5ab5e56922f9e529b Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Fri, 9 Sep 2022 10:53:51 +0000 Subject: [PATCH 5/8] Revert "fix: cargo fmt" This reverts commit 13016527bdbc53d9484642d6b52430550c0efc55. --- bin/node-template/runtime/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index a7f44c57aa8cd..8cc89d6a26cd0 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -41,7 +41,7 @@ pub use pallet_timestamp::Call as TimestampCall; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -pub use sp_runtime::{FixedPointNumber, Perbill, Permill, Perquintill}; +pub use sp_runtime::{Perbill, Permill, Perquintill, FixedPointNumber}; /// Import the template pallet. pub use pallet_template; @@ -269,6 +269,7 @@ parameter_types! { pub type SlowAdjustingFeeUpdate = TargetedFeeAdjustment; + impl pallet_transaction_payment::Config for Runtime { type Event = Event; type OnChargeTransaction = CurrencyAdapter; From c52697986582b48b306375489b2082bc2fcf1a18 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Fri, 9 Sep 2022 10:53:54 +0000 Subject: [PATCH 6/8] Revert "fix: FeeMultiplierUpdate" This reverts commit 2cbddd0b85e0293d0eeda859807ddf70cee29067. --- bin/node-template/runtime/src/lib.rs | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 8cc89d6a26cd0..e28a3bb2adb9d 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -38,10 +38,10 @@ pub use frame_support::{ pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; -use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; +use pallet_transaction_payment::CurrencyAdapter; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -pub use sp_runtime::{Perbill, Permill, Perquintill, FixedPointNumber}; +pub use sp_runtime::{Perbill, Permill}; /// Import the template pallet. pub use pallet_template; @@ -251,32 +251,13 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; } -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(75, 1000_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`](https://github.com/paritytech/polkadot/blob/87d6cfc7c0531d888898c9bbd1a1e299538a546b/runtime/polkadot/src/lib.rs#L2296-L2307). - pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 10u128); -} - -/// Parameterized slow adjusting fee updated based on -/// https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism -pub type SlowAdjustingFeeUpdate = - TargetedFeeAdjustment; - - impl pallet_transaction_payment::Config for Runtime { type Event = Event; type OnChargeTransaction = CurrencyAdapter; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; type LengthToFee = IdentityFee; - type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; + type FeeMultiplierUpdate = (); } impl pallet_sudo::Config for Runtime { From 7da5f441d405e723514f3764a5d51edac3c29aaf Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Fri, 9 Sep 2022 11:28:44 +0000 Subject: [PATCH 7/8] feat: add ConstFeeMultiplier --- frame/transaction-payment/src/lib.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index cbdc9dcb1e846..b3c53cc048bad 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -226,6 +226,30 @@ where } } +/// A struct to make the fee multiplier a constant +pub struct ConstFeeMultiplier>(sp_std::marker::PhantomData); + +impl> MultiplierUpdate for ConstFeeMultiplier { + fn min() -> Multiplier { + M::get() + } + fn target() -> Perquintill { + Default::default() + } + fn variability() -> Multiplier { + Default::default() + } +} + +impl Convert for ConstFeeMultiplier +where + M: Get, +{ + fn convert(_previous: Multiplier) -> Multiplier { + Self::min() + } +} + /// Storage releases of the pallet. #[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] enum Releases { @@ -371,7 +395,8 @@ pub mod pallet { // add 1 percent; let addition = target / 100; if addition == Weight::zero() { - // this is most likely because in a test setup we set everything to (). + // this is most likely because in a test setup we set everything to () + // or to `ConstFeeMultiplier`. return } From 753e48b3a50dba1e2ef097fbc8d1017377febc56 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Fri, 9 Sep 2022 11:29:50 +0000 Subject: [PATCH 8/8] fix: use cConstFeeMultiplier in the template node --- bin/node-template/runtime/src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index e28a3bb2adb9d..e9c2800ffa3f5 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -14,7 +14,9 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, Verify}, + traits::{ + AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, One, Verify, + }, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, MultiSignature, }; @@ -38,7 +40,7 @@ pub use frame_support::{ pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; -use pallet_transaction_payment::CurrencyAdapter; +use pallet_transaction_payment::{ConstFeeMultiplier, CurrencyAdapter, Multiplier}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; @@ -251,13 +253,17 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; } +parameter_types! { + pub FeeMultiplier: Multiplier = Multiplier::one(); +} + impl pallet_transaction_payment::Config for Runtime { type Event = Event; type OnChargeTransaction = CurrencyAdapter; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; type LengthToFee = IdentityFee; - type FeeMultiplierUpdate = (); + type FeeMultiplierUpdate = ConstFeeMultiplier; } impl pallet_sudo::Config for Runtime {