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:
Alexander Theißen
2020-05-21 12:16:04 +02:00
committed by GitHub
parent e04f237152
commit 9dd21b1eed
14 changed files with 241 additions and 79 deletions
+5 -6
View File
@@ -26,7 +26,7 @@ use sp_std::prelude::*;
use frame_support::{
construct_runtime, parameter_types, debug,
weights::{
Weight,
Weight, IdentityFee,
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
},
traits::{Currency, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness, LockIdentifier},
@@ -74,7 +74,7 @@ pub use pallet_staking::StakerStatus;
/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
use impls::{CurrencyToVoteHandler, Author, LinearWeightToFee, TargetedFeeAdjustment};
use impls::{CurrencyToVoteHandler, Author, TargetedFeeAdjustment};
/// Constant values used within the runtime.
pub mod constants;
@@ -228,9 +228,6 @@ impl pallet_balances::Trait for Runtime {
parameter_types! {
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
// In the Substrate node, a weight of 10_000_000 (smallest non-zero weight)
// is mapped to 10_000_000 units of fees, hence:
pub const WeightFeeCoefficient: Balance = 1;
// for a sane configuration, this should always be less than `AvailableBlockRatio`.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
}
@@ -239,7 +236,9 @@ impl pallet_transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = DealWithFees;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = LinearWeightToFee<WeightFeeCoefficient>;
// In the Substrate node, a weight of 10_000_000 (smallest non-zero weight)
// is mapped to 10_000_000 units of fees, hence:
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = TargetedFeeAdjustment<TargetBlockFullness>;
}