Skip to content
Snippets Groups Projects
Commit 65106d77 authored by Kian Paimani's avatar Kian Paimani Committed by GitHub
Browse files

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: default avatarShawn Tabrizi <shawntabrizi@gmail.com>

* undo change to multiplier.

Co-authored-by: default avatarShawn Tabrizi <shawntabrizi@gmail.com>
parent 1a3780aa
No related merge requests found
......@@ -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"
......
......@@ -49,9 +49,9 @@ pub use impls::ToAuthor;
pub type NegativeImbalance<T> = <pallet_balances::Module<T> as Currency<<T as frame_system::Trait>::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! {
......
......@@ -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]
......
......@@ -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 = <pallet_balances::Call<Runtime>>::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(),
);
});
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment