diff --git a/prdoc/pr_4970.prdoc b/prdoc/pr_4970.prdoc new file mode 100644 index 000000000000..d86f1af1e860 --- /dev/null +++ b/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 diff --git a/substrate/frame/transaction-payment/src/lib.rs b/substrate/frame/transaction-payment/src/lib.rs index 69fad6e0e324..7df658a4732e 100644 --- a/substrate/frame/transaction-payment/src/lib.rs +++ b/substrate/frame/transaction-payment/src/lib.rs @@ -207,7 +207,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); @@ -291,7 +291,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. @@ -394,12 +394,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 { @@ -433,7 +432,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); }); } @@ -471,7 +470,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, @@ -484,6 +483,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 @@ -633,7 +637,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); @@ -675,7 +679,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)); }); }