diff --git a/runtime/common/src/fees.rs b/runtime/common/src/fees.rs index 22a4d247efa886ab765dffccf637f640521a2ac8..50e40df1feb60767890de542cbcbe431bda37226 100644 --- a/runtime/common/src/fees.rs +++ b/runtime/common/src/fees.rs @@ -41,23 +41,23 @@ use { }; /// A structure to implement Length to Fee conversion. -/// - `T`: The balance type. -/// - `U`: The system configuration type, providing access to block weights. -/// - `X`: A type providing the target block fullness. -pub struct LengthToFeeImpl<T, U, X>( - sp_std::marker::PhantomData<T>, - sp_std::marker::PhantomData<U>, - sp_std::marker::PhantomData<X>, +/// - `Balance`: The balance type. +/// - `Runtime`: The system configuration type, providing access to block weights. +/// - `Target`: A type providing the target block fullness. +pub struct LengthToFeeImpl<Balance, Runtime, Target>( + sp_std::marker::PhantomData<Balance>, + sp_std::marker::PhantomData<Runtime>, + sp_std::marker::PhantomData<Target>, ); /// Trait implementation for converting transaction length to fee. -impl<T, U, X> WeightToFee for LengthToFeeImpl<T, U, X> +impl<Balance, Runtime, Target> WeightToFee for LengthToFeeImpl<Balance, Runtime, Target> where - T: BaseArithmetic + From<u32> + Copy + Unsigned, - U: frame_system::Config + pallet_transaction_payment::Config, - X: Get<Perquintill>, + Balance: BaseArithmetic + From<u32> + Copy + Unsigned, + Runtime: frame_system::Config + pallet_transaction_payment::Config, + Target: Get<Perquintill>, { - type Balance = T; + type Balance = Balance; /// Function to convert weight to fee when "constant-fees" feature is not enabled. /// @@ -66,22 +66,22 @@ where /// it returns a zero fee. Otherwise, it calculates the fee based on the length in bytes. #[cfg(not(feature = "constant-fees"))] fn weight_to_fee(length_in_bytes: &Weight) -> Self::Balance { - let weights = U::BlockWeights::get(); - let fee_multiplier = pallet_transaction_payment::Pallet::<U>::next_fee_multiplier(); + let weights = Runtime::BlockWeights::get(); + let fee_multiplier = pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier(); let normal_max_weight = weights .get(DispatchClass::Normal) .max_total .unwrap_or(weights.max_block); - let current_block_weight = <frame_system::Pallet<U>>::block_weight(); + let current_block_weight = <frame_system::Pallet<Runtime>>::block_weight(); - let length = U::BlockLength::get(); + let length = Runtime::BlockLength::get(); let normal_max_length = *length.max.get(DispatchClass::Normal) as u64; - let current_block_length = <frame_system::Pallet<U>>::all_extrinsics_len() as u64; + let current_block_length = <frame_system::Pallet<Runtime>>::all_extrinsics_len() as u64; if current_block_weight .get(DispatchClass::Normal) - .all_lt(X::get() * normal_max_weight) - && current_block_length < (X::get() * normal_max_length) + .all_lt(Target::get() * normal_max_weight) + && current_block_length < (Target::get() * normal_max_length) && fee_multiplier.is_one() { 0u32.into() @@ -100,26 +100,26 @@ where } /// A structure to implement Weight to Fee conversion. -/// - `T`: The balance type. -/// - `U`: The system configuration type, providing access to block weights. -/// - `X`: A type providing the target block fullness. -pub struct WeightToFeeImpl<T, U, X>( - sp_std::marker::PhantomData<T>, - sp_std::marker::PhantomData<U>, - sp_std::marker::PhantomData<X>, +/// - `Balance`: The balance type. +/// - `Runtime`: The system configuration type, providing access to block weights. +/// - `Target`: A type providing the target block fullness. +pub struct WeightToFeeImpl<Balance, Runtime, Target>( + sp_std::marker::PhantomData<Balance>, + sp_std::marker::PhantomData<Runtime>, + sp_std::marker::PhantomData<Target>, ); /// Trait implementation for converting transaction weight to fee. /// /// This implementation is only included when the "constant-fees" feature is not enabled. #[cfg(not(feature = "constant-fees"))] -impl<T, U, X> WeightToFeePolynomial for WeightToFeeImpl<T, U, X> +impl<Balance, Runtime, Target> WeightToFeePolynomial for WeightToFeeImpl<Balance, Runtime, Target> where - T: BaseArithmetic + From<u64> + Copy + Unsigned + From<u32> + MultiplyRational, - U: frame_system::Config + pallet_transaction_payment::Config, - X: Get<Perquintill>, + Balance: BaseArithmetic + From<u64> + Copy + Unsigned + From<u32> + MultiplyRational, + Runtime: frame_system::Config + pallet_transaction_payment::Config, + Target: Get<Perquintill>, { - type Balance = T; + type Balance = Balance; /// Function to get the polynomial coefficients for weight to fee conversion. /// @@ -127,22 +127,22 @@ where /// If the current block weight and length are less than a fraction of the block max weight and length, and the fee multiplier is one, /// it returns zero. Otherwise, it calculates the coefficients based on the extrinsic base weight mapped to 5 cents. fn polynomial() -> WeightToFeeCoefficients<Self::Balance> { - let weights = U::BlockWeights::get(); - let fee_multiplier = pallet_transaction_payment::Pallet::<U>::next_fee_multiplier(); + let weights = Runtime::BlockWeights::get(); + let fee_multiplier = pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier(); let normal_max_weight = weights .get(DispatchClass::Normal) .max_total .unwrap_or(weights.max_block); - let current_block_weight = <frame_system::Pallet<U>>::block_weight(); + let current_block_weight = <frame_system::Pallet<Runtime>>::block_weight(); - let length = U::BlockLength::get(); + let length = Runtime::BlockLength::get(); let normal_max_length = *length.max.get(DispatchClass::Normal) as u64; - let current_block_length = <frame_system::Pallet<U>>::all_extrinsics_len() as u64; + let current_block_length = <frame_system::Pallet<Runtime>>::all_extrinsics_len() as u64; if current_block_weight .get(DispatchClass::Normal) - .all_lt(X::get() * normal_max_weight) - && current_block_length < (X::get() * normal_max_length) + .all_lt(Target::get() * normal_max_weight) + && current_block_length < (Target::get() * normal_max_length) && fee_multiplier.is_one() { smallvec![WeightToFeeCoefficient { @@ -169,11 +169,11 @@ where /// /// This implementation is only included when the "constant-fees" feature is enabled. #[cfg(feature = "constant-fees")] -impl<T, U, X> WeightToFee for WeightToFeeImpl<T, U, X> +impl<Balance, Runtime, Target> WeightToFee for WeightToFeeImpl<Balance, Runtime, Target> where - T: BaseArithmetic + From<u32> + Copy + Unsigned, + Balance: BaseArithmetic + From<u32> + Copy + Unsigned, { - type Balance = T; + type Balance = Balance; fn weight_to_fee(_weight: &Weight) -> Self::Balance { 1u32.into() @@ -182,32 +182,33 @@ where /// A structure to implement fee multiplier adjustments. /// -/// - `T`: The system configuration type. -/// - `S`: A type providing the target block fullness. -/// - `X`: A type providing the maximum multiplier value. -pub struct FeeMultiplier<T, S, X>( - sp_std::marker::PhantomData<T>, - sp_std::marker::PhantomData<S>, - sp_std::marker::PhantomData<X>, +/// - `Runtime`: The system configuration type. +/// - `Target`: A type providing the target block fullness. +/// - `MaxMultiplier`: A type providing the maximum multiplier value. +pub struct FeeMultiplier<Runtime, Target, MaxMultiplier>( + sp_std::marker::PhantomData<Runtime>, + sp_std::marker::PhantomData<Target>, + sp_std::marker::PhantomData<MaxMultiplier>, ); /// Trait implementation for updating the fee multiplier. -impl<T, S, X> MultiplierUpdate for FeeMultiplier<T, S, X> +impl<Runtime, Target, MaxMultiplier> MultiplierUpdate + for FeeMultiplier<Runtime, Target, MaxMultiplier> where - T: frame_system::Config, - S: Get<Perquintill>, - X: Get<Multiplier>, + Runtime: frame_system::Config, + Target: Get<Perquintill>, + MaxMultiplier: Get<Multiplier>, { fn min() -> Multiplier { 0.into() } fn max() -> Multiplier { - X::get() + MaxMultiplier::get() } fn target() -> Perquintill { - S::get() + Target::get() } fn variability() -> Multiplier { @@ -216,11 +217,12 @@ where } /// Trait implementation for converting previous `Multiplier` to another for fee adjustment. -impl<T, S, X> Convert<Multiplier, Multiplier> for FeeMultiplier<T, S, X> +impl<Runtime, Target, MaxMultiplier> Convert<Multiplier, Multiplier> + for FeeMultiplier<Runtime, Target, MaxMultiplier> where - T: frame_system::Config, - S: Get<Perquintill>, - X: Get<Multiplier>, + Runtime: frame_system::Config, + Target: Get<Perquintill>, + MaxMultiplier: Get<Multiplier>, { /// Function to convert the previous fee multiplier to a new fee multiplier. /// @@ -229,20 +231,20 @@ where /// - If the current block weight or length is more than the target, it increases the multiplier by one, up to the maximum multiplier. #[cfg(not(feature = "constant-fees"))] fn convert(previous: Multiplier) -> Multiplier { - let max_multiplier = X::get(); - let target_block_fullness = S::get(); + let max_multiplier = MaxMultiplier::get(); + let target_block_fullness = Target::get(); - let weights = T::BlockWeights::get(); + let weights = Runtime::BlockWeights::get(); let normal_max_weight = weights .get(DispatchClass::Normal) .max_total .unwrap_or(weights.max_block); - let length = T::BlockLength::get(); + let length = Runtime::BlockLength::get(); let normal_max_length = *length.max.get(DispatchClass::Normal) as u64; - let current_block_length = <frame_system::Pallet<T>>::all_extrinsics_len() as u64; + let current_block_length = <frame_system::Pallet<Runtime>>::all_extrinsics_len() as u64; - if <frame_system::Pallet<T>>::block_weight() + if <frame_system::Pallet<Runtime>>::block_weight() .get(DispatchClass::Normal) .all_lt(target_block_fullness * normal_max_weight) && current_block_length < (target_block_fullness * normal_max_length)