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
+7 -5
View File
@@ -454,12 +454,12 @@ mod tests {
use sp_core::H256;
use sp_runtime::{
generic::Era, Perbill, DispatchError, testing::{Digest, Header, Block},
traits::{Header as HeaderT, BlakeTwo256, IdentityLookup, Convert, ConvertInto},
traits::{Header as HeaderT, BlakeTwo256, IdentityLookup},
transaction_validity::{InvalidTransaction, UnknownTransaction, TransactionValidityError},
};
use frame_support::{
impl_outer_event, impl_outer_origin, parameter_types, impl_outer_dispatch,
weights::{Weight, RuntimeDbWeight},
weights::{Weight, RuntimeDbWeight, IdentityFee, WeightToFeePolynomial},
traits::{Currency, LockIdentifier, LockableCurrency, WithdrawReasons, WithdrawReason},
};
use frame_system::{self as system, Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo};
@@ -589,7 +589,7 @@ mod tests {
type Currency = Balances;
type OnTransactionPayment = ();
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
}
impl custom::Trait for Runtime {}
@@ -675,7 +675,8 @@ mod tests {
}.assimilate_storage(&mut t).unwrap();
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(2, 69)), sign_extra(1, 0, 0));
let weight = xt.get_dispatch_info().weight + <Runtime as frame_system::Trait>::ExtrinsicBaseWeight::get();
let fee: Balance = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(weight);
let fee: Balance
= <Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&weight);
let mut t = sp_io::TestExternalities::new(t);
t.execute_with(|| {
Executive::initialize_block(&Header::new(
@@ -871,7 +872,8 @@ mod tests {
);
let weight = xt.get_dispatch_info().weight
+ <Runtime as frame_system::Trait>::ExtrinsicBaseWeight::get();
let fee: Balance = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(weight);
let fee: Balance =
<Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&weight);
Executive::initialize_block(&Header::new(
1,
H256::default(),