refactor: Transaction-Payment module (#3816)

* Initial draft that compiles

* Extract payment stuff from balances

* Extract multiplier update stuff from system

* Some fixes.

* Update len-fee as well

* some review comments.

* Remove todo

* bump
This commit is contained in:
Kian Paimani
2019-10-17 14:21:32 +02:00
committed by GitHub
parent 1711483fb6
commit 183c188111
59 changed files with 784 additions and 596 deletions
+1
View File
@@ -45,6 +45,7 @@ finality_tracker = { package = "srml-finality-tracker", path = "../../srml/final
contracts = { package = "srml-contracts", path = "../../srml/contracts" }
system = { package = "srml-system", path = "../../srml/system" }
balances = { package = "srml-balances", path = "../../srml/balances" }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment" }
support = { package = "srml-support", path = "../../srml/support", default-features = false }
im_online = { package = "srml-im-online", path = "../../srml/im-online", default-features = false }
sr-authority-discovery = { package = "srml-authority-discovery", path = "../../srml/authority-discovery", default-features = false }
+1 -1
View File
@@ -56,7 +56,7 @@ impl<Number> FactoryState<Number> {
system::CheckEra::from(Era::mortal(256, phase)),
system::CheckNonce::from(index),
system::CheckWeight::new(),
balances::TakeFees::from(0),
transaction_payment::ChargeTransactionPayment::from(0),
Default::default(),
)
}
+2 -2
View File
@@ -528,14 +528,14 @@ mod tests {
let check_era = system::CheckEra::from(Era::Immortal);
let check_nonce = system::CheckNonce::from(index);
let check_weight = system::CheckWeight::new();
let take_fees = balances::TakeFees::from(0);
let payment = transaction_payment::ChargeTransactionPayment::from(0);
let extra = (
check_version,
check_genesis,
check_era,
check_nonce,
check_weight,
take_fees,
payment,
Default::default(),
);
let raw_payload = SignedPayload::from_raw(
+1
View File
@@ -22,6 +22,7 @@ test-client = { package = "substrate-test-client", path = "../../core/test-clien
sr-primitives = { path = "../../core/sr-primitives" }
runtime_support = { package = "srml-support", path = "../../srml/support" }
balances = { package = "srml-balances", path = "../../srml/balances" }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment" }
session = { package = "srml-session", path = "../../srml/session" }
system = { package = "srml-system", path = "../../srml/system" }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp" }
+49 -32
View File
@@ -46,16 +46,16 @@ mod tests {
traits::{CodeExecutor, Externalities}, storage::well_known_keys,
};
use sr_primitives::{
assert_eq_error_rate,
Fixed64,
traits::{Header as HeaderT, Hash as HashT, Convert}, ApplyResult,
transaction_validity::InvalidTransaction, weights::{WeightMultiplier, GetDispatchInfo},
transaction_validity::InvalidTransaction, weights::GetDispatchInfo,
};
use contracts::ContractAddressFor;
use substrate_executor::{NativeExecutor, WasmExecutionMethod};
use system::{EventRecord, Phase};
use node_runtime::{
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances, BuildStorage,
System, Event, TransferFee, TransactionBaseFee, TransactionByteFee,
System, TransactionPayment, Event, TransferFee, TransactionBaseFee, TransactionByteFee,
constants::currency::*, impls::WeightToFee,
};
use node_primitives::{Balance, Hash, BlockNumber};
@@ -88,17 +88,15 @@ mod tests {
}
/// Default transfer fee
fn transfer_fee<E: Encode>(extrinsic: &E) -> Balance {
fn transfer_fee<E: Encode>(extrinsic: &E, fee_multiplier: Fixed64) -> Balance {
let length_fee = TransactionBaseFee::get() +
TransactionByteFee::get() *
(extrinsic.encode().len() as Balance);
let weight = default_transfer_call().get_dispatch_info().weight;
// NOTE: this is really hard to apply, since the multiplier of each block needs to be fetched
// before the block, while we compute this after the block.
// weight = <system::Module<Runtime>>::next_weight_multiplier().apply_to(weight);
let weight_fee = <Runtime as balances::Trait>::WeightToFee::convert(weight);
length_fee + weight_fee + TransferFee::get()
let weight_fee = <Runtime as transaction_payment::Trait>::WeightToFee::convert(weight);
fee_multiplier.saturated_multiply_accumulate(length_fee + weight_fee) + TransferFee::get()
}
fn default_transfer_call() -> balances::Call<Runtime> {
@@ -217,6 +215,9 @@ mod tests {
None,
).0;
assert!(r.is_ok());
let fm = t.execute_with(TransactionPayment::next_fee_multiplier);
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"BlockBuilder_apply_extrinsic",
@@ -227,7 +228,7 @@ mod tests {
assert!(r.is_ok());
t.execute_with(|| {
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt()));
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt(), fm));
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
});
}
@@ -253,6 +254,9 @@ mod tests {
None,
).0;
assert!(r.is_ok());
let fm = t.execute_with(TransactionPayment::next_fee_multiplier);
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"BlockBuilder_apply_extrinsic",
@@ -263,7 +267,7 @@ mod tests {
assert!(r.is_ok());
t.execute_with(|| {
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt()));
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt(), fm));
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
});
}
@@ -425,6 +429,9 @@ mod tests {
let (block1, block2) = blocks();
let mut alice_last_known_balance: Balance = Default::default();
let mut fm = t.execute_with(TransactionPayment::next_fee_multiplier);
executor().call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
@@ -434,8 +441,9 @@ mod tests {
).0.unwrap();
t.execute_with(|| {
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt()));
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt(), fm));
assert_eq!(Balances::total_balance(&bob()), 169 * DOLLARS);
alice_last_known_balance = Balances::total_balance(&alice());
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
@@ -460,6 +468,9 @@ mod tests {
];
assert_eq!(System::events(), events);
});
fm = t.execute_with(TransactionPayment::next_fee_multiplier);
executor().call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
@@ -471,15 +482,13 @@ mod tests {
t.execute_with(|| {
// NOTE: fees differ slightly in tests that execute more than one block due to the
// weight update. Hence, using `assert_eq_error_rate`.
assert_eq_error_rate!(
assert_eq!(
Balances::total_balance(&alice()),
32 * DOLLARS - 2 * transfer_fee(&xt()),
10_000
alice_last_known_balance - 10 * DOLLARS - transfer_fee(&xt(), fm),
);
assert_eq_error_rate!(
assert_eq!(
Balances::total_balance(&bob()),
179 * DOLLARS - transfer_fee(&xt()),
10_000
179 * DOLLARS - transfer_fee(&xt(), fm),
);
let events = vec![
EventRecord {
@@ -532,6 +541,9 @@ mod tests {
let (block1, block2) = blocks();
let mut alice_last_known_balance: Balance = Default::default();
let mut fm = t.execute_with(TransactionPayment::next_fee_multiplier);
executor().call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
@@ -541,10 +553,13 @@ mod tests {
).0.unwrap();
t.execute_with(|| {
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt()));
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - transfer_fee(&xt(), fm));
assert_eq!(Balances::total_balance(&bob()), 169 * DOLLARS);
alice_last_known_balance = Balances::total_balance(&alice());
});
fm = t.execute_with(TransactionPayment::next_fee_multiplier);
executor().call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"Core_execute_block",
@@ -554,15 +569,13 @@ mod tests {
).0.unwrap();
t.execute_with(|| {
assert_eq_error_rate!(
assert_eq!(
Balances::total_balance(&alice()),
32 * DOLLARS - 2 * transfer_fee(&xt()),
10_000
alice_last_known_balance - 10 * DOLLARS - transfer_fee(&xt(), fm),
);
assert_eq_error_rate!(
assert_eq!(
Balances::total_balance(&bob()),
179 * DOLLARS - 1 * transfer_fee(&xt()),
10_000
179 * DOLLARS - 1 * transfer_fee(&xt(), fm),
);
});
}
@@ -824,6 +837,7 @@ mod tests {
None,
).0;
assert!(r.is_ok());
let fm = t.execute_with(TransactionPayment::next_fee_multiplier);
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
&mut t,
"BlockBuilder_apply_extrinsic",
@@ -837,7 +851,7 @@ mod tests {
.expect("Extrinsic did not fail");
t.execute_with(|| {
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - 1 * transfer_fee(&xt()));
assert_eq!(Balances::total_balance(&alice()), 42 * DOLLARS - 1 * transfer_fee(&xt(), fm));
assert_eq!(Balances::total_balance(&bob()), 69 * DOLLARS);
});
}
@@ -890,13 +904,14 @@ mod tests {
#[test]
fn weight_multiplier_increases_and_decreases_on_big_weight() {
fn fee_multiplier_increases_and_decreases_on_big_weight() {
let mut t = new_test_ext(COMPACT_CODE, false);
let mut prev_multiplier = WeightMultiplier::default();
// initial fee multiplier must be zero
let mut prev_multiplier = Fixed64::from_parts(0);
t.execute_with(|| {
assert_eq!(System::next_weight_multiplier(), prev_multiplier);
assert_eq!(TransactionPayment::next_fee_multiplier(), prev_multiplier);
});
let mut tt = new_test_ext(COMPACT_CODE, false);
@@ -948,7 +963,7 @@ mod tests {
// weight multiplier is increased for next block.
t.execute_with(|| {
let fm = System::next_weight_multiplier();
let fm = TransactionPayment::next_fee_multiplier();
println!("After a big block: {:?} -> {:?}", prev_multiplier, fm);
assert!(fm > prev_multiplier);
prev_multiplier = fm;
@@ -965,7 +980,7 @@ mod tests {
// weight multiplier is increased for next block.
t.execute_with(|| {
let fm = System::next_weight_multiplier();
let fm = TransactionPayment::next_fee_multiplier();
println!("After a small block: {:?} -> {:?}", prev_multiplier, fm);
assert!(fm < prev_multiplier);
});
@@ -978,7 +993,7 @@ mod tests {
// weight of transfer call as of now: 1_000_000
// if weight of the cheapest weight would be 10^7, this would be 10^9, which is:
// - 1 MILLICENTS in substrate node.
// - 1 milldot based on current polkadot runtime.
// - 1 milli-dot based on current polkadot runtime.
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
@@ -1052,6 +1067,7 @@ mod tests {
fn block_weight_capacity_report() {
// Just report how many transfer calls you could fit into a block. The number should at least
// be a few hundred (250 at the time of writing but can change over time). Runs until panic.
use node_primitives::Index;
// execution ext.
let mut t = new_test_ext(COMPACT_CODE, false);
@@ -1118,6 +1134,7 @@ mod tests {
// Just report how big a block can get. Executes until panic. Should be ignored unless if
// manually inspected. The number should at least be a few megabytes (5 at the time of
// writing but can change over time).
use node_primitives::Index;
// execution ext.
let mut t = new_test_ext(COMPACT_CODE, false);
+2
View File
@@ -52,6 +52,7 @@ system-rpc-runtime-api = { package = "srml-system-rpc-runtime-api", path = "../.
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default-features = false }
treasury = { package = "srml-treasury", path = "../../srml/treasury", default-features = false }
utility = { package = "srml-utility", path = "../../srml/utility", default-features = false }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment", default-features = false }
[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.2", path = "../../core/utils/wasm-builder-runner" }
@@ -100,5 +101,6 @@ std = [
"timestamp/std",
"treasury/std",
"utility/std",
"transaction-payment/std",
"version/std",
]
+4 -4
View File
@@ -67,10 +67,10 @@ pub mod time {
pub const DAYS: BlockNumber = HOURS * 24;
}
// CRITICAL NOTE: The system module maintains two constants: a _maximum_ block weight and a
// _ratio_ of it yielding the portion which is accessible to normal transactions (reserving the rest
// for operational ones). `TARGET_BLOCK_FULLNESS` is entirely independent and the system module is
// not aware of if, nor should it care about it. This constant simply denotes on which ratio of the
// CRITICAL NOTE: The system module maintains two constants: a _maximum_ block weight and a _ratio_
// of it yielding the portion which is accessible to normal transactions (reserving the rest for
// operational ones). `TARGET_BLOCK_FULLNESS` is entirely independent and the system module is not
// aware of if, nor should it care about it. This constant simply denotes on which ratio of the
// _maximum_ block weight we tweak the fees. It does NOT care about the type of the dispatch.
//
// For the system to be configured in a sane way, `TARGET_BLOCK_FULLNESS` should always be less than
+103 -64
View File
@@ -17,7 +17,7 @@
//! Some configurable implementations as associated type for the substrate runtime.
use node_primitives::Balance;
use sr_primitives::weights::{Weight, WeightMultiplier};
use sr_primitives::weights::Weight;
use sr_primitives::traits::{Convert, Saturating};
use sr_primitives::Fixed64;
use support::traits::{OnUnbalanced, Currency};
@@ -82,10 +82,10 @@ impl Convert<Weight, Balance> for WeightToFee {
/// next_weight = weight * (1 + (v . diff) + (v . diff)^2 / 2)
///
/// https://research.web3.foundation/en/latest/polkadot/Token%20Economics/#relay-chain-transaction-fees
pub struct WeightMultiplierUpdateHandler;
pub struct FeeMultiplierUpdateHandler;
impl Convert<(Weight, WeightMultiplier), WeightMultiplier> for WeightMultiplierUpdateHandler {
fn convert(previous_state: (Weight, WeightMultiplier)) -> WeightMultiplier {
impl Convert<(Weight, Fixed64), Fixed64> for FeeMultiplierUpdateHandler {
fn convert(previous_state: (Weight, Fixed64)) -> Fixed64 {
let (block_weight, multiplier) = previous_state;
let max_weight = MaximumBlockWeight::get();
let target_weight = (TARGET_BLOCK_FULLNESS * max_weight) as u128;
@@ -113,17 +113,17 @@ impl Convert<(Weight, WeightMultiplier), WeightMultiplier> for WeightMultiplierU
// Note: this is merely bounded by how big the multiplier and the inner value can go,
// not by any economical reasoning.
let excess = first_term.saturating_add(second_term);
multiplier.saturating_add(WeightMultiplier::from_fixed(excess))
multiplier.saturating_add(excess)
} else {
// first_term > second_term
// Proof: first_term > second_term. Safe subtraction.
let negative = first_term - second_term;
multiplier.saturating_sub(WeightMultiplier::from_fixed(negative))
multiplier.saturating_sub(negative)
// despite the fact that apply_to saturates weight (final fee cannot go below 0)
// it is crucially important to stop here and don't further reduce the weight fee
// multiplier. While at -1, it means that the network is so un-congested that all
// transactions have no weight fee. We stop here and only increase if the network
// became more busy.
.max(WeightMultiplier::from_rational(-1, 1))
.max(Fixed64::from_rational(-1, 1))
}
}
}
@@ -132,7 +132,6 @@ impl Convert<(Weight, WeightMultiplier), WeightMultiplier> for WeightMultiplierU
mod tests {
use super::*;
use sr_primitives::weights::Weight;
use sr_primitives::Perbill;
use crate::{MaximumBlockWeight, AvailableBlockRatio, Runtime};
use crate::constants::currency::*;
@@ -145,8 +144,7 @@ mod tests {
}
// poc reference implementation.
#[allow(dead_code)]
fn weight_multiplier_update(block_weight: Weight) -> Perbill {
fn fee_multiplier_update(block_weight: Weight, previous: Fixed64) -> Fixed64 {
let block_weight = block_weight as f32;
let v: f32 = 0.00004;
@@ -157,53 +155,84 @@ mod tests {
// Current saturation in terms of weight
let s = block_weight;
let fm = 1.0 + (v * (s/m - ss/m)) + (v.powi(2) * (s/m - ss/m).powi(2)) / 2.0;
// return a per-bill-like value.
let fm = if fm >= 1.0 { fm - 1.0 } else { 1.0 - fm };
Perbill::from_parts((fm * 1_000_000_000_f32) as u32)
let fm = (v * (s/m - ss/m)) + (v.powi(2) * (s/m - ss/m).powi(2)) / 2.0;
let addition_fm = Fixed64::from_parts((fm * 1_000_000_000_f32) as i64);
previous.saturating_add(addition_fm)
}
fn wm(parts: i64) -> WeightMultiplier {
WeightMultiplier::from_parts(parts)
fn fm(parts: i64) -> Fixed64 {
Fixed64::from_parts(parts)
}
#[test]
fn fee_multiplier_update_poc_works() {
let fm = Fixed64::from_rational(0, 1);
let test_set = vec![
// TODO: this has a rounding error and fails.
// (0, fm.clone()),
(100, fm.clone()),
(target(), fm.clone()),
(max() / 2, fm.clone()),
(max(), fm.clone()),
];
test_set.into_iter().for_each(|(w, fm)| {
assert_eq!(
fee_multiplier_update(w, fm),
FeeMultiplierUpdateHandler::convert((w, fm)),
"failed for weight {} and prev fm {:?}",
w,
fm,
);
})
}
#[test]
fn empty_chain_simulation() {
// just a few txs per_block.
let block_weight = 1000;
let mut wm = WeightMultiplier::default();
let mut fm = Fixed64::default();
let mut iterations: u64 = 0;
loop {
let next = WeightMultiplierUpdateHandler::convert((block_weight, wm));
wm = next;
if wm == WeightMultiplier::from_rational(-1, 1) { break; }
let next = FeeMultiplierUpdateHandler::convert((block_weight, fm));
fm = next;
if fm == Fixed64::from_rational(-1, 1) { break; }
iterations += 1;
}
println!("iteration {}, new wm = {:?}. Weight fee is now zero", iterations, wm);
println!("iteration {}, new fm = {:?}. Weight fee is now zero", iterations, fm);
}
#[test]
#[ignore]
fn congested_chain_simulation() {
// `cargo test congested_chain_simulation -- --nocapture` to get some insight.
// almost full. The entire quota of normal transactions is taken.
let block_weight = AvailableBlockRatio::get() * max();
let tx_weight = 1000;
let mut wm = WeightMultiplier::default();
// default minimum substrate weight
let tx_weight = 10_000u32;
// initial value of system
let mut fm = Fixed64::default();
assert_eq!(fm, Fixed64::from_parts(0));
let mut iterations: u64 = 0;
loop {
let next = WeightMultiplierUpdateHandler::convert((block_weight, wm));
if wm == next { break; }
wm = next;
let next = FeeMultiplierUpdateHandler::convert((block_weight, fm));
if fm == next { break; }
fm = next;
iterations += 1;
let fee = <Runtime as balances::Trait>::WeightToFee::convert(wm.apply_to(tx_weight));
let fee = <Runtime as transaction_payment::Trait>::WeightToFee::convert(tx_weight);
let adjusted_fee = fm.saturated_multiply_accumulate(fee);
println!(
"iteration {}, new wm = {:?}. Fee at this point is: {} millicents, {} cents, {} dollars",
"iteration {}, new fm = {:?}. Fee at this point is: \
{} units, {} millicents, {} cents, {} dollars",
iterations,
wm,
fee / MILLICENTS,
fee / CENTS,
fee / DOLLARS
fm,
adjusted_fee,
adjusted_fee / MILLICENTS,
adjusted_fee / CENTS,
adjusted_fee / DOLLARS
);
}
}
@@ -212,65 +241,65 @@ mod tests {
fn stateless_weight_mul() {
// Light block. Fee is reduced a little.
assert_eq!(
WeightMultiplierUpdateHandler::convert((target() / 4, WeightMultiplier::default())),
wm(-7500)
FeeMultiplierUpdateHandler::convert((target() / 4, Fixed64::default())),
fm(-7500)
);
// a bit more. Fee is decreased less, meaning that the fee increases as the block grows.
assert_eq!(
WeightMultiplierUpdateHandler::convert((target() / 2, WeightMultiplier::default())),
wm(-5000)
FeeMultiplierUpdateHandler::convert((target() / 2, Fixed64::default())),
fm(-5000)
);
// ideal. Original fee. No changes.
assert_eq!(
WeightMultiplierUpdateHandler::convert((target(), WeightMultiplier::default())),
wm(0)
FeeMultiplierUpdateHandler::convert((target(), Fixed64::default())),
fm(0)
);
// // More than ideal. Fee is increased.
assert_eq!(
WeightMultiplierUpdateHandler::convert(((target() * 2), WeightMultiplier::default())),
wm(10000)
FeeMultiplierUpdateHandler::convert(((target() * 2), Fixed64::default())),
fm(10000)
);
}
#[test]
fn stateful_weight_mul_grow_to_infinity() {
assert_eq!(
WeightMultiplierUpdateHandler::convert((target() * 2, WeightMultiplier::default())),
wm(10000)
FeeMultiplierUpdateHandler::convert((target() * 2, Fixed64::default())),
fm(10000)
);
assert_eq!(
WeightMultiplierUpdateHandler::convert((target() * 2, wm(10000))),
wm(20000)
FeeMultiplierUpdateHandler::convert((target() * 2, fm(10000))),
fm(20000)
);
assert_eq!(
WeightMultiplierUpdateHandler::convert((target() * 2, wm(20000))),
wm(30000)
FeeMultiplierUpdateHandler::convert((target() * 2, fm(20000))),
fm(30000)
);
// ...
assert_eq!(
WeightMultiplierUpdateHandler::convert((target() * 2, wm(1_000_000_000))),
wm(1_000_000_000 + 10000)
FeeMultiplierUpdateHandler::convert((target() * 2, fm(1_000_000_000))),
fm(1_000_000_000 + 10000)
);
}
#[test]
fn stateful_weight_mil_collapse_to_minus_one() {
assert_eq!(
WeightMultiplierUpdateHandler::convert((0, WeightMultiplier::default())),
wm(-10000)
FeeMultiplierUpdateHandler::convert((0, Fixed64::default())),
fm(-10000)
);
assert_eq!(
WeightMultiplierUpdateHandler::convert((0, wm(-10000))),
wm(-20000)
FeeMultiplierUpdateHandler::convert((0, fm(-10000))),
fm(-20000)
);
assert_eq!(
WeightMultiplierUpdateHandler::convert((0, wm(-20000))),
wm(-30000)
FeeMultiplierUpdateHandler::convert((0, fm(-20000))),
fm(-30000)
);
// ...
assert_eq!(
WeightMultiplierUpdateHandler::convert((0, wm(1_000_000_000 * -1))),
wm(-1_000_000_000)
FeeMultiplierUpdateHandler::convert((0, fm(1_000_000_000 * -1))),
fm(-1_000_000_000)
);
}
@@ -278,20 +307,30 @@ mod tests {
fn weight_to_fee_should_not_overflow_on_large_weights() {
let kb = 1024 as Weight;
let mb = kb * kb;
let max_fm = WeightMultiplier::from_fixed(Fixed64::from_natural(i64::max_value()));
let max_fm = Fixed64::from_natural(i64::max_value());
vec![0, 1, 10, 1000, kb, 10 * kb, 100 * kb, mb, 10 * mb, Weight::max_value() / 2, Weight::max_value()]
.into_iter()
.for_each(|i| {
WeightMultiplierUpdateHandler::convert((i, WeightMultiplier::default()));
});
vec![
0,
1,
10,
1000,
kb,
10 * kb,
100 * kb,
mb,
10 * mb,
Weight::max_value() / 2,
Weight::max_value()
].into_iter().for_each(|i| {
FeeMultiplierUpdateHandler::convert((i, Fixed64::default()));
});
// Some values that are all above the target and will cause an increase.
let t = target();
vec![t + 100, t * 2, t * 4]
.into_iter()
.for_each(|i| {
let fm = WeightMultiplierUpdateHandler::convert((
let fm = FeeMultiplierUpdateHandler::convert((
i,
max_fm
));
+17 -9
View File
@@ -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, WeightMultiplierUpdateHandler, Author, WeightToFee};
use impls::{CurrencyToVoteHandler, FeeMultiplierUpdateHandler, Author, WeightToFee};
/// Constant values used within the runtime.
pub mod constants;
@@ -84,8 +84,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to equal spec_version. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 177,
impl_version: 177,
spec_version: 178,
impl_version: 178,
apis: RUNTIME_API_VERSIONS,
};
@@ -125,7 +125,6 @@ impl system::Trait for Runtime {
type AccountId = AccountId;
type Lookup = Indices;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type WeightMultiplierUpdate = WeightMultiplierUpdateHandler;
type Event = Event;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
@@ -161,8 +160,6 @@ parameter_types! {
pub const ExistentialDeposit: Balance = 1 * DOLLARS;
pub const TransferFee: Balance = 1 * CENTS;
pub const CreationFee: Balance = 1 * CENTS;
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}
impl balances::Trait for Runtime {
@@ -170,15 +167,25 @@ impl balances::Trait for Runtime {
type OnFreeBalanceZero = ((Staking, Contracts), Session);
type OnNewAccount = Indices;
type Event = Event;
type TransactionPayment = DealWithFees;
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}
parameter_types! {
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}
impl transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = DealWithFees;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = FeeMultiplierUpdateHandler;
}
parameter_types! {
@@ -480,7 +487,7 @@ impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtim
system::CheckEra::<Runtime>::from(generic::Era::mortal(period, current_block)),
system::CheckNonce::<Runtime>::from(index),
system::CheckWeight::<Runtime>::new(),
balances::TakeFees::<Runtime>::from(tip),
transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
Default::default(),
);
let raw_payload = SignedPayload::new(call, extra).ok()?;
@@ -504,6 +511,7 @@ construct_runtime!(
Authorship: authorship::{Module, Call, Storage, Inherent},
Indices: indices,
Balances: balances::{default, Error},
TransactionPayment: transaction_payment::{Module, Storage},
Staking: staking::{default, OfflineWorker},
Session: session::{Module, Call, Storage, Event, Config<T>},
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
@@ -540,7 +548,7 @@ pub type SignedExtra = (
system::CheckEra<Runtime>,
system::CheckNonce<Runtime>,
system::CheckWeight<Runtime>,
balances::TakeFees<Runtime>,
transaction_payment::ChargeTransactionPayment<Runtime>,
contracts::CheckBlockGasLimit<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
+1
View File
@@ -27,4 +27,5 @@ system = { package = "srml-system", path = "../../srml/system" }
test-client = { package = "substrate-test-client", path = "../../core/test-client" }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp" }
treasury = { package = "srml-treasury", path = "../../srml/treasury" }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment" }
wabt = "0.9.2"
+1 -1
View File
@@ -72,7 +72,7 @@ pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
system::CheckEra::from(Era::mortal(256, 0)),
system::CheckNonce::from(nonce),
system::CheckWeight::new(),
balances::TakeFees::from(extra_fee),
transaction_payment::ChargeTransactionPayment::from(extra_fee),
Default::default(),
)
}