mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
Apply WeightToFeePolynomials to pallet_transaction_payment's length fee (#10785)
* Apply WeightToFeePolynomials to length fee * Remove TransactionByteFee * Add test cases for ConstantModifierFee * Restore import * Use pallet::constant_name * Remove irrelevant TODO comment * Update frame/support/src/weights.rs * Update frame/transaction-payment/src/lib.rs * Update frame/transaction-payment/src/lib.rs * Update frame/transaction-payment/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * s/ConstantModifierFee/ConstantMultiplier/ * Impl LengthToFee for test configs * fmt * Remove unused import * Impl WeightToFeePolynomial for byte fee in ExtBuilder * Remove unused import * fix doc Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -260,10 +260,6 @@ pub mod pallet {
|
||||
/// might be refunded. In the end the fees can be deposited.
|
||||
type OnChargeTransaction: OnChargeTransaction<Self>;
|
||||
|
||||
/// The fee to be paid for making a transaction; the per-byte portion.
|
||||
#[pallet::constant]
|
||||
type TransactionByteFee: Get<BalanceOf<Self>>;
|
||||
|
||||
/// A fee mulitplier for `Operational` extrinsics to compute "virtual tip" to boost their
|
||||
/// `priority`
|
||||
///
|
||||
@@ -291,6 +287,9 @@ pub mod pallet {
|
||||
/// Convert a weight value into a deductible fee based on the currency type.
|
||||
type WeightToFee: WeightToFeePolynomial<Balance = BalanceOf<Self>>;
|
||||
|
||||
/// Convert a length value into a deductible fee based on the currency type.
|
||||
type LengthToFee: WeightToFeePolynomial<Balance = BalanceOf<Self>>;
|
||||
|
||||
/// Update the multiplier of the next block, based on the previous block's weight.
|
||||
type FeeMultiplierUpdate: MultiplierUpdate;
|
||||
}
|
||||
@@ -302,6 +301,12 @@ pub mod pallet {
|
||||
fn weight_to_fee_polynomial() -> Vec<WeightToFeeCoefficient<BalanceOf<T>>> {
|
||||
T::WeightToFee::polynomial().to_vec()
|
||||
}
|
||||
|
||||
/// The polynomial that is applied in order to derive fee from length.
|
||||
#[pallet::constant_name(LengthToFee)]
|
||||
fn length_to_fee_polynomial() -> Vec<WeightToFeeCoefficient<BalanceOf<T>>> {
|
||||
T::LengthToFee::polynomial().to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::type_value]
|
||||
@@ -510,25 +515,18 @@ where
|
||||
class: DispatchClass,
|
||||
) -> FeeDetails<BalanceOf<T>> {
|
||||
if pays_fee == Pays::Yes {
|
||||
let len = <BalanceOf<T>>::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);
|
||||
|
||||
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,
|
||||
adjusted_weight_fee,
|
||||
}),
|
||||
inclusion_fee: Some(InclusionFee { base_fee, len_fee, adjusted_weight_fee }),
|
||||
tip,
|
||||
}
|
||||
} else {
|
||||
@@ -536,6 +534,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn length_to_fee(length: u32) -> BalanceOf<T> {
|
||||
T::LengthToFee::calc(&(length as Weight))
|
||||
}
|
||||
|
||||
fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
|
||||
// cap the weight to the maximum defined in runtime, otherwise it will be the
|
||||
// `Bounded` maximum of its data type, which is not desired.
|
||||
@@ -835,8 +837,8 @@ mod tests {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub static TransactionByteFee: u64 = 1;
|
||||
pub static WeightToFee: u64 = 1;
|
||||
pub static TransactionByteFee: u64 = 1;
|
||||
pub static OperationalFeeMultiplier: u8 = 5;
|
||||
}
|
||||
|
||||
@@ -892,6 +894,19 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
impl WeightToFeePolynomial for TransactionByteFee {
|
||||
type Balance = u64;
|
||||
|
||||
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
|
||||
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<u64> = RefCell::new(0);
|
||||
static FEE_UNBALANCED_AMOUNT: RefCell<u64> = RefCell::new(0);
|
||||
@@ -913,9 +928,9 @@ mod tests {
|
||||
|
||||
impl Config for Runtime {
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
|
||||
type TransactionByteFee = TransactionByteFee;
|
||||
type OperationalFeeMultiplier = OperationalFeeMultiplier;
|
||||
type WeightToFee = WeightToFee;
|
||||
type LengthToFee = TransactionByteFee;
|
||||
type FeeMultiplierUpdate = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -73,7 +73,6 @@ pub struct CurrencyAdapter<C, OU>(PhantomData<(C, OU)>);
|
||||
impl<T, C, OU> OnChargeTransaction<T> for CurrencyAdapter<C, OU>
|
||||
where
|
||||
T: Config,
|
||||
T::TransactionByteFee: Get<<C as Currency<<T as frame_system::Config>::AccountId>>::Balance>,
|
||||
C: Currency<<T as frame_system::Config>::AccountId>,
|
||||
C::PositiveImbalance: Imbalance<
|
||||
<C as Currency<<T as frame_system::Config>::AccountId>>::Balance,
|
||||
|
||||
Reference in New Issue
Block a user