diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 590e6273daabb2656c904b6e1371cec5b9fdf437..a5637f921bfd72ceecd8d45519a7ac3dcedc3551 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 132ef5da6408697fbf10b28632d847301cca5000..9569412b7cb77daa26b09075b3cbb319e846a166 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<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! { diff --git a/polkadot/runtime/kusama/Cargo.toml b/polkadot/runtime/kusama/Cargo.toml index af4923d99c2e699c5dd9bacd2a79f4c67af73c63..ccc77ca92536cc086c6c2ecb44f1d31997f73ed0 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 765f2fcada8700e74ad80fc338530c98093e4f68..e4d41f1a2bcb5c5ebeba3dae341f42dc17891329 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 = <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(), + ); + }); + } +}