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
+136 -136
View File
File diff suppressed because it is too large Load Diff
+4 -11
View File
@@ -636,7 +636,7 @@ mod tests {
use parity_scale_codec::Encode;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup, Identity}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup, Identity}, testing::Header};
use frame_support::{
impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err, assert_noop, parameter_types,
ord_parameter_types, weights::{Pays, GetDispatchInfo}, traits::ExistenceRequirement,
@@ -661,12 +661,12 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
@@ -678,13 +678,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+5 -11
View File
@@ -579,7 +579,7 @@ mod tests {
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sp_runtime::{
Perbill, Permill, Percent, testing::Header, DispatchResult,
Permill, Percent, testing::Header, DispatchResult,
traits::{BlakeTwo256, IdentityLookup},
};
use crate::slots::Registrar;
@@ -595,12 +595,13 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = ();
type Index = u64;
@@ -612,13 +613,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+13 -10
View File
@@ -72,7 +72,8 @@ where
#[cfg(test)]
mod tests {
use super::*;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_system::limits;
use frame_support::{impl_outer_origin, parameter_types, weights::DispatchClass};
use frame_support::traits::FindAuthor;
use sp_core::H256;
use sp_runtime::{
@@ -91,9 +92,15 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const ExtrinsicBaseWeight: u64 = 100;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.for_class(DispatchClass::all(), |weight| {
weight.base_extrinsic = 100;
})
.for_class(DispatchClass::non_mandatory(), |weight| {
weight.max_total = Some(1024);
})
.build_or_panic();
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
@@ -110,13 +117,9 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type BlockLength = BlockLength;
type BlockWeights = BlockWeights;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+55 -27
View File
@@ -28,10 +28,11 @@ pub mod paras_sudo_wrapper;
pub mod paras_registrar;
use primitives::v1::{BlockNumber, ValidatorId};
use sp_runtime::{Perquintill, Perbill, FixedPointNumber, traits::Saturating};
use sp_runtime::{Perquintill, Perbill, FixedPointNumber};
use frame_system::limits;
use frame_support::{
parameter_types, traits::{Currency},
weights::{Weight, constants::WEIGHT_PER_SECOND},
weights::{Weight, constants::WEIGHT_PER_SECOND, DispatchClass},
};
use pallet_transaction_payment::{TargetedFeeAdjustment, Multiplier};
use static_assertions::const_assert;
@@ -55,22 +56,19 @@ const WASM_MAGIC: &[u8] = &[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
/// 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);
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_perthousand(25);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());
// Common constants used in all runtimes.
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
/// Block time that can be used by weights.
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
/// Portion of the block available to normal class of dispatches.
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
/// Maximum weight that a _single_ extrinsic can take.
pub MaximumExtrinsicWeight: Weight =
AvailableBlockRatio::get().saturating_sub(AVERAGE_ON_INITIALIZE_WEIGHT)
* MaximumBlockWeight::get();
/// Maximum length of block. 5MB.
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
/// The portion of the `AvailableBlockRatio` that we adjust the fees with. Blocks filled less
/// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less
/// than this will decrease the weight and more will increase.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
@@ -80,9 +78,41 @@ parameter_types! {
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
/// See `multiplier_can_grow_from_zero`.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000_000u128);
/// Maximum length of block. Up to 5MB.
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
/// Block weights base values and limits.
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
// Operational transactions have an extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT,
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
}
const_assert!(AvailableBlockRatio::get().deconstruct() >= AVERAGE_ON_INITIALIZE_WEIGHT.deconstruct());
parameter_types! {
/// A limit for off-chain phragmen unsigned solution submission.
///
/// We want to keep it as high as possible, but can't risk having it reject,
/// so we always subtract the base block execution weight.
pub OffchainSolutionWeightLimit: Weight = BlockWeights::get()
.get(DispatchClass::Normal)
.max_extrinsic
.expect("Normal extrinsics have weight limit configured by default; qed")
.saturating_sub(BlockExecutionWeight::get());
}
/// Parameterized slow adjusting fee updated based on
/// https://w3f-research.readthedocs.io/en/latest/polkadot/Token%20Economics.html#-2.-slow-adjusting-mechanism
@@ -148,14 +178,18 @@ mod multiplier_tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const ExtrinsicBaseWeight: u64 = 100;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockLength: frame_system::limits::BlockLength =
frame_system::limits::BlockLength::max(2 * 1024);
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -167,13 +201,6 @@ mod multiplier_tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = ();
@@ -188,7 +215,7 @@ mod multiplier_tests {
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap().into();
t.execute_with(|| {
System::set_block_limits(w, 0);
System::set_block_consumed_resources(w, 0);
assertions()
});
}
@@ -196,7 +223,8 @@ mod multiplier_tests {
#[test]
fn multiplier_can_grow_from_zero() {
let minimum_multiplier = MinimumMultiplier::get();
let target = TargetBlockFullness::get() * (AvailableBlockRatio::get() * MaximumBlockWeight::get());
let target = TargetBlockFullness::get() *
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
// if the min is too small, then this will not change, and we are doomed forever.
// the weight is 1/10th bigger than target.
run_with_system_weight(target * 101 / 100, || {
+9 -10
View File
@@ -264,6 +264,7 @@ mod tests {
use primitives::v1::{
Balance, BlockNumber, Header, Signature, AuthorityDiscoveryId,
};
use frame_system::limits;
use frame_support::{
traits::{Randomness, OnInitialize, OnFinalize},
impl_outer_origin, impl_outer_dispatch, assert_ok, parameter_types,
@@ -299,11 +300,13 @@ mod tests {
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
const NORMAL_RATIO: Perbill = Perbill::from_percent(75);
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub BlockWeights: limits::BlockWeights =
limits::BlockWeights::with_sensible_defaults(4 * 1024 * 1024, NORMAL_RATIO);
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(4 * 1024 * 1024, NORMAL_RATIO);
}
impl frame_system::Config for Test {
@@ -319,13 +322,9 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type BlockWeights = BlockWeights;
type BlockLength = BlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u128>;
@@ -416,7 +415,7 @@ mod tests {
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = ();
type MinSolutionScoreBump = ();
type OffchainSolutionWeightLimit = MaximumBlockWeight;
type OffchainSolutionWeightLimit = ();
type WeightInfo = ();
}
+5 -12
View File
@@ -382,7 +382,7 @@ pub fn remove_pallet<T>() -> frame_support::weights::Weight
remove_storage_prefix(b"Purchase", b"Statement", b"");
remove_storage_prefix(b"Purchase", b"UnlockBlock", b"");
T::MaximumBlockWeight::get()
<T as frame_system::Config>::BlockWeights::get().max_block
}
#[cfg(test)]
@@ -393,7 +393,7 @@ mod tests {
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sp_runtime::{
Perbill, MultiSignature,
MultiSignature,
traits::{BlakeTwo256, IdentityLookup, Identity, Verify, IdentifyAccount, Dispatchable},
testing::Header
};
@@ -424,12 +424,12 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
@@ -441,13 +441,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+4 -14
View File
@@ -942,10 +942,7 @@ mod tests {
use std::{collections::HashMap, cell::RefCell};
use sp_core::H256;
use sp_runtime::{
Perbill,
traits::{BlakeTwo256, Hash, IdentityLookup},
};
use sp_runtime::traits::{BlakeTwo256, Hash, IdentityLookup};
use frame_support::{
impl_outer_origin, parameter_types, assert_ok, assert_noop,
traits::{OnInitialize, OnFinalize}
@@ -964,12 +961,12 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: u32 = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = ();
type Index = u64;
@@ -981,13 +978,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+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(),
);
}
+8 -16
View File
@@ -17,17 +17,14 @@
//! Mocks for all the traits.
use sp_io::TestExternalities;
use sp_core::{H256};
use sp_runtime::{
Perbill,
traits::{
use sp_core::H256;
use sp_runtime::traits::{
BlakeTwo256, IdentityLookup,
},
};
use primitives::v1::{AuthorityDiscoveryId, BlockNumber, Header};
use frame_support::{
impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types,
weights::Weight, traits::Randomness as RandomnessT,
traits::Randomness as RandomnessT,
};
use crate::inclusion;
use crate as parachains;
@@ -65,13 +62,15 @@ impl RandomnessT<H256> for TestRandomness {
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub const MaximumBlockWeight: Weight = 4 * 1024 * 1024;
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(4 * 1024 * 1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
@@ -83,13 +82,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = TestEvent;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u128>;
+4 -4
View File
@@ -61,7 +61,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:
@@ -87,16 +87,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);
}
+8 -14
View File
@@ -24,9 +24,8 @@ use pallet_transaction_payment::CurrencyAdapter;
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_std::prelude::*;
@@ -142,6 +141,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;
@@ -153,13 +154,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>;
@@ -169,6 +164,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;
}
@@ -177,7 +174,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>;
@@ -333,9 +330,6 @@ parameter_types! {
pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 16;
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<
@@ -603,7 +597,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 {
+7 -6
View File
@@ -87,8 +87,8 @@ pub mod fee {
#[cfg(test)]
mod tests {
use frame_support::weights::WeightToFeePolynomial;
use runtime_common::{MaximumBlockWeight, ExtrinsicBaseWeight};
use frame_support::weights::{WeightToFeePolynomial, DispatchClass};
use runtime_common::BlockWeights;
use super::fee::WeightToFee;
use super::currency::{CENTS, DOLLARS, MILLICENTS};
@@ -96,8 +96,8 @@ mod tests {
// This function tests that the fee for `MaximumBlockWeight` 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());
println!("Base: {}", BlockWeights::get().get(DispatchClass::Normal).base_extrinsic);
let x = WeightToFee::calc(&BlockWeights::get().max_block);
let y = 16 * DOLLARS;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
@@ -106,8 +106,9 @@ mod tests {
// This function tests that the fee for `ExtrinsicBaseWeight` of weight is correct
fn extrinsic_base_fee_is_correct() {
// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&ExtrinsicBaseWeight::get());
let base_weight = BlockWeights::get().get(DispatchClass::Normal).base_extrinsic;
println!("Base: {}", base_weight);
let x = WeightToFee::calc(&base_weight);
let y = CENTS / 10;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
+6 -11
View File
@@ -33,8 +33,7 @@ use primitives::v1::{
use runtime_common::{
SlowAdjustingFeeUpdate,
impls::ToAuthor,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, MaximumExtrinsicWeight,
BlockHashCount, BlockWeights, BlockLength, RocksDbWeight, OffchainSolutionWeightLimit,
};
use runtime_parachains::{
self,
@@ -212,6 +211,9 @@ parameter_types! {
impl frame_system::Config for Runtime {
type BaseCallFilter = BaseFilter;
type BlockWeights = BlockWeights;
type BlockLength = BlockLength;
type DbWeight = RocksDbWeight;
type Origin = Origin;
type Call = Call;
type Index = Nonce;
@@ -223,13 +225,6 @@ 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>;
@@ -364,7 +359,7 @@ impl pallet_staking::Config for Runtime {
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = MaxIterations;
type OffchainSolutionWeightLimit = MaximumBlockWeight;
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
type MinSolutionScoreBump = MinSolutionScoreBump;
type WeightInfo = ();
}
@@ -398,7 +393,7 @@ parameter_types! {
}
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 {
+6 -11
View File
@@ -45,8 +45,7 @@ use primitives::v1::{
};
use runtime_common::{
claims, SlowAdjustingFeeUpdate, paras_sudo_wrapper,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight,
BlockHashCount, BlockWeights, BlockLength,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
@@ -125,6 +124,9 @@ parameter_types! {
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = BlockLength;
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = Nonce;
@@ -136,13 +138,6 @@ impl frame_system::Config for Runtime {
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Event = Event;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = Version;
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
@@ -331,7 +326,7 @@ impl pallet_staking::Config for Runtime {
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = MaxIterations;
type OffchainSolutionWeightLimit = MaximumBlockWeight;
type OffchainSolutionWeightLimit = ();
type MinSolutionScoreBump = MinSolutionScoreBump;
type WeightInfo = ();
@@ -401,7 +396,7 @@ impl frame_system::offchain::SigningTypes for Runtime {
}
parameter_types! {
pub storage OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
pub storage OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * BlockWeights::get().max_block;
}
impl pallet_offences::Config for Runtime {
+4 -4
View File
@@ -61,7 +61,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:
@@ -87,16 +87,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);
}
+7 -13
View File
@@ -33,8 +33,7 @@ use primitives::v1::{
use runtime_common::{
SlowAdjustingFeeUpdate, CurrencyToVote,
impls::ToAuthor,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, MaximumExtrinsicWeight,
BlockHashCount, BlockWeights, BlockLength, RocksDbWeight, OffchainSolutionWeightLimit,
ParachainSessionKeyPlaceholder,
};
use sp_runtime::{
@@ -120,6 +119,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;
@@ -131,13 +132,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>;
@@ -147,6 +142,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;
}
@@ -155,7 +152,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>;
@@ -312,9 +309,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());
}
impl pallet_staking::Config for Runtime {
@@ -356,7 +350,7 @@ parameter_types! {
}
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 {