From 65106d77920c9c714eb9aa2d8af82f3e13c5421c Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Tue, 27 Oct 2020 22:05:04 +0100 Subject: [PATCH] Reconfigure on_initialize weight. (#1838) * Reconfigure transaction payment and on_initialize weight. * Some tests to investigate with * fix build * Update runtime/common/src/lib.rs Co-authored-by: Shawn Tabrizi * undo change to multiplier. Co-authored-by: Shawn Tabrizi --- polkadot/Cargo.lock | 7 +++ polkadot/runtime/common/src/lib.rs | 6 +-- polkadot/runtime/kusama/Cargo.toml | 1 + polkadot/runtime/kusama/src/lib.rs | 72 ++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 590e6273da..a5637f921b 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -2618,6 +2618,7 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-common", "rustc-hex", + "separator", "serde", "serde_derive", "serde_json", @@ -7540,6 +7541,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" +[[package]] +name = "separator" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f97841a747eef040fcd2e7b3b9a220a7205926e60488e673d9e4926d27772ce5" + [[package]] name = "serde" version = "1.0.117" diff --git a/polkadot/runtime/common/src/lib.rs b/polkadot/runtime/common/src/lib.rs index 132ef5da64..9569412b7c 100644 --- a/polkadot/runtime/common/src/lib.rs +++ b/polkadot/runtime/common/src/lib.rs @@ -49,9 +49,9 @@ pub use impls::ToAuthor; pub type NegativeImbalance = as Currency<::AccountId>>::NegativeImbalance; -/// We assume that an on-initialize consumes 10% of the weight on average, hence a single extrinsic -/// will not be allowed to consume more than `AvailableBlockRatio - 10%`. -pub const AVERAGE_ON_INITIALIZE_WEIGHT: Perbill = Perbill::from_percent(10); +/// We assume that an on-initialize consumes 2.5% of the weight on average, hence a single extrinsic +/// will not be allowed to consume more than `AvailableBlockRatio - 2.5%`. +pub const AVERAGE_ON_INITIALIZE_WEIGHT: Perbill = Perbill::from_perthousand(25); // Common constants used in all runtimes. parameter_types! { diff --git a/polkadot/runtime/kusama/Cargo.toml b/polkadot/runtime/kusama/Cargo.toml index af4923d99c..ccc77ca925 100644 --- a/polkadot/runtime/kusama/Cargo.toml +++ b/polkadot/runtime/kusama/Cargo.toml @@ -79,6 +79,7 @@ libsecp256k1 = "0.3.2" tiny-keccak = "1.5.0" keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } +separator = "0.4.1" serde_json = "1.0.41" [build-dependencies] diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 765f2fcada..e4d41f1a2b 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -1307,3 +1307,75 @@ sp_api::impl_runtime_apis! { } } } + +#[cfg(test)] +mod test_fees { + use super::*; + use frame_support::weights::WeightToFeePolynomial; + use frame_support::storage::StorageValue; + use sp_runtime::FixedPointNumber; + use frame_support::weights::GetDispatchInfo; + use codec::Encode; + use pallet_transaction_payment::Multiplier; + use separator::Separatable; + + + #[test] + #[ignore] + fn block_cost() { + let raw_fee = WeightToFee::calc(&MaximumBlockWeight::get()); + + println!( + "Full Block weight == {} // WeightToFee(full_block) == {} plank", + MaximumBlockWeight::get(), + raw_fee.separated_string(), + ); + } + + #[test] + #[ignore] + fn transfer_cost_min_multiplier() { + let min_multiplier = runtime_common::MinimumMultiplier::get(); + let call = >::transfer_keep_alive(Default::default(), Default::default()); + let info = call.get_dispatch_info(); + // convert to outer call. + let call = Call::Balances(call); + let len = call.using_encoded(|e| e.len()) as u32; + + let mut ext = sp_io::TestExternalities::new_empty(); + ext.execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::put(min_multiplier); + let fee = TransactionPayment::compute_fee(len, &info, 0); + println!( + "weight = {:?} // multiplier = {:?} // full transfer fee = {:?}", + info.weight.separated_string(), + pallet_transaction_payment::NextFeeMultiplier::get(), + fee.separated_string(), + ); + }); + + ext.execute_with(|| { + let mul = Multiplier::saturating_from_rational(1, 1000_000_000u128); + pallet_transaction_payment::NextFeeMultiplier::put(mul); + let fee = TransactionPayment::compute_fee(len, &info, 0); + println!( + "weight = {:?} // multiplier = {:?} // full transfer fee = {:?}", + info.weight.separated_string(), + pallet_transaction_payment::NextFeeMultiplier::get(), + fee.separated_string(), + ); + }); + + ext.execute_with(|| { + let mul = Multiplier::saturating_from_rational(1, 1u128); + pallet_transaction_payment::NextFeeMultiplier::put(mul); + let fee = TransactionPayment::compute_fee(len, &info, 0); + println!( + "weight = {:?} // multiplier = {:?} // full transfer fee = {:?}", + info.weight.separated_string(), + pallet_transaction_payment::NextFeeMultiplier::get(), + fee.separated_string(), + ); + }); + } +}