Companion for #6629 (weight params refactor) (#1420)

* Change branch.

* Update runtime.

* Revert "Change branch."

This reverts commit 841c59f3398136c27cc235a29d7d459e8a4c8ce0.

* Update substrate.

* Fix tests.

* Fix compilation.

* Fix frame system imports.

* Fix usages of system

* Fix stuff.

* Fix compilation.

* Fixes.

* Fix block_weight usage.

* Bump substrate.
This commit is contained in:
Tomasz Drwięga
2020-12-08 13:55:57 +01:00
committed by GitHub
parent 48746afd6a
commit f28333aedb
18 changed files with 298 additions and 332 deletions
+4 -4
View File
@@ -69,7 +69,7 @@ pub mod fee {
/// node's balance type.
///
/// This should typically create a mapping between the following ranges:
/// - [0, frame_system::MaximumBlockWeight]
/// - [0, MAXIMUM_BLOCK_WEIGHT]
/// - [Balance::min, Balance::max]
///
/// Yet, it can be used for any other sort of change to weight-fee. Some examples being:
@@ -95,16 +95,16 @@ pub mod fee {
#[cfg(test)]
mod tests {
use frame_support::weights::WeightToFeePolynomial;
use runtime_common::{MaximumBlockWeight, ExtrinsicBaseWeight};
use runtime_common::{MAXIMUM_BLOCK_WEIGHT, ExtrinsicBaseWeight};
use super::fee::WeightToFee;
use super::currency::{CENTS, DOLLARS, MILLICENTS};
#[test]
// This function tests that the fee for `MaximumBlockWeight` of weight is correct
// This function tests that the fee for `MAXIMUM_BLOCK_WEIGHT` of weight is correct
fn full_block_fee_is_correct() {
// A full block should cost 16 DOLLARS
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&MaximumBlockWeight::get());
let x = WeightToFee::calc(&MAXIMUM_BLOCK_WEIGHT);
let y = 16 * DOLLARS;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
+12 -17
View File
@@ -34,9 +34,8 @@ use primitives::v1::{
use runtime_common::{
claims, SlowAdjustingFeeUpdate, CurrencyToVote,
impls::DealWithFees,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight,
MaximumExtrinsicWeight, ParachainSessionKeyPlaceholder,
BlockHashCount, RocksDbWeight, BlockWeights, BlockLength, OffchainSolutionWeightLimit,
ParachainSessionKeyPlaceholder,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, ModuleId,
@@ -129,6 +128,8 @@ parameter_types! {
impl frame_system::Config for Runtime {
type BaseCallFilter = BaseFilter;
type BlockWeights = BlockWeights;
type BlockLength = BlockLength;
type Origin = Origin;
type Call = Call;
type Index = Nonce;
@@ -140,13 +141,7 @@ impl frame_system::Config for Runtime {
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Event = Event;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = RocksDbWeight;
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = Version;
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
@@ -156,6 +151,8 @@ impl frame_system::Config for Runtime {
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
}
@@ -164,7 +161,7 @@ impl pallet_scheduler::Config for Runtime {
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
type MaximumWeight = MaximumBlockWeight;
type MaximumWeight = MaximumSchedulerWeight;
type ScheduleOrigin = EnsureRoot<AccountId>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = weights::pallet_scheduler::WeightInfo<Runtime>;
@@ -326,9 +323,6 @@ parameter_types! {
pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
pub const MaxIterations: u32 = 10;
pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
pub OffchainSolutionWeightLimit: Weight = MaximumExtrinsicWeight::get()
.saturating_sub(BlockExecutionWeight::get())
.saturating_sub(ExtrinsicBaseWeight::get());
}
type SlashCancelOrigin = EnsureOneOf<
@@ -557,7 +551,7 @@ impl pallet_treasury::Config for Runtime {
}
parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * BlockWeights::get().max_block;
}
impl pallet_offences::Config for Runtime {
@@ -1107,7 +1101,7 @@ impl frame_support::traits::OnRuntimeUpgrade for FixCouncilHistoricalVotes {
};
});
frame_support::debug::info!("Migration to fix voters happened. Accounts with inaccurate reserved amount: {}", failure);
<Runtime as frame_system::Config>::MaximumBlockWeight::get()
<Runtime as frame_system::Config>::BlockWeights::get().max_block
}
}
@@ -1534,11 +1528,12 @@ mod test_fees {
#[test]
#[ignore]
fn block_cost() {
let raw_fee = WeightToFee::calc(&MaximumBlockWeight::get());
let max_block_weight = BlockWeights::get().max_block;
let raw_fee = WeightToFee::calc(&max_block_weight);
println!(
"Full Block weight == {} // WeightToFee(full_block) == {} plank",
MaximumBlockWeight::get(),
max_block_weight,
raw_fee.separated_string(),
);
}