Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Reconfigure on_initialize weight. #1838

Merged
6 commits merged into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
1 change: 1 addition & 0 deletions runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
72 changes: 72 additions & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
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(),
);
});
}
}