mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Allow fee calculation to happen off-chain (#6076)
* Emit a PaymentParameters event once per block This contains per-block paramaters need to calculate fees off-chain. * Add WeightToFee trait * Add documentation to polynomial types * Ignore pseudo code snippet for doc tests * Use `Mul` implementation of Perbill * Add tests for WeightToFeePolynomial * Revert "Emit a PaymentParameters event once per block" This reverts commit 6c4763baff3d8179676a3c1660fe7063fd56a8ca. Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
committed by
GitHub
parent
e04f237152
commit
9dd21b1eed
@@ -21,7 +21,9 @@ use core::num::NonZeroI128;
|
||||
use node_primitives::Balance;
|
||||
use sp_runtime::traits::{Convert, Saturating};
|
||||
use sp_runtime::{Fixed128, Perquintill};
|
||||
use frame_support::{traits::{OnUnbalanced, Currency, Get}, weights::Weight};
|
||||
use frame_support::{
|
||||
traits::{OnUnbalanced, Currency, Get},
|
||||
};
|
||||
use crate::{Balances, System, Authorship, MaximumBlockWeight, NegativeImbalance};
|
||||
|
||||
pub struct Author;
|
||||
@@ -47,18 +49,6 @@ impl Convert<u128, Balance> for CurrencyToVoteHandler {
|
||||
fn convert(x: u128) -> Balance { x * Self::factor() }
|
||||
}
|
||||
|
||||
/// Convert from weight to balance via a simple coefficient multiplication
|
||||
/// The associated type C encapsulates a constant in units of balance per weight
|
||||
pub struct LinearWeightToFee<C>(sp_std::marker::PhantomData<C>);
|
||||
|
||||
impl<C: Get<Balance>> Convert<Weight, Balance> for LinearWeightToFee<C> {
|
||||
fn convert(w: Weight) -> Balance {
|
||||
// setting this to zero will disable the weight fee.
|
||||
let coefficient = C::get();
|
||||
Balance::from(w).saturating_mul(coefficient)
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the given multiplier based on the following formula
|
||||
///
|
||||
/// diff = (previous_block_weight - target_weight)/max_weight
|
||||
@@ -120,7 +110,7 @@ mod tests {
|
||||
use sp_runtime::assert_eq_error_rate;
|
||||
use crate::{MaximumBlockWeight, AvailableBlockRatio, Runtime};
|
||||
use crate::{constants::currency::*, TransactionPayment, TargetBlockFullness};
|
||||
use frame_support::weights::Weight;
|
||||
use frame_support::weights::{Weight, WeightToFeePolynomial};
|
||||
use core::num::NonZeroI128;
|
||||
|
||||
fn max() -> Weight {
|
||||
@@ -228,7 +218,8 @@ mod tests {
|
||||
if fm == next { panic!("The fee should ever increase"); }
|
||||
fm = next;
|
||||
iterations += 1;
|
||||
let fee = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(tx_weight);
|
||||
let fee =
|
||||
<Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&tx_weight);
|
||||
let adjusted_fee = fm.saturated_multiply_accumulate(fee);
|
||||
println!(
|
||||
"iteration {}, new fm = {:?}. Fee at this point is: {} units / {} millicents, \
|
||||
|
||||
Reference in New Issue
Block a user