diff --git a/node/executor/src/lib.rs b/node/executor/src/lib.rs index f5cb7c8c64bb6..cb8627f65beab 100644 --- a/node/executor/src/lib.rs +++ b/node/executor/src/lib.rs @@ -56,8 +56,9 @@ mod tests { use node_runtime::{ Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances, BuildStorage, System, TransactionPayment, Event, TransferFee, TransactionBaseFee, TransactionByteFee, - WeightToFee, constants::currency::*, + WeightFeeCoefficient, constants::currency::*, }; + use node_runtime::impls::LinearWeightToFee; use node_primitives::{Balance, Hash, BlockNumber}; use node_testing::keyring::*; use wabt; @@ -1046,7 +1047,7 @@ mod tests { balance_alice -= length_fee; let weight = default_transfer_call().get_dispatch_info().weight; - let weight_fee = WeightToFee::convert(weight); + let weight_fee = LinearWeightToFee::::convert(weight); // we know that weight to fee multiplier is effect-less in block 1. assert_eq!(weight_fee as Balance, MILLICENTS); diff --git a/node/runtime/src/impls.rs b/node/runtime/src/impls.rs index ae53c59a057a5..26a90fe6097f8 100644 --- a/node/runtime/src/impls.rs +++ b/node/runtime/src/impls.rs @@ -22,7 +22,7 @@ use sr_primitives::traits::{Convert, Saturating}; use sr_primitives::{Fixed64, Perbill}; use support::traits::{OnUnbalanced, Currency, Get}; use crate::{ - Balances, System, Authorship, MaximumBlockWeight, NegativeImbalance, WeightToFee, + Balances, System, Authorship, MaximumBlockWeight, NegativeImbalance, TargetedFeeAdjustment, }; @@ -49,10 +49,18 @@ impl Convert for CurrencyToVoteHandler { fn convert(x: u128) -> Balance { x * Self::factor() } } -/// Simply multiply by a coefficient denoted by the `Get` implementation. -impl Convert for WeightToFee { - fn convert(x: Weight) -> Balance { - Balance::from(x).saturating_mul(Self::get()) +/// 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(rstd::marker::PhantomData); + +impl Convert for LinearWeightToFee + where C: Get { + + fn convert(w: Weight) -> Balance { + // substrate-node a weight of 10_000 (smallest non-zero weight) to be mapped to 10^7 units of + // fees, hence: + let coefficient = C::get(); + Balance::from(w).saturating_mul(coefficient) } } diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index 944ef5127d40b..25e3ad1dff588 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -65,7 +65,7 @@ pub use staking::StakerStatus; /// Implementations of some helper traits passed into runtime modules as associated types. pub mod impls; -use impls::{CurrencyToVoteHandler, Author}; +use impls::{CurrencyToVoteHandler, Author, LinearWeightToFee}; /// Constant values used within the runtime. pub mod constants; @@ -178,7 +178,7 @@ parameter_types! { pub const TransactionBaseFee: Balance = 1 * CENTS; pub const TransactionByteFee: Balance = 10 * MILLICENTS; // setting this to zero will disable the weight fee. - pub const WeightToFee: Balance = 1_000; + pub const WeightFeeCoefficient: Balance = 1_000; // for a sane configuration, this should always be less than `AvailableBlockRatio`. pub const TargetedFeeAdjustment: Perbill = Perbill::from_percent(25); } @@ -188,7 +188,7 @@ impl transaction_payment::Trait for Runtime { type OnTransactionPayment = DealWithFees; type TransactionBaseFee = TransactionBaseFee; type TransactionByteFee = TransactionByteFee; - type WeightToFee = WeightToFee; + type WeightToFee = LinearWeightToFee; type FeeMultiplierUpdate = TargetedFeeAdjustment; }