From 70d2ce1c098f69cd2e9be41bd9f0ffa9794e1907 Mon Sep 17 00:00:00 2001 From: Parth Mittal Date: Mon, 8 Jul 2024 17:10:25 +0530 Subject: [PATCH 1/3] Remove pallet-getter usage from the transaction-payment pallet --- .../frame/transaction-payment/src/lib.rs | 20 ++++++++++------- .../frame/transaction-payment/src/tests.rs | 22 +++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/substrate/frame/transaction-payment/src/lib.rs b/substrate/frame/transaction-payment/src/lib.rs index 0e440ee4e9ff..f744749da0a5 100644 --- a/substrate/frame/transaction-payment/src/lib.rs +++ b/substrate/frame/transaction-payment/src/lib.rs @@ -208,7 +208,7 @@ where // the computed ratio is only among the normal class. let normal_max_weight = weights.get(DispatchClass::Normal).max_total.unwrap_or(weights.max_block); - let current_block_weight = >::block_weight(); + let current_block_weight = frame_system::Pallet::::block_weight(); let normal_block_weight = current_block_weight.get(DispatchClass::Normal).min(normal_max_weight); @@ -292,7 +292,7 @@ where /// Storage releases of the pallet. #[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] -enum Releases { +pub enum Releases { /// Original version of the pallet. V1Ancient, /// One that bumps the usage to FixedU128 from FixedI128. @@ -395,12 +395,11 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn next_fee_multiplier)] pub type NextFeeMultiplier = StorageValue<_, Multiplier, ValueQuery, NextFeeMultiplierOnEmpty>; #[pallet::storage] - pub(super) type StorageVersion = StorageValue<_, Releases, ValueQuery>; + pub type StorageVersion = StorageValue<_, Releases, ValueQuery>; #[pallet::genesis_config] pub struct GenesisConfig { @@ -434,7 +433,7 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_finalize(_: frame_system::pallet_prelude::BlockNumberFor) { - >::mutate(|fm| { + NextFeeMultiplier::::mutate(|fm| { *fm = T::FeeMultiplierUpdate::convert(*fm); }); } @@ -472,7 +471,7 @@ pub mod pallet { let min_value = T::FeeMultiplierUpdate::min(); let target = target + addition; - >::set_block_consumed_resources(target, 0); + frame_system::Pallet::::set_block_consumed_resources(target, 0); let next = T::FeeMultiplierUpdate::convert(min_value); assert!( next > min_value, @@ -485,6 +484,11 @@ pub mod pallet { } impl Pallet { + /// Public function to access the next fee multiplier. + pub fn next_fee_multiplier() -> Multiplier { + NextFeeMultiplier::::get() + } + /// Query the data that we know about the fee of a given `call`. /// /// This pallet is not and cannot be aware of the internals of a signed extension, for example @@ -634,7 +638,7 @@ impl Pallet { if pays_fee == Pays::Yes { // the adjustable part of the fee. let unadjusted_weight_fee = Self::weight_to_fee(weight); - let multiplier = Self::next_fee_multiplier(); + let multiplier = NextFeeMultiplier::::get(); // final adjusted weight fee. let adjusted_weight_fee = multiplier.saturating_mul_int(unadjusted_weight_fee); @@ -676,7 +680,7 @@ where /// share that the weight contributes to the overall fee of a transaction. It is mainly /// for informational purposes and not used in the actual fee calculation. fn convert(weight: Weight) -> BalanceOf { - >::get().saturating_mul_int(Self::weight_to_fee(weight)) + NextFeeMultiplier::::get().saturating_mul_int(Self::weight_to_fee(weight)) } } diff --git a/substrate/frame/transaction-payment/src/tests.rs b/substrate/frame/transaction-payment/src/tests.rs index bc0efd2d64a3..35d5322a6f33 100644 --- a/substrate/frame/transaction-payment/src/tests.rs +++ b/substrate/frame/transaction-payment/src/tests.rs @@ -180,7 +180,7 @@ fn signed_extension_transaction_payment_multiplied_refund_works() { .build() .execute_with(|| { let len = 10; - >::put(Multiplier::saturating_from_rational(3, 2)); + NextFeeMultiplier::::put(Multiplier::saturating_from_rational(3, 2)); let pre = ChargeTransactionPayment::::from(5 /* tipped */) .pre_dispatch(&2, CALL, &info_from_weight(Weight::from_parts(100, 0)), len) @@ -270,7 +270,7 @@ fn signed_ext_length_fee_is_also_updated_per_congestion() { .build() .execute_with(|| { // all fees should be x1.5 - >::put(Multiplier::saturating_from_rational(3, 2)); + NextFeeMultiplier::::put(Multiplier::saturating_from_rational(3, 2)); let len = 10; assert_ok!(ChargeTransactionPayment::::from(10) // tipped @@ -305,7 +305,7 @@ fn query_info_and_fee_details_works() { .build() .execute_with(|| { // all fees should be x1.5 - >::put(Multiplier::saturating_from_rational(3, 2)); + NextFeeMultiplier::::put(Multiplier::saturating_from_rational(3, 2)); assert_eq!( TransactionPayment::query_info(xt.clone(), len), @@ -362,7 +362,7 @@ fn query_call_info_and_fee_details_works() { .build() .execute_with(|| { // all fees should be x1.5 - >::put(Multiplier::saturating_from_rational(3, 2)); + NextFeeMultiplier::::put(Multiplier::saturating_from_rational(3, 2)); assert_eq!( TransactionPayment::query_call_info(call.clone(), len), @@ -401,7 +401,7 @@ fn compute_fee_works_without_multiplier() { .build() .execute_with(|| { // Next fee multiplier is zero - assert_eq!(>::get(), Multiplier::one()); + assert_eq!(NextFeeMultiplier::::get(), Multiplier::one()); // Tip only, no fees works let dispatch_info = DispatchInfo { @@ -440,7 +440,7 @@ fn compute_fee_works_with_multiplier() { .build() .execute_with(|| { // Add a next fee multiplier. Fees will be x3/2. - >::put(Multiplier::saturating_from_rational(3, 2)); + NextFeeMultiplier::::put(Multiplier::saturating_from_rational(3, 2)); // Base fee is unaffected by multiplier let dispatch_info = DispatchInfo { weight: Weight::from_parts(0, 0), @@ -472,7 +472,7 @@ fn compute_fee_works_with_negative_multiplier() { .build() .execute_with(|| { // Add a next fee multiplier. All fees will be x1/2. - >::put(Multiplier::saturating_from_rational(1, 2)); + NextFeeMultiplier::::put(Multiplier::saturating_from_rational(1, 2)); // Base fee is unaffected by multiplier. let dispatch_info = DispatchInfo { @@ -637,7 +637,7 @@ fn refund_consistent_with_actual_weight() { let len = 10; let tip = 5; - >::put(Multiplier::saturating_from_rational(5, 4)); + NextFeeMultiplier::::put(Multiplier::saturating_from_rational(5, 4)); let pre = ChargeTransactionPayment::::from(tip) .pre_dispatch(&2, CALL, &info, len) @@ -797,7 +797,7 @@ fn post_info_can_change_pays_fee() { let len = 10; let tip = 5; - >::put(Multiplier::saturating_from_rational(5, 4)); + NextFeeMultiplier::::put(Multiplier::saturating_from_rational(5, 4)); let pre = ChargeTransactionPayment::::from(tip) .pre_dispatch(&2, CALL, &info, len) @@ -829,7 +829,7 @@ fn genesis_config_works() { .build() .execute_with(|| { assert_eq!( - >::get(), + NextFeeMultiplier::::get(), Multiplier::saturating_from_integer(100) ); }); @@ -838,6 +838,6 @@ fn genesis_config_works() { #[test] fn genesis_default_works() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(>::get(), Multiplier::saturating_from_integer(1)); + assert_eq!(NextFeeMultiplier::::get(), Multiplier::saturating_from_integer(1)); }); } From a44a81693dece9b6de7a594e96e701c4f4f69aea Mon Sep 17 00:00:00 2001 From: Parth Mittal Date: Mon, 8 Jul 2024 17:16:02 +0530 Subject: [PATCH 2/3] Add PR doc --- .../transaction-payment/src/prdoc/pr_4970.prdoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 substrate/frame/transaction-payment/src/prdoc/pr_4970.prdoc diff --git a/substrate/frame/transaction-payment/src/prdoc/pr_4970.prdoc b/substrate/frame/transaction-payment/src/prdoc/pr_4970.prdoc new file mode 100644 index 000000000000..d86f1af1e860 --- /dev/null +++ b/substrate/frame/transaction-payment/src/prdoc/pr_4970.prdoc @@ -0,0 +1,14 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: "Remove `pallet::getter` usage from the transaction-payment pallet" + +doc: + - audience: Runtime Dev + description: | + This PR removes the `pallet::getter`s from `pallet-transaction-payment`. + The syntax `StorageItem::::get()` should be used instead. + +crates: + - name: pallet-transaction-payment + bump: minor From ae1dc6a8993532e764bca93d1a5c09babb242d11 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 23 Jul 2024 12:35:22 +0200 Subject: [PATCH 3/3] Move prdoc Signed-off-by: Oliver Tale-Yazdi --- .../frame/transaction-payment/src/prdoc => prdoc}/pr_4970.prdoc | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {substrate/frame/transaction-payment/src/prdoc => prdoc}/pr_4970.prdoc (100%) diff --git a/substrate/frame/transaction-payment/src/prdoc/pr_4970.prdoc b/prdoc/pr_4970.prdoc similarity index 100% rename from substrate/frame/transaction-payment/src/prdoc/pr_4970.prdoc rename to prdoc/pr_4970.prdoc