From bca17eea06bdc5fbfe7522b127da70a89c145c30 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Wed, 2 Feb 2022 14:13:32 -0700 Subject: [PATCH 01/17] Apply WeightToFeePolynomials to length fee --- frame/transaction-payment/src/lib.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 16d2ff5827c4f..deb4225c17bc2 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -292,6 +292,9 @@ pub mod pallet { /// Convert a weight value into a deductible fee based on the currency type. type WeightToFee: WeightToFeePolynomial>; + /// Convert a length value into a deductible fee based on the currency type. + type LengthToFee: WeightToFeePolynomial>; + /// Update the multiplier of the next block, based on the previous block's weight. type FeeMultiplierUpdate: MultiplierUpdate; } @@ -304,6 +307,12 @@ pub mod pallet { fn WeightToFee() -> Vec>> { T::WeightToFee::polynomial().to_vec() } + + #[allow(non_snake_case)] + /// The polynomial that is a pplied in order to derive fee from length. + fn LengthToFee() -> Vec>> { + T::LengthToFee::polynomial().to_vec() + } } #[pallet::type_value] @@ -512,23 +521,22 @@ where class: DispatchClass, ) -> FeeDetails> { if pays_fee == Pays::Yes { - let len = >::from(len); let per_byte = T::TransactionByteFee::get(); - // length fee. this is not adjusted. - let fixed_len_fee = per_byte.saturating_mul(len); - // the adjustable part of the fee. let unadjusted_weight_fee = Self::weight_to_fee(weight); let multiplier = Self::next_fee_multiplier(); // final adjusted weight fee. let adjusted_weight_fee = multiplier.saturating_mul_int(unadjusted_weight_fee); + // length fee. this is adjusted via LengthToFee + let len_fee = Self::length_to_fee(len).saturating_mul(per_byte); + let base_fee = Self::weight_to_fee(T::BlockWeights::get().get(class).base_extrinsic); FeeDetails { inclusion_fee: Some(InclusionFee { base_fee, - len_fee: fixed_len_fee, + len_fee, adjusted_weight_fee, }), tip, @@ -538,6 +546,10 @@ where } } + fn length_to_fee(length: u32) -> BalanceOf { + T::LengthToFee::calc(&(length as u64)) // TODO: saturating / upper bound + } + fn weight_to_fee(weight: Weight) -> BalanceOf { // cap the weight to the maximum defined in runtime, otherwise it will be the // `Bounded` maximum of its data type, which is not desired. From 5276cd7fcc36e84643c37b9489d863b626b3b11c Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 24 Feb 2022 13:44:59 -0700 Subject: [PATCH 02/17] Remove TransactionByteFee --- bin/node-template/runtime/src/lib.rs | 6 +----- bin/node/runtime/src/lib.rs | 4 ++-- frame/support/src/weights.rs | 21 +++++++++++++++++++++ frame/transaction-payment/src/lib.rs | 10 +--------- frame/transaction-payment/src/payment.rs | 1 - 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 0b39d76fe495e..82255757b7f34 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -249,15 +249,11 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; } -parameter_types! { - pub const TransactionByteFee: Balance = 1; -} - impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter; - type TransactionByteFee = TransactionByteFee; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; + type LengthToFee = IdentityFee; type FeeMultiplierUpdate = (); } diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index e70adc6aa7238..a63d913b1f90d 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -33,7 +33,7 @@ use frame_support::{ }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, - DispatchClass, IdentityFee, Weight, + DispatchClass, IdentityFee, ConstantModifierFee, Weight, }, PalletId, RuntimeDebug, }; @@ -445,9 +445,9 @@ parameter_types! { impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter; - type TransactionByteFee = TransactionByteFee; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = IdentityFee; + type LengthToFee = ConstantModifierFee; type FeeMultiplierUpdate = TargetedFeeAdjustment; } diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index 65087c85d3265..2a8d4948882fb 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -128,6 +128,7 @@ //! - rustc 1.42.0 (b8cedc004 2020-03-09) use crate::dispatch::{DispatchError, DispatchErrorWithPostInfo, DispatchResultWithPostInfo}; +use crate::traits::Get; use codec::{Decode, Encode}; use scale_info::TypeInfo; #[cfg(feature = "std")] @@ -713,6 +714,26 @@ where } } +/// Implementor of `WeightToFeePolynomial` that uses a constant modifier. +pub struct ConstantModifierFee(sp_std::marker::PhantomData, sp_std::marker::PhantomData); + +impl WeightToFeePolynomial for ConstantModifierFee +where + T: BaseArithmetic + From + Copy + Unsigned, + M: Get, +{ + type Balance = T; + + fn polynomial() -> WeightToFeeCoefficients { + smallvec!(WeightToFeeCoefficient { + coeff_integer: M::get(), + coeff_frac: Perbill::zero(), + negative: false, + degree: 1, + }) + } +} + /// A struct holding value for each `DispatchClass`. #[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)] pub struct PerDispatchClass { diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index deb4225c17bc2..4e3ffa692b222 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -261,10 +261,6 @@ pub mod pallet { /// might be refunded. In the end the fees can be deposited. type OnChargeTransaction: OnChargeTransaction; - /// The fee to be paid for making a transaction; the per-byte portion. - #[pallet::constant] - type TransactionByteFee: Get>; - /// A fee mulitplier for `Operational` extrinsics to compute "virtual tip" to boost their /// `priority` /// @@ -521,8 +517,6 @@ where class: DispatchClass, ) -> FeeDetails> { if pays_fee == Pays::Yes { - let per_byte = T::TransactionByteFee::get(); - // the adjustable part of the fee. let unadjusted_weight_fee = Self::weight_to_fee(weight); let multiplier = Self::next_fee_multiplier(); @@ -530,7 +524,7 @@ where let adjusted_weight_fee = multiplier.saturating_mul_int(unadjusted_weight_fee); // length fee. this is adjusted via LengthToFee - let len_fee = Self::length_to_fee(len).saturating_mul(per_byte); + let len_fee = Self::length_to_fee(len); let base_fee = Self::weight_to_fee(T::BlockWeights::get().get(class).base_extrinsic); FeeDetails { @@ -849,7 +843,6 @@ mod tests { } parameter_types! { - pub static TransactionByteFee: u64 = 1; pub static WeightToFee: u64 = 1; pub static OperationalFeeMultiplier: u8 = 5; } @@ -927,7 +920,6 @@ mod tests { impl Config for Runtime { type OnChargeTransaction = CurrencyAdapter; - type TransactionByteFee = TransactionByteFee; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = WeightToFee; type FeeMultiplierUpdate = (); diff --git a/frame/transaction-payment/src/payment.rs b/frame/transaction-payment/src/payment.rs index 58e6ef63109a3..7df29575c43a8 100644 --- a/frame/transaction-payment/src/payment.rs +++ b/frame/transaction-payment/src/payment.rs @@ -73,7 +73,6 @@ pub struct CurrencyAdapter(PhantomData<(C, OU)>); impl OnChargeTransaction for CurrencyAdapter where T: Config, - T::TransactionByteFee: Get<::AccountId>>::Balance>, C: Currency<::AccountId>, C::PositiveImbalance: Imbalance< ::AccountId>>::Balance, From fc7486be37547d1a5d580cee7e9a8abd95226bd4 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 24 Feb 2022 14:31:49 -0700 Subject: [PATCH 03/17] Add test cases for ConstantModifierFee --- frame/support/src/weights.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index 2a8d4948882fb..7435bf8c20474 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -127,8 +127,10 @@ //! - Ubuntu 19.10 (GNU/Linux 5.3.0-18-generic x86_64) //! - rustc 1.42.0 (b8cedc004 2020-03-09) -use crate::dispatch::{DispatchError, DispatchErrorWithPostInfo, DispatchResultWithPostInfo}; -use crate::traits::Get; +use crate::{ + dispatch::{DispatchError, DispatchErrorWithPostInfo, DispatchResultWithPostInfo}, + traits::Get +}; use codec::{Decode, Encode}; use scale_info::TypeInfo; #[cfg(feature = "std")] @@ -715,7 +717,7 @@ where } /// Implementor of `WeightToFeePolynomial` that uses a constant modifier. -pub struct ConstantModifierFee(sp_std::marker::PhantomData, sp_std::marker::PhantomData); +pub struct ConstantModifierFee(sp_std::marker::PhantomData<(T, M)>); impl WeightToFeePolynomial for ConstantModifierFee where @@ -1008,4 +1010,13 @@ mod tests { assert_eq!(IdentityFee::::calc(&50), 50); assert_eq!(IdentityFee::::calc(&Weight::max_value()), Balance::max_value()); } + + #[test] + fn constant_fee_works() { + use crate::traits::ConstU128; + assert_eq!(ConstantModifierFee::>::calc(&0), 0); + assert_eq!(ConstantModifierFee::>::calc(&50), 500); + assert_eq!(ConstantModifierFee::>::calc(&16), 16384); + assert_eq!(ConstantModifierFee::>::calc(&2), u128::MAX); + } } From 829f286b65671686cb61b7732ab233bbf05e5f28 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 3 Mar 2022 14:00:30 -0700 Subject: [PATCH 04/17] Restore import --- frame/support/src/weights.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index 51d6594e742db..4e3687135cd70 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -130,7 +130,10 @@ mod paritydb_weights; mod rocksdb_weights; -use crate::dispatch::{DispatchError, DispatchErrorWithPostInfo, DispatchResultWithPostInfo}; +use crate::{ + dispatch::{DispatchError, DispatchErrorWithPostInfo, DispatchResultWithPostInfo}, + traits::Get, +}; use codec::{Decode, Encode}; use scale_info::TypeInfo; #[cfg(feature = "std")] From 2dd382204911b79610eef761f1d0c8ac3963fd88 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 3 Mar 2022 14:00:51 -0700 Subject: [PATCH 05/17] Use pallet::constant_name --- frame/transaction-payment/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index c1c9ea0133f95..9c1fcbc1de2ef 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -302,9 +302,9 @@ pub mod pallet { T::WeightToFee::polynomial().to_vec() } - #[allow(non_snake_case)] + #[pallet::constant_name(LengthToFee)] /// The polynomial that is a pplied in order to derive fee from length. - fn LengthToFee() -> Vec>> { + fn length_to_fee_polynomial() -> Vec>> { T::LengthToFee::polynomial().to_vec() } } From d14ccf3ea1e26e883169d988aa6562b07b10ec96 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 3 Mar 2022 14:13:57 -0700 Subject: [PATCH 06/17] Remove irrelevant TODO comment --- frame/transaction-payment/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 9c1fcbc1de2ef..abf89524d4e7a 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -539,7 +539,7 @@ where } fn length_to_fee(length: u32) -> BalanceOf { - T::LengthToFee::calc(&(length as u64)) // TODO: saturating / upper bound + T::LengthToFee::calc(&(length as u64)) } fn weight_to_fee(weight: Weight) -> BalanceOf { From 11c138dd8f07276b57b5cd223e72e1def4aa5a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 4 Mar 2022 12:23:33 +0100 Subject: [PATCH 07/17] Update frame/support/src/weights.rs --- frame/support/src/weights.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index 4e3687135cd70..d2285a6ab011f 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -712,7 +712,7 @@ where } } -/// Implementor of `WeightToFeePolynomial` that uses a constant modifier. +/// Implementor of [`WeightToFeePolynomial`] that uses a constant modifier. pub struct ConstantModifierFee(sp_std::marker::PhantomData<(T, M)>); impl WeightToFeePolynomial for ConstantModifierFee From 0ed5de4e962764d05980ba96d11fa2c28d52764f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 4 Mar 2022 12:23:38 +0100 Subject: [PATCH 08/17] Update frame/transaction-payment/src/lib.rs --- frame/transaction-payment/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index abf89524d4e7a..72aceb334a355 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -302,8 +302,8 @@ pub mod pallet { T::WeightToFee::polynomial().to_vec() } + /// The polynomial that is applied in order to derive fee from length. #[pallet::constant_name(LengthToFee)] - /// The polynomial that is a pplied in order to derive fee from length. fn length_to_fee_polynomial() -> Vec>> { T::LengthToFee::polynomial().to_vec() } From 34c6545fcc67b10a0eabdbac3d912e146ff75ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 4 Mar 2022 12:23:42 +0100 Subject: [PATCH 09/17] Update frame/transaction-payment/src/lib.rs --- frame/transaction-payment/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 72aceb334a355..8c0cd62614bc2 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -539,7 +539,7 @@ where } fn length_to_fee(length: u32) -> BalanceOf { - T::LengthToFee::calc(&(length as u64)) + T::LengthToFee::calc(&(length as Weight)) } fn weight_to_fee(weight: Weight) -> BalanceOf { From f8834ceb71ba35700a12b153891d72aac75b3649 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Mon, 4 Apr 2022 13:25:10 -0600 Subject: [PATCH 10/17] Update frame/transaction-payment/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- frame/transaction-payment/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 8c0cd62614bc2..117c5f599450e 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -521,7 +521,7 @@ where // final adjusted weight fee. let adjusted_weight_fee = multiplier.saturating_mul_int(unadjusted_weight_fee); - // length fee. this is adjusted via LengthToFee + // length fee. this is adjusted via `LengthToFee`. let len_fee = Self::length_to_fee(len); let base_fee = Self::weight_to_fee(T::BlockWeights::get().get(class).base_extrinsic); From dfbb5f56495ae881678efeb2819bd4ffd545dd5f Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Mon, 4 Apr 2022 15:26:47 -0600 Subject: [PATCH 11/17] s/ConstantModifierFee/ConstantMultiplier/ --- bin/node/runtime/src/lib.rs | 4 ++-- frame/support/src/weights.rs | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 7358f060556fe..fd2b51c58d435 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -33,7 +33,7 @@ use frame_support::{ }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, - DispatchClass, IdentityFee, ConstantModifierFee, Weight, + DispatchClass, IdentityFee, ConstantMultiplier, Weight, }, PalletId, RuntimeDebug, }; @@ -443,7 +443,7 @@ impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = IdentityFee; - type LengthToFee = ConstantModifierFee; + type LengthToFee = ConstantMultiplier; type FeeMultiplierUpdate = TargetedFeeAdjustment; } diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index d2285a6ab011f..f36e3b7e1ee71 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -712,10 +712,18 @@ where } } -/// Implementor of [`WeightToFeePolynomial`] that uses a constant modifier. -pub struct ConstantModifierFee(sp_std::marker::PhantomData<(T, M)>); +/// Implementor of [`WeightToFeePolynomial`] that uses a constant multiplier. +/// # Example +/// +/// ``` +/// // Results in a multiplier of 10 for each unit of weight (or length) +/// ConstantMultiplier::> +/// +/// ``` +/// +pub struct ConstantMultiplier(sp_std::marker::PhantomData<(T, M)>); -impl WeightToFeePolynomial for ConstantModifierFee +impl WeightToFeePolynomial for ConstantMultiplier where T: BaseArithmetic + From + Copy + Unsigned, M: Get, @@ -1010,9 +1018,9 @@ mod tests { #[test] fn constant_fee_works() { use crate::traits::ConstU128; - assert_eq!(ConstantModifierFee::>::calc(&0), 0); - assert_eq!(ConstantModifierFee::>::calc(&50), 500); - assert_eq!(ConstantModifierFee::>::calc(&16), 16384); - assert_eq!(ConstantModifierFee::>::calc(&2), u128::MAX); + assert_eq!(ConstantMultiplier::>::calc(&0), 0); + assert_eq!(ConstantMultiplier::>::calc(&50), 500); + assert_eq!(ConstantMultiplier::>::calc(&16), 16384); + assert_eq!(ConstantMultiplier::>::calc(&2), u128::MAX); } } From bef9e21d5be435c99602cc94af5281becf7f201d Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Wed, 6 Apr 2022 17:15:53 +0000 Subject: [PATCH 12/17] Impl LengthToFee for test configs --- frame/balances/src/tests_composite.rs | 2 +- frame/balances/src/tests_local.rs | 2 +- frame/balances/src/tests_reentrancy.rs | 2 +- frame/executive/src/lib.rs | 4 ++-- frame/transaction-payment/asset-tx-payment/src/tests.rs | 2 +- frame/transaction-payment/src/lib.rs | 3 ++- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/frame/balances/src/tests_composite.rs b/frame/balances/src/tests_composite.rs index a24be44927375..4a2cc1d91936d 100644 --- a/frame/balances/src/tests_composite.rs +++ b/frame/balances/src/tests_composite.rs @@ -78,9 +78,9 @@ impl frame_system::Config for Test { impl pallet_transaction_payment::Config for Test { type OnChargeTransaction = CurrencyAdapter, ()>; - type TransactionByteFee = ConstU64<1>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; + type LengthToFee = IdentityFee; type FeeMultiplierUpdate = (); } diff --git a/frame/balances/src/tests_local.rs b/frame/balances/src/tests_local.rs index ae56f3b1f0f2c..cfc7f84ab3a38 100644 --- a/frame/balances/src/tests_local.rs +++ b/frame/balances/src/tests_local.rs @@ -79,9 +79,9 @@ impl frame_system::Config for Test { impl pallet_transaction_payment::Config for Test { type OnChargeTransaction = CurrencyAdapter, ()>; - type TransactionByteFee = ConstU64<1>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; + type LengthToFee = IdentityFee; type FeeMultiplierUpdate = (); } diff --git a/frame/balances/src/tests_reentrancy.rs b/frame/balances/src/tests_reentrancy.rs index 4303efc2322c5..7037e9615afd8 100644 --- a/frame/balances/src/tests_reentrancy.rs +++ b/frame/balances/src/tests_reentrancy.rs @@ -85,9 +85,9 @@ impl frame_system::Config for Test { impl pallet_transaction_payment::Config for Test { type OnChargeTransaction = CurrencyAdapter, ()>; - type TransactionByteFee = ConstU64<1>; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; + type LengthToFee = IdentityFee; type FeeMultiplierUpdate = (); } diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index d19ea8127bad3..e84991731fb98 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -576,7 +576,7 @@ mod tests { ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, LockableCurrency, WithdrawReasons, }, - weights::{IdentityFee, RuntimeDbWeight, Weight, WeightToFeePolynomial}, + weights::{IdentityFee, ConstantMultiplier, RuntimeDbWeight, Weight, WeightToFeePolynomial}, }; use frame_system::{Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo}; use pallet_balances::Call as BalancesCall; @@ -787,9 +787,9 @@ mod tests { } impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter; - type TransactionByteFee = TransactionByteFee; type OperationalFeeMultiplier = ConstU8<5>; type WeightToFee = IdentityFee; + type LengthToFee = ConstantMultiplier; type FeeMultiplierUpdate = (); } impl custom::Config for Runtime {} diff --git a/frame/transaction-payment/asset-tx-payment/src/tests.rs b/frame/transaction-payment/asset-tx-payment/src/tests.rs index f2a1ad1406575..d72a288ac7a33 100644 --- a/frame/transaction-payment/asset-tx-payment/src/tests.rs +++ b/frame/transaction-payment/asset-tx-payment/src/tests.rs @@ -145,8 +145,8 @@ impl WeightToFeePolynomial for WeightToFee { impl pallet_transaction_payment::Config for Runtime { type OnChargeTransaction = CurrencyAdapter; - type TransactionByteFee = TransactionByteFee; type WeightToFee = WeightToFee; + type LengthToFee = WeightToFee; type FeeMultiplierUpdate = (); type OperationalFeeMultiplier = ConstU8<5>; } diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 117c5f599450e..a912c02ea8bd3 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -798,6 +798,7 @@ mod tests { weights::{ DispatchClass, DispatchInfo, GetDispatchInfo, PostDispatchInfo, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, + IdentityFee, }, }; use frame_system as system; @@ -920,6 +921,7 @@ mod tests { type OnChargeTransaction = CurrencyAdapter; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = WeightToFee; + type LengthToFee = IdentityFee; type FeeMultiplierUpdate = (); } @@ -955,7 +957,6 @@ mod tests { } fn set_constants(&self) { EXTRINSIC_BASE_WEIGHT.with(|v| *v.borrow_mut() = self.base_weight); - TRANSACTION_BYTE_FEE.with(|v| *v.borrow_mut() = self.byte_fee); WEIGHT_TO_FEE.with(|v| *v.borrow_mut() = self.weight_to_fee); } pub fn build(self) -> sp_io::TestExternalities { From e8a1b3acc2972f985a51e5c2bd4196dd44acdef3 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 6 Apr 2022 13:51:14 -0400 Subject: [PATCH 13/17] fmt --- bin/node/runtime/src/lib.rs | 2 +- frame/executive/src/lib.rs | 4 +++- frame/support/src/weights.rs | 2 -- frame/transaction-payment/src/lib.rs | 9 ++------- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index f9782f4dd1bd2..57584bed39b2c 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -35,7 +35,7 @@ use frame_support::{ }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, - DispatchClass, IdentityFee, ConstantMultiplier, Weight, + ConstantMultiplier, DispatchClass, IdentityFee, Weight, }, PalletId, RuntimeDebug, }; diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index e84991731fb98..de1cc3b916404 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -576,7 +576,9 @@ mod tests { ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, LockableCurrency, WithdrawReasons, }, - weights::{IdentityFee, ConstantMultiplier, RuntimeDbWeight, Weight, WeightToFeePolynomial}, + weights::{ + ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, WeightToFeePolynomial, + }, }; use frame_system::{Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo}; use pallet_balances::Call as BalancesCall; diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index 17e11b43e21f0..56db34611e21f 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -718,9 +718,7 @@ where /// ``` /// // Results in a multiplier of 10 for each unit of weight (or length) /// ConstantMultiplier::> -/// /// ``` -/// pub struct ConstantMultiplier(sp_std::marker::PhantomData<(T, M)>); impl WeightToFeePolynomial for ConstantMultiplier diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index a912c02ea8bd3..cef485861b324 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -526,11 +526,7 @@ where let base_fee = Self::weight_to_fee(T::BlockWeights::get().get(class).base_extrinsic); FeeDetails { - inclusion_fee: Some(InclusionFee { - base_fee, - len_fee, - adjusted_weight_fee, - }), + inclusion_fee: Some(InclusionFee { base_fee, len_fee, adjusted_weight_fee }), tip, } } else { @@ -796,9 +792,8 @@ mod tests { assert_noop, assert_ok, parameter_types, traits::{ConstU32, ConstU64, Currency, Imbalance, OnUnbalanced}, weights::{ - DispatchClass, DispatchInfo, GetDispatchInfo, PostDispatchInfo, Weight, + DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, PostDispatchInfo, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, - IdentityFee, }, }; use frame_system as system; From 5a9b0c5f695f4a92588c2e66ce7eec20ad1fa0c5 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Wed, 6 Apr 2022 18:17:06 +0000 Subject: [PATCH 14/17] Remove unused import --- frame/transaction-payment/src/payment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/transaction-payment/src/payment.rs b/frame/transaction-payment/src/payment.rs index 7df29575c43a8..5b4a613102792 100644 --- a/frame/transaction-payment/src/payment.rs +++ b/frame/transaction-payment/src/payment.rs @@ -12,7 +12,7 @@ use sp_runtime::{ use sp_std::{fmt::Debug, marker::PhantomData}; use frame_support::{ - traits::{Currency, ExistenceRequirement, Get, Imbalance, OnUnbalanced, WithdrawReasons}, + traits::{Currency, ExistenceRequirement, Imbalance, OnUnbalanced, WithdrawReasons}, unsigned::TransactionValidityError, }; From 51ee1c2ad831a7a7012d8ca88bfa8eda62da679a Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Wed, 6 Apr 2022 18:55:45 +0000 Subject: [PATCH 15/17] Impl WeightToFeePolynomial for byte fee in ExtBuilder --- frame/transaction-payment/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index cef485861b324..aab49f9ee3c20 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -838,6 +838,7 @@ mod tests { parameter_types! { pub static WeightToFee: u64 = 1; + pub static TransactionByteFee: u64 = 1; pub static OperationalFeeMultiplier: u8 = 5; } @@ -893,6 +894,19 @@ mod tests { } } + impl WeightToFeePolynomial for TransactionByteFee { + type Balance = u64; + + fn polynomial() -> WeightToFeeCoefficients { + smallvec![WeightToFeeCoefficient { + degree: 1, + coeff_frac: Perbill::zero(), + coeff_integer: TRANSACTION_BYTE_FEE.with(|v| *v.borrow()), + negative: false, + }] + } + } + thread_local! { static TIP_UNBALANCED_AMOUNT: RefCell = RefCell::new(0); static FEE_UNBALANCED_AMOUNT: RefCell = RefCell::new(0); @@ -916,7 +930,7 @@ mod tests { type OnChargeTransaction = CurrencyAdapter; type OperationalFeeMultiplier = OperationalFeeMultiplier; type WeightToFee = WeightToFee; - type LengthToFee = IdentityFee; + type LengthToFee = TransactionByteFee; type FeeMultiplierUpdate = (); } @@ -952,6 +966,7 @@ mod tests { } fn set_constants(&self) { EXTRINSIC_BASE_WEIGHT.with(|v| *v.borrow_mut() = self.base_weight); + TRANSACTION_BYTE_FEE.with(|v| *v.borrow_mut() = self.byte_fee); WEIGHT_TO_FEE.with(|v| *v.borrow_mut() = self.weight_to_fee); } pub fn build(self) -> sp_io::TestExternalities { From e3c37fbf53fbd95ea6064cf7da74a84eb95f49b3 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Wed, 6 Apr 2022 19:03:23 +0000 Subject: [PATCH 16/17] Remove unused import --- frame/transaction-payment/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index aab49f9ee3c20..4ec4fe901ffef 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -792,7 +792,7 @@ mod tests { assert_noop, assert_ok, parameter_types, traits::{ConstU32, ConstU64, Currency, Imbalance, OnUnbalanced}, weights::{ - DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, PostDispatchInfo, Weight, + DispatchClass, DispatchInfo, GetDispatchInfo, PostDispatchInfo, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, }; From 855fc05ab29547c29105f8c5c412c7e40e68a424 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Wed, 6 Apr 2022 17:34:34 -0400 Subject: [PATCH 17/17] fix doc --- frame/support/src/weights.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index 56db34611e21f..4c3fcaa0fd423 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -716,8 +716,10 @@ where /// # Example /// /// ``` +/// # use frame_support::traits::ConstU128; +/// # use frame_support::weights::ConstantMultiplier; /// // Results in a multiplier of 10 for each unit of weight (or length) -/// ConstantMultiplier::> +/// type LengthToFee = ConstantMultiplier::>; /// ``` pub struct ConstantMultiplier(sp_std::marker::PhantomData<(T, M)>);