Companion for #6076 (Allow fee calculation to happen off-chain) (#1111)

* Switch from Convert to WeightToFeePolynomial

* Bump

Co-authored-by: Gav Wood <gavin@parity.io>
This commit is contained in:
Alexander Theißen
2020-05-21 13:47:55 +02:00
committed by GitHub
parent 162baa62fb
commit b6829b6d21
10 changed files with 214 additions and 162 deletions
+16 -6
View File
@@ -46,8 +46,11 @@ pub mod time {
pub mod fee {
pub use sp_runtime::Perbill;
use primitives::Balance;
use frame_support::weights::Weight;
use sp_runtime::traits::Convert;
use runtime_common::ExtrinsicBaseWeight;
use frame_support::weights::{
WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients,
};
use smallvec::smallvec;
/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
@@ -63,10 +66,17 @@ pub mod fee {
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
pub struct WeightToFee;
impl Convert<Weight, Balance> for WeightToFee {
fn convert(x: Weight) -> Balance {
// in Kusama a weight of 10_000_000 (smallest non-zero weight) is mapped to 1/10 CENT:
Balance::from(x).saturating_mul(super::currency::CENTS / (10 * 10_000_000))
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
let p = super::currency::CENTS;
let q = 10 * Balance::from(ExtrinsicBaseWeight::get());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational_approximation(p % q, q),
coeff_integer: p / q,
}]
}
}
}