Trait common_runtime::fees::WeightToFee

pub trait WeightToFee {
    type Balance: BaseArithmetic + From<u32> + Copy + Unsigned;

    // Required method
    fn weight_to_fee(weight: &Weight) -> Self::Balance;
}
Expand description

In our deployed fee model, users will not pay any fees if blockchain usage remains below a specified threshold, and fees are applied based on transaction weight and length once this threshold is exceeded, helping to prevent spamming attacks.

When the current block’s weight and length are below the targeted thresholds, no fees are charged, as the weight-to-fee conversion results in zero. Once the block’s weight and length exceed these targets, the weight-to-fee conversion maps BASE_EXTRINSIC_WEIGHT_COST to a base extrinsic weight. Additionally, a fee is applied based on the length of the extrinsic and is mapped affinely: 2_000 (20G) corresponds to an extrinsic length of BYTES_PER_UNIT*10 plus the BASE_EXTRINSIC_LENGTH_COST and will be applied only if the extrinsic exceeds MAX_EXTRINSIC_LENGTH bytes or if the block target in weight or length is surpassed.

To further deter abuse, if the previous block’s weight or length the target thresholds, the chain increases the fees by multiplying the transaction weight with a FeeMultiplier. For each consecutive block that exceeds the targets, this multiplier increases by one. If the targets are not reached, the multiplier decreases by one. The FeeMultiplier ranges from 1 (normal usage) to MaxMultiplier, where heavy usage causes a number MaxMultiplier of consecutive blocks to exceed targets.

For testing purposes, a simplified, human-predictable weight system is used. This test model sets a constant weight_to_fee of 1 and a length_to_fee of 0, making each extrinsic cost 2 (2cG), and can be activated with the #[cfg(feature = “constant-fees”)] feature. A trait that describes the weight to fee calculation.

Required Associated Types§

type Balance: BaseArithmetic + From<u32> + Copy + Unsigned

The type that is returned as result from calculation.

Required Methods§

fn weight_to_fee(weight: &Weight) -> Self::Balance

Calculates the fee from the passed weight.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Balance, Runtime, Target> WeightToFee for LengthToFeeImpl<Balance, Runtime, Target>
where Balance: BaseArithmetic + From<u32> + Copy + Unsigned, Runtime: Config + Config, Target: Get<Perquintill>,

Trait implementation for converting transaction length to fee.

§

type Balance = Balance

§

impl<T> WeightToFee for IdentityFee<T>
where T: BaseArithmetic + From<u32> + Copy + Unsigned,

§

type Balance = T

§

impl<T> WeightToFee for T
where T: WeightToFeePolynomial,

§

type Balance = <T as WeightToFeePolynomial>::Balance

§

impl<T, M> WeightToFee for ConstantMultiplier<T, M>
where T: BaseArithmetic + From<u32> + Copy + Unsigned, M: Get<T>,

§

type Balance = T

§

impl<const F: u32, T> WeightToFee for FixedFee<F, T>
where T: BaseArithmetic + From<u32> + Copy + Unsigned,

§

type Balance = T