Streamline frame_system weight parametrization (#6629)

* Basic weights builder.

* Fixing WiP

* Make the tests work.

* Fix weights in node/runtime.

* WiP.

* Update pallets with new weights parameters.

* Validate returns a Result now.

* Count mandatory weight separately.

* DRY

* BREAKING: Updating state root, because of the left-over weight-tracking stuff

* Update tests affected by Mandatory tracking.

* Fixing tests.

* Fix defaults for simple_max

* Update frame/system/src/weights.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Rework the API a bit.

* Fix compilation & tests.

* Apply suggestions from code review

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Add extra docs & rename few things.

* Fix whitespace in ASCII art.

* Update frame/system/src/limits.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Fix max_extrinsic calculations.

* Fix conflicts.

* Fix compilation.

* Fix new code.

* re-remove generic asset

* Fix usage.

* Update state root.

* Update proxy.

* Fix tests.

* Move weights validity to integrity_test

* Remove redundant BlockWeights.

* Add all/non_mandatory comment

* Add test.

* Remove fn block_weights

* Make the macro prettier.

* Fix some docs.

* Make max_total behave more predictabily.

* Add BlockWeights to metadata.

* fix balances test

* Fix utility test.

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org>
Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Tomasz Drwięga
2020-12-08 13:18:34 +01:00
committed by GitHub
parent f6198b4c1b
commit 39a776cd00
66 changed files with 1275 additions and 929 deletions
@@ -1,8 +1,8 @@
use crate::{Module, Config};
use sp_core::H256;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, parameter_types};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup}, testing::Header, Perbill,
traits::{BlakeTwo256, IdentityLookup}, testing::Header,
};
use frame_system as system;
@@ -16,13 +16,13 @@ impl_outer_origin! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = ();
type Index = u64;
@@ -34,13 +34,6 @@ impl system::Config for Test {
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 = ();
+12 -24
View File
@@ -13,7 +13,7 @@ use sp_runtime::{
transaction_validity::{TransactionValidity, TransactionSource},
};
use sp_runtime::traits::{
BlakeTwo256, Block as BlockT, AccountIdLookup, Verify, IdentifyAccount, NumberFor, Saturating,
BlakeTwo256, Block as BlockT, AccountIdLookup, Verify, IdentifyAccount, NumberFor,
};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
@@ -126,16 +126,16 @@ pub fn native_version() -> NativeVersion {
}
}
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time.
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
/// Assume 10% of weight for average on_initialize calls.
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
.saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION;
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
}
// Configure FRAME pallets to include in runtime.
@@ -143,6 +143,10 @@ parameter_types! {
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
type BlockLength = BlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
@@ -165,24 +169,8 @@ impl frame_system::Config for Runtime {
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// Maximum weight of each block.
type MaximumBlockWeight = MaximumBlockWeight;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// The weight of the overhead invoked on the block import process, independent of the
/// extrinsics included in that block.
type BlockExecutionWeight = BlockExecutionWeight;
/// The base weight of any extrinsic processed by the runtime, independent of the
/// logic of that extrinsic. (Signature verification, nonce increment, fee, etc...)
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
/// The maximum weight that a single extrinsic of `Normal` dispatch class can have,
/// idependent of the logic of that extrinsics. (Roughly max block weight - average on
/// initialize cost).
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
type MaximumBlockLength = MaximumBlockLength;
/// Portion of the block weight that is available to all normal transactions.
type AvailableBlockRatio = AvailableBlockRatio;
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
+20 -14
View File
@@ -34,13 +34,15 @@ mod multiplier_tests {
use crate::{
constants::{currency::*, time::*},
TransactionPayment, MaximumBlockWeight, AvailableBlockRatio, Runtime, TargetBlockFullness,
TransactionPayment, Runtime, TargetBlockFullness,
AdjustmentVariable, System, MinimumMultiplier,
RuntimeBlockWeights as BlockWeights,
};
use frame_support::weights::{Weight, WeightToFeePolynomial};
use frame_support::weights::{Weight, WeightToFeePolynomial, DispatchClass};
fn max() -> Weight {
AvailableBlockRatio::get() * MaximumBlockWeight::get()
fn max_normal() -> Weight {
BlockWeights::get().get(DispatchClass::Normal).max_total
.unwrap_or_else(|| BlockWeights::get().max_block)
}
fn min_multiplier() -> Multiplier {
@@ -48,7 +50,7 @@ mod multiplier_tests {
}
fn target() -> Weight {
TargetBlockFullness::get() * max()
TargetBlockFullness::get() * max_normal()
}
// update based on runtime impl.
@@ -69,7 +71,7 @@ mod multiplier_tests {
let previous_float = previous_float.max(min_multiplier().into_inner() as f64 / accuracy);
// maximum tx weight
let m = max() as f64;
let m = max_normal() as f64;
// block weight always truncated to max weight
let block_weight = (block_weight as f64).min(m);
let v: f64 = AdjustmentVariable::get().to_fraction();
@@ -89,7 +91,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()
});
}
@@ -102,8 +104,8 @@ mod multiplier_tests {
(100, fm.clone()),
(1000, fm.clone()),
(target(), fm.clone()),
(max() / 2, fm.clone()),
(max(), fm.clone()),
(max_normal() / 2, fm.clone()),
(max_normal(), fm.clone()),
];
test_set.into_iter().for_each(|(w, fm)| {
run_with_system_weight(w, || {
@@ -164,7 +166,7 @@ mod multiplier_tests {
#[test]
fn min_change_per_day() {
run_with_system_weight(max(), || {
run_with_system_weight(max_normal(), || {
let mut fm = Multiplier::one();
// See the example in the doc of `TargetedFeeAdjustment`. are at least 0.234, hence
// `fm > 1.234`.
@@ -182,7 +184,7 @@ mod multiplier_tests {
// `cargo test congested_chain_simulation -- --nocapture` to get some insight.
// almost full. The entire quota of normal transactions is taken.
let block_weight = AvailableBlockRatio::get() * max() - 100;
let block_weight = BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap() - 100;
// Default substrate weight.
let tx_weight = frame_support::weights::constants::ExtrinsicBaseWeight::get();
@@ -320,15 +322,19 @@ mod multiplier_tests {
10 * mb,
2147483647,
4294967295,
MaximumBlockWeight::get() / 2,
MaximumBlockWeight::get(),
BlockWeights::get().max_block / 2,
BlockWeights::get().max_block,
Weight::max_value() / 2,
Weight::max_value(),
].into_iter().for_each(|i| {
run_with_system_weight(i, || {
let next = runtime_multiplier_update(Multiplier::one());
let truth = truth_value_update(i, Multiplier::one());
assert_eq_error_rate!(truth, next, Multiplier::from_inner(50_000_000));
assert_eq_error_rate!(
truth,
next,
Multiplier::from_inner(50_000_000)
);
});
});
+47 -24
View File
@@ -28,14 +28,17 @@ use frame_support::{
construct_runtime, parameter_types, debug, RuntimeDebug,
weights::{
Weight, IdentityFee,
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, DispatchClass,
},
traits::{
Currency, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness, LockIdentifier,
U128CurrencyToVote,
},
};
use frame_system::{EnsureRoot, EnsureOneOf};
use frame_system::{
EnsureRoot, EnsureOneOf,
limits::{BlockWeights, BlockLength}
};
use frame_support::traits::InstanceFilter;
use codec::{Encode, Decode};
use sp_core::{
@@ -54,7 +57,7 @@ use sp_runtime::curve::PiecewiseLinear;
use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority};
use sp_runtime::traits::{
self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion,
ConvertInto, OpaqueKeys, NumberFor, Saturating,
ConvertInto, OpaqueKeys, NumberFor,
};
use sp_version::RuntimeVersion;
#[cfg(any(feature = "std", test))]
@@ -141,23 +144,47 @@ impl OnUnbalanced<NegativeImbalance> for DealWithFees {
}
}
const AVERAGE_ON_INITIALIZE_WEIGHT: Perbill = Perbill::from_percent(10);
/// We assume that ~10% of the block weight is consumed by `on_initalize` handlers.
/// This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// 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.
const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time.
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
/// Assume 10% of weight for average on_initialize calls.
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get().saturating_sub(AVERAGE_ON_INITIALIZE_WEIGHT)
* MaximumBlockWeight::get();
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockWeights: BlockWeights = 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 some 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());
const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
type DbWeight = RocksDbWeight;
type Origin = Origin;
type Call = Call;
type Index = Index;
@@ -169,13 +196,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>;
@@ -277,7 +297,8 @@ impl pallet_proxy::Config for Runtime {
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) *
RuntimeBlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
}
@@ -438,9 +459,10 @@ parameter_types! {
pub const MaxIterations: u32 = 10;
// 0.05%. The higher the value, the more strict solution acceptance becomes.
pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
pub OffchainSolutionWeightLimit: Weight = MaximumExtrinsicWeight::get()
.saturating_sub(BlockExecutionWeight::get())
.saturating_sub(ExtrinsicBaseWeight::get());
pub OffchainSolutionWeightLimit: Weight = RuntimeBlockWeights::get()
.get(DispatchClass::Normal)
.max_extrinsic.expect("Normal extrinsics have a weight limit configured; qed")
.saturating_sub(BlockExecutionWeight::get());
}
impl pallet_staking::Config for Runtime {
@@ -779,7 +801,8 @@ impl pallet_im_online::Config for Runtime {
}
parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) *
RuntimeBlockWeights::get().max_block;
}
impl pallet_offences::Config for Runtime {
+5 -15
View File
@@ -905,12 +905,9 @@ impl<T: Config> Module<T> {
mod tests {
use super::*;
use frame_support::{
impl_outer_origin, impl_outer_event, assert_ok, assert_noop, parameter_types,
weights::Weight
};
use frame_support::{impl_outer_origin, assert_ok, assert_noop, parameter_types, impl_outer_event};
use sp_core::H256;
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
mod pallet_assets {
pub use crate::Event;
@@ -932,12 +929,12 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type Call = ();
@@ -949,13 +946,6 @@ mod tests {
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+6 -14
View File
@@ -2,12 +2,9 @@
use super::*;
use frame_support::{
impl_outer_origin, parameter_types, weights::Weight,
};
use frame_support::{impl_outer_origin, parameter_types};
use sp_core::H256;
use sp_runtime::{
Perbill,
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
@@ -20,12 +17,14 @@ impl_outer_origin! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -37,13 +36,6 @@ impl frame_system::Config for Test {
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>;
+7 -12
View File
@@ -22,10 +22,10 @@
use crate::{Config, Module, GenesisConfig};
use sp_consensus_aura::ed25519::AuthorityId;
use sp_runtime::{
traits::IdentityLookup, Perbill,
traits::IdentityLookup,
testing::{Header, UintAuthorityId},
};
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, parameter_types};
use sp_io;
use sp_core::H256;
@@ -39,14 +39,16 @@ pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
pub const MinimumPeriod: u64 = 1;
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -58,13 +60,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = ();
+7 -12
View File
@@ -93,7 +93,7 @@ impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
#[cfg(test)]
mod tests {
use super::*;
use sp_authority_discovery::{AuthorityPair};
use sp_authority_discovery::AuthorityPair;
use sp_application_crypto::Pair;
use sp_core::{crypto::key_types, H256};
use sp_io::TestExternalities;
@@ -101,7 +101,7 @@ mod tests {
testing::{Header, UintAuthorityId}, traits::{ConvertInto, IdentityLookup, OpaqueKeys},
Perbill, KeyTypeId,
};
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, parameter_types};
type AuthorityDiscovery = Module<Test>;
@@ -138,13 +138,15 @@ mod tests {
pub const Offset: BlockNumber = 0;
pub const UncleGenerations: u64 = 0;
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = BlockNumber;
@@ -156,13 +158,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = ();
+7 -12
View File
@@ -399,9 +399,9 @@ mod tests {
use super::*;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup}, testing::Header, generic::DigestItem, Perbill,
traits::{BlakeTwo256, IdentityLookup}, testing::Header, generic::DigestItem,
};
use frame_support::{parameter_types, impl_outer_origin, ConsensusEngineId, weights::Weight};
use frame_support::{parameter_types, impl_outer_origin, ConsensusEngineId};
impl_outer_origin!{
pub enum Origin for Test where system = frame_system {}
@@ -412,13 +412,15 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -430,13 +432,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = ();
+7 -11
View File
@@ -57,16 +57,18 @@ pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const EpochDuration: u64 = 3;
pub const ExpectedBlockTime: u64 = 1;
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(16);
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -79,13 +81,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u128>;
type OnNewAccount = ();
@@ -209,7 +204,8 @@ impl pallet_staking::Config for Test {
}
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 Test {
@@ -20,7 +20,6 @@
#![cfg(test)]
use sp_runtime::{
Perbill,
traits::IdentityLookup,
testing::Header,
};
@@ -52,13 +51,15 @@ impl_outer_event! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -70,13 +71,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = 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 = super::AccountData<u64>;
+5 -11
View File
@@ -20,7 +20,6 @@
#![cfg(test)]
use sp_runtime::{
Perbill,
traits::IdentityLookup,
testing::Header,
};
@@ -53,13 +52,15 @@ impl_outer_event! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -71,13 +72,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = 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 = super::AccountData<u64>;
+3 -7
View File
@@ -74,6 +74,9 @@ pub struct Test;
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -85,13 +88,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = ();
type BlockHashCount = ();
type MaximumBlockWeight = ();
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = ();
type MaximumBlockLength = ();
type AvailableBlockRatio = ();
type Version = ();
type PalletInfo = ();
type AccountData = ();
+7 -12
View File
@@ -933,27 +933,29 @@ impl<
#[cfg(test)]
mod tests {
use super::*;
use frame_support::{Hashable, assert_ok, assert_noop, parameter_types, weights::Weight};
use frame_support::{Hashable, assert_ok, assert_noop, parameter_types};
use frame_system::{self as system, EventRecord, Phase};
use hex_literal::hex;
use sp_core::H256;
use sp_runtime::{
Perbill, traits::{BlakeTwo256, IdentityLookup, Block as BlockT}, testing::Header,
traits::{BlakeTwo256, IdentityLookup, Block as BlockT}, testing::Header,
BuildStorage,
};
use crate as collective;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const MotionDuration: u64 = 3;
pub const MaxProposals: u32 = 100;
pub const MaxMembers: u32 = 100;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -965,13 +967,6 @@ mod tests {
type Header = Header;
type Event = 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 = ();
+5 -11
View File
@@ -23,7 +23,6 @@ use crate::{
use assert_matches::assert_matches;
use codec::Encode;
use sp_runtime::{
Perbill,
traits::{BlakeTwo256, Hash, IdentityLookup, Convert},
testing::{Header, H256},
AccountId32,
@@ -105,13 +104,15 @@ pub mod test_utils {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
pub static ExistentialDeposit: u64 = 0;
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -123,13 +124,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = MetaEvent;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+4 -3
View File
@@ -1086,7 +1086,7 @@ decl_module! {
}
/// Enact a proposal from a referendum. For now we just make the weight be the maximum.
#[weight = T::MaximumBlockWeight::get()]
#[weight = T::BlockWeights::get().max_block]
fn enact_proposal(origin, proposal_hash: T::Hash, index: ReferendumIndex) -> DispatchResult {
ensure_root(origin)?;
Self::do_enact_proposal(proposal_hash, index)
@@ -1609,6 +1609,7 @@ impl<T: Config> Module<T> {
/// - Db reads per R: `DepositOf`, `ReferendumInfoOf`
/// # </weight>
fn begin_block(now: T::BlockNumber) -> Result<Weight, DispatchError> {
let max_block_weight = T::BlockWeights::get().max_block;
let mut weight = 0;
// pick out another public referendum if it's time.
@@ -1616,7 +1617,7 @@ impl<T: Config> Module<T> {
// Errors come from the queue being empty. we don't really care about that, and even if
// we did, there is nothing we can do here.
let _ = Self::launch_next(now);
weight = T::MaximumBlockWeight::get();
weight = max_block_weight;
}
let next = Self::lowest_unbaked();
@@ -1627,7 +1628,7 @@ impl<T: Config> Module<T> {
for (index, info) in Self::maturing_referenda_at_inner(now, next..last).into_iter() {
let approved = Self::bake_referendum(now, index, info)?;
ReferendumInfoOf::<T>::insert(index, ReferendumInfo::Finished { end: now, approved });
weight = T::MaximumBlockWeight::get();
weight = max_block_weight;
}
Ok(weight)
+6 -11
View File
@@ -88,12 +88,14 @@ impl Filter<Call> for BaseFilter {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1_000_000;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1_000_000);
}
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -105,13 +107,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = 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>;
@@ -120,7 +115,7 @@ impl frame_system::Config for Test {
type SystemWeightInfo = ();
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
}
impl pallet_scheduler::Config for Test {
type Event = Event;
+9 -16
View File
@@ -621,7 +621,7 @@ decl_module! {
#[weight = if *has_replacement {
T::WeightInfo::remove_member_with_replacement()
} else {
T::MaximumBlockWeight::get()
T::BlockWeights::get().max_block
}]
fn remove_member(
origin,
@@ -829,7 +829,7 @@ impl<T: Config> Module<T> {
if !Self::term_duration().is_zero() {
if (block_number % Self::term_duration()).is_zero() {
Self::do_phragmen();
return T::MaximumBlockWeight::get()
return T::BlockWeights::get().max_block;
}
}
0
@@ -1058,26 +1058,26 @@ impl<T: Config> ContainsLengthBound for Module<T> {
#[cfg(test)]
mod tests {
use super::*;
use frame_support::{assert_ok, assert_noop, assert_err_with_weight, parameter_types,
weights::Weight,
};
use frame_support::{assert_ok, assert_noop, assert_err_with_weight, parameter_types};
use substrate_test_utils::assert_eq_uvec;
use sp_core::H256;
use sp_runtime::{
Perbill, testing::Header, BuildStorage, DispatchResult,
testing::Header, BuildStorage, DispatchResult,
traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
};
use crate as elections_phragmen;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -1089,13 +1089,6 @@ mod tests {
type Header = Header;
type Event = 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>;
+6 -12
View File
@@ -22,23 +22,24 @@
use frame_support::{
StorageValue, StorageMap, parameter_types, assert_ok,
traits::{ChangeMembers, Currency, LockIdentifier},
weights::Weight,
};
use sp_core::H256;
use sp_runtime::{
Perbill, BuildStorage, testing::Header, traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
BuildStorage, testing::Header, traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
};
use crate as elections;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
@@ -50,13 +51,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = 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>;
@@ -20,7 +20,6 @@ use std::sync::Arc;
use codec::{Encode, Decode};
use frame_support::{
assert_ok, impl_outer_origin, parameter_types,
weights::Weight,
};
use sp_core::{
H256,
@@ -33,7 +32,7 @@ use sp_keystore::{
testing::KeyStore,
};
use sp_runtime::{
Perbill, RuntimeAppPublic,
RuntimeAppPublic,
testing::{Header, TestXt},
traits::{
BlakeTwo256, IdentityLookup, Extrinsic as ExtrinsicT,
@@ -52,12 +51,14 @@ impl_outer_origin! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = ();
type Index = u64;
@@ -69,13 +70,6 @@ impl frame_system::Config for Test {
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 = ();
@@ -18,7 +18,7 @@
use crate::*;
use codec::{Encode, Decode};
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, parameter_types};
use sp_core::H256;
use sp_runtime::{
Perbill,
@@ -34,8 +34,6 @@ impl_outer_origin! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
@@ -53,13 +51,9 @@ impl frame_system::Config for Test {
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 = ();
type BlockLength = ();
type Version = ();
type AccountData = ();
type OnNewAccount = ();
+5 -11
View File
@@ -718,7 +718,6 @@ 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,
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
@@ -740,12 +739,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -757,13 +758,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>;
+36 -26
View File
@@ -251,8 +251,12 @@ where
weight = weight.saturating_add(
<frame_system::Module<System> as OnInitialize<System::BlockNumber>>::on_initialize(*block_number)
);
weight = weight.saturating_add(<AllModules as OnInitialize<System::BlockNumber>>::on_initialize(*block_number))
.saturating_add(<System::BlockExecutionWeight as frame_support::traits::Get<_>>::get());
weight = weight.saturating_add(
<AllModules as OnInitialize<System::BlockNumber>>::on_initialize(*block_number)
);
weight = weight.saturating_add(
<System::BlockWeights as frame_support::traits::Get<_>>::get().base_block
);
<frame_system::Module::<System>>::register_extra_weight_unchecked(weight, DispatchClass::Mandatory);
frame_system::Module::<System>::note_finished_initialize();
@@ -482,7 +486,7 @@ mod tests {
use super::*;
use sp_core::H256;
use sp_runtime::{
generic::{Era, DigestItem}, Perbill, DispatchError, testing::{Digest, Header, Block},
generic::{Era, DigestItem}, DispatchError, testing::{Digest, Header, Block},
traits::{Header as HeaderT, BlakeTwo256, IdentityLookup},
transaction_validity::{
InvalidTransaction, ValidTransaction, TransactionValidityError, UnknownTransaction
@@ -493,7 +497,9 @@ mod tests {
weights::{Weight, RuntimeDbWeight, IdentityFee, WeightToFeePolynomial},
traits::{Currency, LockIdentifier, LockableCurrency, WithdrawReasons},
};
use frame_system::{Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo};
use frame_system::{
Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo,
};
use pallet_transaction_payment::CurrencyAdapter;
use pallet_balances::Call as BalancesCall;
use hex_literal::hex;
@@ -584,11 +590,12 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const BlockExecutionWeight: Weight = 10;
pub const ExtrinsicBaseWeight: Weight = 5;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::builder()
.base_block(10)
.for_class(DispatchClass::all(), |weights| weights.base_extrinsic = 5)
.for_class(DispatchClass::non_mandatory(), |weights| weights.max_total = 1024.into())
.build_or_panic();
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 10,
write: 100,
@@ -596,6 +603,9 @@ mod tests {
}
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type Call = Call;
@@ -607,13 +617,6 @@ mod tests {
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = DbWeight;
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = RuntimeVersion;
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
@@ -715,7 +718,8 @@ mod tests {
balances: vec![(1, 211)],
}.assimilate_storage(&mut t).unwrap();
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(2, 69)), sign_extra(1, 0, 0));
let weight = xt.get_dispatch_info().weight + <Runtime as frame_system::Config>::ExtrinsicBaseWeight::get();
let weight = xt.get_dispatch_info().weight +
<Runtime as frame_system::Config>::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic;
let fee: Balance
= <Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(&weight);
let mut t = sp_io::TestExternalities::new(t);
@@ -749,7 +753,7 @@ mod tests {
header: Header {
parent_hash: [69u8; 32].into(),
number: 1,
state_root: hex!("465a1569d309039bdf84b0479d28064ea29e6584584dc7d788904bb14489c6f6").into(),
state_root: hex!("6a3ad91caba5b8ac15c325a36d7568adf6a7e49321865de7527b851d870343d4").into(),
extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(),
digest: Digest { logs: vec![], },
},
@@ -817,9 +821,11 @@ mod tests {
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(33, 0)), sign_extra(1, 0, 0));
let encoded = xt.encode();
let encoded_len = encoded.len() as Weight;
// on_initialize weight + block execution weight
let base_block_weight = 175 + <Runtime as frame_system::Config>::BlockExecutionWeight::get();
let limit = AvailableBlockRatio::get() * MaximumBlockWeight::get() - base_block_weight;
// on_initialize weight + base block execution weight
let block_weights = <Runtime as frame_system::Config>::BlockWeights::get();
let base_block_weight = 175 + block_weights.base_block;
let limit = block_weights.get(DispatchClass::Normal).max_total.unwrap()
- base_block_weight;
let num_to_exhaust_block = limit / (encoded_len + 5);
t.execute_with(|| {
Executive::initialize_block(&Header::new(
@@ -861,7 +867,7 @@ mod tests {
let mut t = new_test_ext(1);
t.execute_with(|| {
// Block execution weight + on_initialize weight from custom module
let base_block_weight = 175 + <Runtime as frame_system::Config>::BlockExecutionWeight::get();
let base_block_weight = 175 + <Runtime as frame_system::Config>::BlockWeights::get().base_block;
Executive::initialize_block(&Header::new(
1,
@@ -879,7 +885,8 @@ mod tests {
assert!(Executive::apply_extrinsic(x2.clone()).unwrap().is_ok());
// default weight for `TestXt` == encoded length.
let extrinsic_weight = len as Weight + <Runtime as frame_system::Config>::ExtrinsicBaseWeight::get();
let extrinsic_weight = len as Weight + <Runtime as frame_system::Config>::BlockWeights
::get().get(DispatchClass::Normal).base_extrinsic;
assert_eq!(
<frame_system::Module<Runtime>>::block_weight().total(),
base_block_weight + 3 * extrinsic_weight,
@@ -945,8 +952,11 @@ mod tests {
Call::System(SystemCall::remark(vec![1u8])),
sign_extra(1, 0, 0),
);
let weight = xt.get_dispatch_info().weight
+ <Runtime as frame_system::Config>::ExtrinsicBaseWeight::get();
let weight = xt.get_dispatch_info().weight + <Runtime as frame_system::Config>
::BlockWeights
::get()
.get(DispatchClass::Normal)
.base_extrinsic;
let fee: Balance =
<Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(&weight);
Executive::initialize_block(&Header::new(
@@ -1106,7 +1116,7 @@ mod tests {
let runtime_upgrade_weight = <AllModules as OnRuntimeUpgrade>::on_runtime_upgrade();
let frame_system_on_initialize_weight = frame_system::Module::<Runtime>::on_initialize(block_number);
let on_initialize_weight = <AllModules as OnInitialize<u64>>::on_initialize(block_number);
let base_block_weight = <Runtime as frame_system::Config>::BlockExecutionWeight::get();
let base_block_weight = <Runtime as frame_system::Config>::BlockWeights::get().base_block;
// Weights are recorded correctly
assert_eq!(
+6 -11
View File
@@ -74,13 +74,15 @@ pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -92,13 +94,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>;
@@ -224,7 +219,7 @@ impl pallet_staking::Config for Test {
}
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 Test {
+1
View File
@@ -1134,3 +1134,4 @@ impl<T: Config> Module<T> {
.collect()
}
}
+6 -11
View File
@@ -21,13 +21,13 @@ use super::*;
use sp_runtime::traits::BadOrigin;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight,
assert_ok, assert_noop, impl_outer_origin, parameter_types,
ord_parameter_types,
};
use sp_core::H256;
use frame_system::{EnsureSignedBy, EnsureOneOf, EnsureRoot};
use sp_runtime::{
Perbill, testing::Header, traits::{BlakeTwo256, IdentityLookup},
testing::Header, traits::{BlakeTwo256, IdentityLookup},
};
impl_outer_origin! {
@@ -38,12 +38,13 @@ impl_outer_origin! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -55,13 +56,7 @@ impl frame_system::Config for Test {
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>;
+6 -11
View File
@@ -27,7 +27,7 @@ use sp_staking::{SessionIndex, offence::{ReportOffence, OffenceError}};
use sp_runtime::testing::{Header, UintAuthorityId, TestXt};
use sp_runtime::traits::{IdentityLookup, BlakeTwo256, ConvertInto};
use sp_core::H256;
use frame_support::{impl_outer_origin, impl_outer_dispatch, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, impl_outer_dispatch, parameter_types};
impl_outer_origin!{
pub enum Origin for Runtime {}
@@ -104,13 +104,15 @@ pub struct Runtime;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -122,13 +124,6 @@ impl frame_system::Config for Runtime {
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 = ();
+6 -12
View File
@@ -20,9 +20,8 @@
#![cfg(test)]
use sp_runtime::testing::Header;
use sp_runtime::Perbill;
use sp_core::H256;
use frame_support::{impl_outer_origin, impl_outer_event, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, impl_outer_event, parameter_types};
use crate::{self as indices, Module, Config};
use frame_system as system;
use pallet_balances as balances;
@@ -44,13 +43,15 @@ pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = ();
type Index = u64;
@@ -62,13 +63,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = MetaEvent;
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>;
+7 -12
View File
@@ -279,11 +279,11 @@ mod tests {
use super::*;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight,
assert_ok, assert_noop, impl_outer_origin, parameter_types,
ord_parameter_types
};
use sp_core::H256;
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup, BadOrigin}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup, BadOrigin}, testing::Header};
use frame_system::EnsureSignedBy;
impl_outer_origin! {
@@ -294,14 +294,16 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
pub static Members: Vec<u64> = vec![];
pub static Prime: Option<u64> = None;
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -313,13 +315,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 = ();
+7 -12
View File
@@ -23,10 +23,10 @@ use super::*;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, impl_outer_dispatch,
weights::Weight, impl_outer_event, traits::Filter,
impl_outer_event, traits::Filter,
};
use sp_core::H256;
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use crate as multisig;
impl_outer_origin! {
@@ -55,12 +55,14 @@ impl_outer_dispatch! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = TestBaseCallFilter;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -72,13 +74,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<u64>;
+7 -12
View File
@@ -241,13 +241,13 @@ mod tests {
use super::*;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight,
assert_ok, assert_noop, impl_outer_origin, parameter_types,
ord_parameter_types
};
use sp_core::H256;
use frame_system::EnsureSignedBy;
use sp_runtime::{
Perbill, testing::Header, traits::{BlakeTwo256, IdentityLookup, BadOrigin},
testing::Header, traits::{BlakeTwo256, IdentityLookup, BadOrigin},
};
impl_outer_origin! {
@@ -258,12 +258,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -275,13 +277,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>;
+7 -14
View File
@@ -267,7 +267,7 @@ decl_module! {
pub fn reset_well_known_nodes(origin, nodes: Vec<(PeerId, T::AccountId)>) {
T::ResetOrigin::ensure_origin(origin)?;
ensure!(nodes.len() < T::MaxWellKnownNodes::get() as usize, Error::<T>::TooManyNodes);
Self::initialize_nodes(&nodes);
Self::deposit_event(RawEvent::NodesReset(nodes));
@@ -280,7 +280,7 @@ decl_module! {
#[weight = T::WeightInfo::claim_node()]
pub fn claim_node(origin, node: PeerId) {
let sender = ensure_signed(origin)?;
ensure!(node.0.len() < T::MaxPeerIdLength::get() as usize, Error::<T>::PeerIdTooLong);
ensure!(!Owners::<T>::contains_key(&node),Error::<T>::AlreadyClaimed);
@@ -433,12 +433,12 @@ mod tests {
use super::*;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, weights::Weight,
assert_ok, assert_noop, impl_outer_origin,
parameter_types, ord_parameter_types,
};
use frame_system::EnsureSignedBy;
use sp_core::H256;
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup, BadOrigin}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup, BadOrigin}, testing::Header};
impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
@@ -449,12 +449,12 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type DbWeight = ();
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -466,13 +466,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 = ();
@@ -37,11 +37,15 @@ type BlockNumber = u64;
type Balance = u64;
parameter_types! {
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(2 * WEIGHT_PER_SECOND);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
@@ -53,18 +57,11 @@ impl frame_system::Config for Test {
type Header = sp_runtime::testing::Header;
type Event = Event;
type BlockHashCount = ();
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type AvailableBlockRatio = ();
type MaximumBlockLength = ();
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = (Balances,);
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = ();
type SystemWeightInfo = ();
}
parameter_types! {
@@ -184,7 +181,7 @@ impl pallet_im_online::Config for Test {
}
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 Test {
+7 -11
View File
@@ -91,12 +91,14 @@ pub fn set_offence_weight(new: Weight) {
pub struct Runtime;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(2 * WEIGHT_PER_SECOND);
}
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = RocksDbWeight;
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -108,13 +110,6 @@ impl frame_system::Config for Runtime {
type Header = Header;
type Event = TestEvent;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = RocksDbWeight;
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = ();
@@ -124,7 +119,8 @@ impl frame_system::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 Config for Runtime {
+1 -1
View File
@@ -727,6 +727,6 @@ pub mod migration {
deposit,
))
);
T::MaximumBlockWeight::get()
T::BlockWeights::get().max_block
}
}
+7 -12
View File
@@ -23,11 +23,11 @@ use super::*;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, impl_outer_dispatch,
weights::Weight, impl_outer_event, RuntimeDebug, dispatch::DispatchError, traits::Filter,
impl_outer_event, RuntimeDebug, dispatch::DispatchError, traits::Filter,
};
use codec::{Encode, Decode};
use sp_core::H256;
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use crate as proxy;
impl_outer_origin! {
@@ -57,12 +57,14 @@ impl_outer_dispatch! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -74,13 +76,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<u64>;
@@ -135,12 +135,12 @@ mod tests {
use super::*;
use sp_core::H256;
use sp_runtime::{
Perbill,
testing::Header,
traits::{BlakeTwo256, Header as _, IdentityLookup},
};
use frame_system::limits;
use frame_support::{
impl_outer_origin, parameter_types, weights::Weight, traits::{Randomness, OnInitialize},
impl_outer_origin, parameter_types, traits::{Randomness, OnInitialize},
};
#[derive(Clone, PartialEq, Eq)]
@@ -152,13 +152,17 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: limits::BlockWeights = limits::BlockWeights
::simple_max(1024);
pub BlockLength: limits::BlockLength = limits::BlockLength
::max(2 * 1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = BlockLength;
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -170,13 +174,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = ();
+6 -12
View File
@@ -21,12 +21,11 @@ use super::*;
use frame_support::{
impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types,
weights::Weight,
traits::{OnInitialize, OnFinalize},
};
use sp_core::H256;
use sp_runtime::{
Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header,
traits::{BlakeTwo256, IdentityLookup}, testing::Header,
};
use crate as recovery;
@@ -53,13 +52,15 @@ pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
@@ -71,13 +72,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>;
+6 -11
View File
@@ -812,12 +812,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 2_000_000_000_000;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(2_000_000_000_000);
}
impl system::Config for Test {
type BaseCallFilter = BaseFilter;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = RocksDbWeight;
type Origin = Origin;
type Call = Call;
type Index = u64;
@@ -829,13 +831,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = RocksDbWeight;
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type PalletInfo = ();
type AccountData = ();
@@ -847,7 +842,7 @@ mod tests {
type Event = ();
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 10;
}
ord_parameter_types! {
+7 -14
View File
@@ -20,10 +20,10 @@
use super::*;
use std::cell::RefCell;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight, ord_parameter_types};
use frame_support::{impl_outer_origin, parameter_types, ord_parameter_types};
use sp_core::H256;
use sp_runtime::{
Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header,
traits::{BlakeTwo256, IdentityLookup}, testing::Header,
};
use frame_system::EnsureSignedBy;
@@ -36,13 +36,10 @@ pub struct Test;
parameter_types! {
pub const CandidateDeposit: u64 = 25;
pub const Period: u64 = 4;
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const ExistentialDeposit: u64 = 1;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
ord_parameter_types! {
pub const KickOrigin: u64 = 2;
@@ -51,6 +48,9 @@ ord_parameter_types! {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -62,13 +62,6 @@ impl frame_system::Config for Test {
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>;
@@ -47,6 +47,9 @@ pub struct Test;
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
@@ -58,13 +61,6 @@ impl frame_system::Config for Test {
type Header = sp_runtime::testing::Header;
type Event = ();
type BlockHashCount = ();
type MaximumBlockWeight = ();
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = ();
type AvailableBlockRatio = ();
type MaximumBlockLength = ();
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+1 -1
View File
@@ -549,7 +549,7 @@ decl_module! {
fn on_initialize(n: T::BlockNumber) -> Weight {
if T::ShouldEndSession::should_end_session(n) {
Self::rotate_session();
T::MaximumBlockWeight::get()
T::BlockWeights::get().max_block
} else {
// NOTE: the non-database part of the weight for `should_end_session(n)` is
// included as weight for empty block, the database part is expected to be in
+7 -12
View File
@@ -19,7 +19,7 @@
use super::*;
use std::cell::RefCell;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, parameter_types};
use sp_core::{crypto::key_types::DUMMY, H256};
use sp_runtime::{
Perbill, impl_opaque_keys,
@@ -165,15 +165,17 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const MinimumPeriod: u64 = 5;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -185,13 +187,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = ();
+15 -14
View File
@@ -533,7 +533,7 @@ decl_module! {
///
/// Total Complexity: O(M + B + C + logM + logB + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn bid(origin, value: BalanceOf<T, I>) -> DispatchResult {
let who = ensure_signed(origin)?;
ensure!(!<SuspendedCandidates<T, I>>::contains_key(&who), Error::<T, I>::Suspended);
@@ -572,7 +572,7 @@ decl_module! {
///
/// Total Complexity: O(B + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn unbid(origin, pos: u32) -> DispatchResult {
let who = ensure_signed(origin)?;
@@ -642,7 +642,7 @@ decl_module! {
///
/// Total Complexity: O(M + B + C + logM + logB + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn vouch(origin, who: T::AccountId, value: BalanceOf<T, I>, tip: BalanceOf<T, I>) -> DispatchResult {
let voucher = ensure_signed(origin)?;
// Check user is not suspended.
@@ -683,7 +683,7 @@ decl_module! {
///
/// Total Complexity: O(B)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn unvouch(origin, pos: u32) -> DispatchResult {
let voucher = ensure_signed(origin)?;
ensure!(Self::vouching(&voucher) == Some(VouchingStatus::Vouching), Error::<T, I>::NotVouching);
@@ -721,7 +721,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + C)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn vote(origin, candidate: <T::Lookup as StaticLookup>::Source, approve: bool) {
let voter = ensure_signed(origin)?;
let candidate = T::Lookup::lookup(candidate)?;
@@ -752,7 +752,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn defender_vote(origin, approve: bool) {
let voter = ensure_signed(origin)?;
let members = <Members<T, I>>::get();
@@ -784,7 +784,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + P + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
pub fn payout(origin) {
let who = ensure_signed(origin)?;
@@ -826,7 +826,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn found(origin, founder: T::AccountId, max_members: u32, rules: Vec<u8>) {
T::FounderSetOrigin::ensure_origin(origin)?;
ensure!(!<Head<T, I>>::exists(), Error::<T, I>::AlreadyFounded);
@@ -853,7 +853,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn unfound(origin) {
let founder = ensure_signed(origin)?;
ensure!(Founder::<T, I>::get() == Some(founder.clone()), Error::<T, I>::NotFounder);
@@ -895,7 +895,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + B)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn judge_suspended_member(origin, who: T::AccountId, forgive: bool) {
T::SuspensionJudgementOrigin::ensure_origin(origin)?;
ensure!(<SuspendedMembers<T, I>>::contains_key(&who), Error::<T, I>::NotSuspended);
@@ -966,7 +966,7 @@ decl_module! {
///
/// Total Complexity: O(M + logM + B + X)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn judge_suspended_candidate(origin, who: T::AccountId, judgement: Judgement) {
T::SuspensionJudgementOrigin::ensure_origin(origin)?;
if let Some((value, kind)) = <SuspendedCandidates<T, I>>::get(&who) {
@@ -1026,7 +1026,7 @@ decl_module! {
///
/// Total Complexity: O(1)
/// # </weight>
#[weight = T::MaximumBlockWeight::get() / 10]
#[weight = T::BlockWeights::get().max_block / 10]
fn set_max_members(origin, max: u32) {
ensure_root(origin)?;
ensure!(max > 1, Error::<T, I>::MaxMembers);
@@ -1038,13 +1038,14 @@ decl_module! {
let mut members = vec![];
let mut weight = 0;
let weights = T::BlockWeights::get();
// Run a candidate/membership rotation
if (n % T::RotationPeriod::get()).is_zero() {
members = <Members<T, I>>::get();
Self::rotate_period(&mut members);
weight += T::MaximumBlockWeight::get() / 20;
weight += weights.max_block / 20;
}
// Run a challenge rotation
@@ -1055,7 +1056,7 @@ decl_module! {
}
Self::rotate_challenge(&mut members);
weight += T::MaximumBlockWeight::get() / 20;
weight += weights.max_block / 20;
}
weight
+5 -13
View File
@@ -25,7 +25,6 @@ use frame_support::{
};
use sp_core::H256;
use sp_runtime::{
Perbill,
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
@@ -45,14 +44,11 @@ parameter_types! {
pub const PeriodSpend: u64 = 1000;
pub const MaxLockDuration: u64 = 100;
pub const ChallengePeriod: u64 = 8;
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const ExistentialDeposit: u64 = 1;
pub const SocietyModuleId: ModuleId = ModuleId(*b"py/socie");
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
ord_parameter_types! {
@@ -62,6 +58,9 @@ ord_parameter_types! {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -73,13 +72,6 @@ impl frame_system::Config for Test {
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 OnNewAccount = ();
+3 -7
View File
@@ -45,11 +45,10 @@ pub struct Test;
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = ();
type Origin = Origin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
type Call = Call;
@@ -60,9 +59,6 @@ impl frame_system::Config for Test {
type Header = sp_runtime::testing::Header;
type Event = ();
type BlockHashCount = ();
type MaximumBlockWeight = ();
type AvailableBlockRatio = ();
type MaximumBlockLength = ();
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+12 -2
View File
@@ -521,7 +521,12 @@ benchmarks! {
compact,
score,
size
) = offchain_election::prepare_submission::<T>(assignments, winners, false, T::MaximumBlockWeight::get()).unwrap();
) = offchain_election::prepare_submission::<T>(
assignments,
winners,
false,
T::BlockWeights::get().max_block,
).unwrap();
assert_eq!(
winners.len(), compact.unique_targets().len(),
@@ -589,7 +594,12 @@ benchmarks! {
compact,
score,
size
) = offchain_election::prepare_submission::<T>(assignments, winners, false, T::MaximumBlockWeight::get()).unwrap();
) = offchain_election::prepare_submission::<T>(
assignments,
winners,
false,
T::BlockWeights::get().max_block,
).unwrap();
assert_eq!(
winners.len(), compact.unique_targets().len(),
+8 -11
View File
@@ -129,9 +129,10 @@ pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = frame_support::weights::constants::WEIGHT_PER_SECOND * 2;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(
frame_support::weights::constants::WEIGHT_PER_SECOND * 2
);
pub const MaxLocks: u32 = 1024;
pub static SessionsPerEra: SessionIndex = 3;
pub static ExistentialDeposit: Balance = 0;
@@ -143,6 +144,9 @@ parameter_types! {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = RocksDbWeight;
type Origin = Origin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
@@ -154,13 +158,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = MetaEvent;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = RocksDbWeight;
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<Balance>;
@@ -235,7 +232,7 @@ parameter_types! {
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const UnsignedPriority: u64 = 1 << 20;
pub const MinSolutionScoreBump: Perbill = Perbill::zero();
pub const OffchainSolutionWeightLimit: Weight = MaximumBlockWeight::get();
pub OffchainSolutionWeightLimit: Weight = BlockWeights::get().max_block;
}
thread_local! {
+1 -1
View File
@@ -301,7 +301,7 @@ pub fn get_seq_phragmen_solution<T: Config>(
assignments,
winners,
do_reduce,
T::MaximumBlockWeight::get(),
T::BlockWeights::get().max_block,
)
.unwrap()
}
+6 -11
View File
@@ -23,10 +23,11 @@ use frame_support::{
weights::Weight,
};
use sp_core::H256;
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_io;
use crate as sudo;
use frame_support::traits::Filter;
use frame_system::limits;
// Logger module to track execution.
pub mod logger {
@@ -106,9 +107,7 @@ pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::simple_max(1024);
}
pub struct BlockEverything;
@@ -120,6 +119,9 @@ impl Filter<Call> for BlockEverything {
impl frame_system::Config for Test {
type BaseCallFilter = BlockEverything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Call = Call;
type Index = u64;
@@ -131,13 +133,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 = ();
+117
View File
@@ -213,6 +213,9 @@ impl Default for Pays {
}
/// A generalized group of dispatch types.
///
/// NOTE whenever upgrading the enum make sure to also update
/// [DispatchClass::all] and [DispatchClass::non_mandatory] helper functions.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug)]
@@ -242,6 +245,39 @@ impl Default for DispatchClass {
}
}
impl DispatchClass {
/// Returns an array containing all dispatch classes.
pub fn all() -> &'static [DispatchClass] {
&[DispatchClass::Normal, DispatchClass::Operational, DispatchClass::Mandatory]
}
/// Returns an array of all dispatch classes except `Mandatory`.
pub fn non_mandatory() -> &'static [DispatchClass] {
&[DispatchClass::Normal, DispatchClass::Operational]
}
}
/// A trait that represents one or many values of given type.
///
/// Useful to accept as parameter type to let the caller pass either a single value directly
/// or an iterator.
pub trait OneOrMany<T> {
/// The iterator type.
type Iter: Iterator<Item = T>;
/// Convert this item into an iterator.
fn into_iter(self) -> Self::Iter;
}
impl OneOrMany<DispatchClass> for DispatchClass {
type Iter = sp_std::iter::Once<DispatchClass>;
fn into_iter(self) -> Self::Iter { sp_std::iter::once(self) }
}
impl<'a> OneOrMany<DispatchClass> for &'a [DispatchClass] {
type Iter = sp_std::iter::Cloned<sp_std::slice::Iter<'a, DispatchClass>>;
fn into_iter(self) -> Self::Iter { self.iter().cloned() }
}
/// Primitives related to priority management of Frame.
pub mod priority {
/// The starting point of all Operational transactions. 3/4 of u64::max_value().
@@ -695,6 +731,87 @@ impl<T> WeightToFeePolynomial for IdentityFee<T> where
}
}
/// A struct holding value for each `DispatchClass`.
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
pub struct PerDispatchClass<T> {
/// Value for `Normal` extrinsics.
normal: T,
/// Value for `Operational` extrinsics.
operational: T,
/// Value for `Mandatory` extrinsics.
mandatory: T,
}
impl<T> PerDispatchClass<T> {
/// Create new `PerDispatchClass` with the same value for every class.
pub fn new(val: impl Fn(DispatchClass) -> T) -> Self {
Self {
normal: val(DispatchClass::Normal),
operational: val(DispatchClass::Operational),
mandatory: val(DispatchClass::Mandatory),
}
}
/// Get a mutable reference to current value of given class.
pub fn get_mut(&mut self, class: DispatchClass) -> &mut T {
match class {
DispatchClass::Operational => &mut self.operational,
DispatchClass::Normal => &mut self.normal,
DispatchClass::Mandatory => &mut self.mandatory,
}
}
/// Get current value for given class.
pub fn get(&self, class: DispatchClass) -> &T {
match class {
DispatchClass::Normal => &self.normal,
DispatchClass::Operational => &self.operational,
DispatchClass::Mandatory => &self.mandatory,
}
}
}
impl<T: Clone> PerDispatchClass<T> {
/// Set the value of given class.
pub fn set(&mut self, new: T, class: impl OneOrMany<DispatchClass>) {
for class in class.into_iter() {
*self.get_mut(class) = new.clone();
}
}
}
impl PerDispatchClass<Weight> {
/// Returns the total weight consumed by all extrinsics in the block.
pub fn total(&self) -> Weight {
let mut sum = 0;
for class in DispatchClass::all() {
sum = sum.saturating_add(*self.get(*class));
}
sum
}
/// Add some weight of a specific dispatch class, saturating at the numeric bounds of `Weight`.
pub fn add(&mut self, weight: Weight, class: DispatchClass) {
let value = self.get_mut(class);
*value = value.saturating_add(weight);
}
/// Try to add some weight of a specific dispatch class, returning Err(()) if overflow would
/// occur.
pub fn checked_add(&mut self, weight: Weight, class: DispatchClass) -> Result<(), ()> {
let value = self.get_mut(class);
*value = value.checked_add(weight).ok_or(())?;
Ok(())
}
/// Subtract some weight of a specific dispatch class, saturating at the numeric bounds of
/// `Weight`.
pub fn sub(&mut self, weight: Weight, class: DispatchClass) {
let value = self.get_mut(class);
*value = value.saturating_sub(weight);
}
}
#[cfg(test)]
#[allow(dead_code)]
mod tests {
@@ -117,9 +117,6 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: frame_support::weights::Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: sp_runtime::Perbill = sp_runtime::Perbill::one();
}
impl frame_system::Config for Runtime {
@@ -135,13 +132,9 @@ mod tests {
type Header = TestHeader;
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 = ();
type BlockLength = ();
type Version = ();
type PalletInfo = ();
type AccountData = ();
+11 -10
View File
@@ -54,14 +54,22 @@ impl_outer_event! {
frame_support::parameter_types! {
pub const BlockHashCount: u64 = 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::with_sensible_defaults(
4 * 1024 * 1024, Perbill::from_percent(75),
);
pub BlockLength: frame_system::limits::BlockLength =
frame_system::limits::BlockLength::max_with_normal_ratio(
4 * 1024 * 1024, Perbill::from_percent(75),
);
}
#[derive(Clone, Eq, PartialEq)]
pub struct Runtime;
impl system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = BlockLength;
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -73,13 +81,6 @@ impl system::Config for Runtime {
type Header = Header;
type Event = 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 = ();
@@ -25,8 +25,10 @@ use sp_std::prelude::*;
use sp_core::{ChangesTrieConfiguration, storage::well_known_keys};
use sp_runtime::traits::Hash;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_support::traits::Get;
use frame_support::storage::{self, StorageMap};
use frame_support::{
storage::{self, StorageMap},
traits::Get,
};
use frame_system::{Module as System, Call, RawOrigin, DigestItemOf, AccountInfo};
mod mock;
@@ -38,7 +40,7 @@ benchmarks! {
_ { }
remark {
let b in 0 .. T::MaximumBlockLength::get();
let b in 0 .. T::BlockWeights::get().max_block as u32;
let remark_message = vec![1; b as usize];
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), remark_message)
@@ -52,6 +52,9 @@ pub struct Test;
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
@@ -63,13 +66,6 @@ impl frame_system::Config for Test {
type Header = sp_runtime::testing::Header;
type Event = ();
type BlockHashCount = ();
type MaximumBlockWeight = ();
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = ();
type AvailableBlockRatio = ();
type MaximumBlockLength = ();
type Version = ();
type PalletInfo = ();
type AccountData = ();
@@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::{Config, Module};
use crate::{limits::BlockWeights, Config, Module};
use codec::{Encode, Decode};
use sp_runtime::{
traits::{SignedExtension, DispatchInfoOf, Dispatchable, PostDispatchInfoOf, Printable},
@@ -23,7 +23,7 @@ use sp_runtime::{
ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity,
TransactionPriority,
},
Perbill, DispatchResult,
DispatchResult,
};
use frame_support::{
traits::{Get},
@@ -36,52 +36,19 @@ use frame_support::{
pub struct CheckWeight<T: Config + Send + Sync>(sp_std::marker::PhantomData<T>);
impl<T: Config + Send + Sync> CheckWeight<T> where
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>,
{
/// Get the quota ratio of each dispatch class type. This indicates that all operational and mandatory
/// dispatches can use the full capacity of any resource, while user-triggered ones can consume
/// a portion.
fn get_dispatch_limit_ratio(class: DispatchClass) -> Perbill {
match class {
DispatchClass::Operational | DispatchClass::Mandatory
=> <Perbill as sp_runtime::PerThing>::one(),
DispatchClass::Normal => T::AvailableBlockRatio::get(),
}
}
/// Checks if the current extrinsic does not exceed `MaximumExtrinsicWeight` limit.
/// Checks if the current extrinsic does not exceed the maximum weight a single extrinsic
/// with given `DispatchClass` can have.
fn check_extrinsic_weight(
info: &DispatchInfoOf<T::Call>,
) -> Result<(), TransactionValidityError> {
match info.class {
// Mandatory transactions are included in a block unconditionally, so
// we don't verify weight.
DispatchClass::Mandatory => Ok(()),
// Normal transactions must not exceed `MaximumExtrinsicWeight`.
DispatchClass::Normal => {
let maximum_weight = T::MaximumExtrinsicWeight::get();
let extrinsic_weight = info.weight.saturating_add(T::ExtrinsicBaseWeight::get());
if extrinsic_weight > maximum_weight {
Err(InvalidTransaction::ExhaustsResources.into())
} else {
Ok(())
}
},
// For operational transactions we make sure it doesn't exceed
// the space alloted for `Operational` class.
DispatchClass::Operational => {
let maximum_weight = T::MaximumBlockWeight::get();
let operational_limit =
Self::get_dispatch_limit_ratio(DispatchClass::Operational) * maximum_weight;
let operational_limit =
operational_limit.saturating_sub(T::BlockExecutionWeight::get());
let extrinsic_weight = info.weight.saturating_add(T::ExtrinsicBaseWeight::get());
if extrinsic_weight > operational_limit {
Err(InvalidTransaction::ExhaustsResources.into())
} else {
Ok(())
}
let max = T::BlockWeights::get().get(info.class).max_extrinsic;
match max {
Some(max) if info.weight > max => {
Err(InvalidTransaction::ExhaustsResources.into())
},
_ => Ok(()),
}
}
@@ -90,51 +57,10 @@ impl<T: Config + Send + Sync> CheckWeight<T> where
/// Upon successes, it returns the new block weight as a `Result`.
fn check_block_weight(
info: &DispatchInfoOf<T::Call>,
) -> Result<crate::weight::ExtrinsicsWeight, TransactionValidityError> {
let maximum_weight = T::MaximumBlockWeight::get();
let mut all_weight = Module::<T>::block_weight();
match info.class {
// If we have a dispatch that must be included in the block, it ignores all the limits.
DispatchClass::Mandatory => {
let extrinsic_weight = info.weight.saturating_add(T::ExtrinsicBaseWeight::get());
all_weight.add(extrinsic_weight, DispatchClass::Mandatory);
Ok(all_weight)
},
// If we have a normal dispatch, we follow all the normal rules and limits.
DispatchClass::Normal => {
let normal_limit = Self::get_dispatch_limit_ratio(DispatchClass::Normal) * maximum_weight;
let extrinsic_weight = info.weight.checked_add(T::ExtrinsicBaseWeight::get())
.ok_or(InvalidTransaction::ExhaustsResources)?;
all_weight.checked_add(extrinsic_weight, DispatchClass::Normal)
.map_err(|_| InvalidTransaction::ExhaustsResources)?;
if all_weight.get(DispatchClass::Normal) > normal_limit {
Err(InvalidTransaction::ExhaustsResources.into())
} else {
Ok(all_weight)
}
},
// If we have an operational dispatch, allow it if we have not used our full
// "operational space" (independent of existing fullness).
DispatchClass::Operational => {
let operational_limit = Self::get_dispatch_limit_ratio(DispatchClass::Operational) * maximum_weight;
let normal_limit = Self::get_dispatch_limit_ratio(DispatchClass::Normal) * maximum_weight;
let operational_space = operational_limit.saturating_sub(normal_limit);
let extrinsic_weight = info.weight.checked_add(T::ExtrinsicBaseWeight::get())
.ok_or(InvalidTransaction::ExhaustsResources)?;
all_weight.checked_add(extrinsic_weight, DispatchClass::Operational)
.map_err(|_| InvalidTransaction::ExhaustsResources)?;
// If it would fit in normally, its okay
if all_weight.total() <= maximum_weight ||
// If we have not used our operational space
all_weight.get(DispatchClass::Operational) <= operational_space {
Ok(all_weight)
} else {
Err(InvalidTransaction::ExhaustsResources.into())
}
}
}
) -> Result<crate::ConsumedWeight, TransactionValidityError> {
let maximum_weight = T::BlockWeights::get();
let all_weight = Module::<T>::block_weight();
calculate_consumed_weight::<T::Call>(maximum_weight, all_weight, info)
}
/// Checks if the current extrinsic can fit into the block with respect to block length limits.
@@ -144,19 +70,18 @@ impl<T: Config + Send + Sync> CheckWeight<T> where
info: &DispatchInfoOf<T::Call>,
len: usize,
) -> Result<u32, TransactionValidityError> {
let length_limit = T::BlockLength::get();
let current_len = Module::<T>::all_extrinsics_len();
let maximum_len = T::MaximumBlockLength::get();
let limit = Self::get_dispatch_limit_ratio(info.class) * maximum_len;
let added_len = len as u32;
let next_len = current_len.saturating_add(added_len);
if next_len > limit {
if next_len > *length_limit.max.get(info.class) {
Err(InvalidTransaction::ExhaustsResources.into())
} else {
Ok(next_len)
}
}
/// get the priority of an extrinsic denoted by `info`.
/// Get the priority of an extrinsic denoted by `info`.
///
/// Operational transaction will be given a fixed initial amount to be fairly distinguished from
/// the normal ones.
@@ -213,6 +138,53 @@ impl<T: Config + Send + Sync> CheckWeight<T> where
}
}
pub fn calculate_consumed_weight<Call>(
maximum_weight: BlockWeights,
mut all_weight: crate::ConsumedWeight,
info: &DispatchInfoOf<Call>,
) -> Result<crate::ConsumedWeight, TransactionValidityError> where
Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>,
{
let extrinsic_weight = info.weight.saturating_add(maximum_weight.get(info.class).base_extrinsic);
let limit_per_class = maximum_weight.get(info.class);
// add the weight. If class is unlimited, use saturating add instead of checked one.
if limit_per_class.max_total.is_none() && limit_per_class.reserved.is_none() {
all_weight.add(extrinsic_weight, info.class)
} else {
all_weight.checked_add(extrinsic_weight, info.class)
.map_err(|_| InvalidTransaction::ExhaustsResources)?;
}
let per_class = *all_weight.get(info.class);
// Check if we don't exceed per-class allowance
match limit_per_class.max_total {
Some(max) if per_class > max => {
return Err(InvalidTransaction::ExhaustsResources.into());
},
// There is no `max_total` limit (`None`),
// or we are below the limit.
_ => {},
}
// In cases total block weight is exceeded, we need to fall back
// to `reserved` pool if there is any.
if all_weight.total() > maximum_weight.max_block {
match limit_per_class.reserved {
// We are over the limit in reserved pool.
Some(reserved) if per_class > reserved => {
return Err(InvalidTransaction::ExhaustsResources.into());
}
// There is either no limit in reserved pool (`None`),
// or we are below the limit.
_ => {},
}
}
Ok(all_weight)
}
impl<T: Config + Send + Sync> SignedExtension for CheckWeight<T> where
T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>
{
@@ -277,7 +249,7 @@ impl<T: Config + Send + Sync> SignedExtension for CheckWeight<T> where
// to them actually being useful. Block producers are thus not allowed to include mandatory
// extrinsics that result in error.
if let (DispatchClass::Mandatory, Err(e)) = (info.class, result) {
"Bad mandantory".print();
"Bad mandatory".print();
e.print();
Err(InvalidTransaction::BadMandatory)?
@@ -315,12 +287,21 @@ mod tests {
use frame_support::{assert_ok, assert_noop};
use frame_support::weights::{Weight, Pays};
fn block_weights() -> crate::limits::BlockWeights {
<Test as crate::Config>::BlockWeights::get()
}
fn normal_weight_limit() -> Weight {
<Test as Config>::AvailableBlockRatio::get() * <Test as Config>::MaximumBlockWeight::get()
block_weights().get(DispatchClass::Normal).max_total
.unwrap_or_else(|| block_weights().max_block)
}
fn block_weight_limit() -> Weight {
block_weights().max_block
}
fn normal_length_limit() -> u32 {
<Test as Config>::AvailableBlockRatio::get() * <Test as Config>::MaximumBlockLength::get()
*<Test as Config>::BlockLength::get().max.get(DispatchClass::Normal)
}
#[test]
@@ -341,7 +322,7 @@ mod tests {
check(|max, len| {
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(max, len));
assert_eq!(System::block_weight().total(), Weight::max_value());
assert!(System::block_weight().total() > <Test as Config>::MaximumBlockWeight::get());
assert!(System::block_weight().total() > block_weight_limit());
});
check(|max, len| {
assert_ok!(CheckWeight::<Test>::do_validate(max, len));
@@ -352,7 +333,7 @@ mod tests {
fn normal_extrinsic_limited_by_maximum_extrinsic_weight() {
new_test_ext().execute_with(|| {
let max = DispatchInfo {
weight: <Test as Config>::MaximumExtrinsicWeight::get() + 1,
weight: block_weights().get(DispatchClass::Normal).max_extrinsic.unwrap() + 1,
class: DispatchClass::Normal,
..Default::default()
};
@@ -368,13 +349,12 @@ mod tests {
#[test]
fn operational_extrinsic_limited_by_operational_space_limit() {
new_test_ext().execute_with(|| {
let operational_limit = CheckWeight::<Test>::get_dispatch_limit_ratio(
DispatchClass::Operational
) * <Test as Config>::MaximumBlockWeight::get();
let base_weight = <Test as Config>::ExtrinsicBaseWeight::get();
let block_base = <Test as Config>::BlockExecutionWeight::get();
let weights = block_weights();
let operational_limit = weights.get(DispatchClass::Operational).max_total
.unwrap_or_else(|| weights.max_block);
let base_weight = weights.get(DispatchClass::Normal).base_extrinsic;
let weight = operational_limit - base_weight - block_base;
let weight = operational_limit - base_weight;
let okay = DispatchInfo {
weight,
class: DispatchClass::Operational,
@@ -406,7 +386,7 @@ mod tests {
new_test_ext().execute_with(|| {
System::register_extra_weight_unchecked(Weight::max_value(), DispatchClass::Normal);
assert_eq!(System::block_weight().total(), Weight::max_value());
assert!(System::block_weight().total() > <Test as Config>::MaximumBlockWeight::get());
assert!(System::block_weight().total() > block_weight_limit());
});
}
@@ -426,8 +406,8 @@ mod tests {
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(System::block_weight().total(), 768);
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&rest_operational, len));
assert_eq!(<Test as Config>::MaximumBlockWeight::get(), 1024);
assert_eq!(System::block_weight().total(), <Test as Config>::MaximumBlockWeight::get());
assert_eq!(block_weight_limit(), 1024);
assert_eq!(System::block_weight().total(), block_weight_limit());
// Checking single extrinsic should not take current block weight into account.
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&rest_operational), Ok(()));
});
@@ -446,8 +426,8 @@ mod tests {
// Extra 15 here from block execution + base extrinsic weight
assert_eq!(System::block_weight().total(), 266);
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(<Test as Config>::MaximumBlockWeight::get(), 1024);
assert_eq!(System::block_weight().total(), <Test as Config>::MaximumBlockWeight::get());
assert_eq!(block_weight_limit(), 1024);
assert_eq!(System::block_weight().total(), block_weight_limit());
});
}
@@ -486,7 +466,7 @@ mod tests {
// given almost full block
BlockWeight::mutate(|current_weight| {
current_weight.put(normal_limit, DispatchClass::Normal)
current_weight.set(normal_limit, DispatchClass::Normal)
});
// will not fit.
assert!(CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &normal, len).is_err());
@@ -552,19 +532,20 @@ mod tests {
new_test_ext().execute_with(|| {
let normal_limit = normal_weight_limit();
let small = DispatchInfo { weight: 100, ..Default::default() };
let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic;
let medium = DispatchInfo {
weight: normal_limit - <Test as Config>::ExtrinsicBaseWeight::get(),
weight: normal_limit - base_extrinsic,
..Default::default()
};
let big = DispatchInfo {
weight: normal_limit - <Test as Config>::ExtrinsicBaseWeight::get() + 1,
weight: normal_limit - base_extrinsic + 1,
..Default::default()
};
let len = 0_usize;
let reset_check_weight = |i, f, s| {
BlockWeight::mutate(|current_weight| {
current_weight.put(s, DispatchClass::Normal)
current_weight.set(s, DispatchClass::Normal)
});
let r = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, i, len);
if f { assert!(r.is_err()) } else { assert!(r.is_ok()) }
@@ -586,10 +567,12 @@ mod tests {
pays_fee: Default::default(),
};
let len = 0_usize;
let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic;
// We allow 75% for normal transaction, so we put 25% - extrinsic base weight
BlockWeight::mutate(|current_weight| {
current_weight.put(256 - <Test as Config>::ExtrinsicBaseWeight::get(), DispatchClass::Normal)
current_weight.set(0, DispatchClass::Mandatory);
current_weight.set(256 - base_extrinsic, DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
@@ -617,13 +600,14 @@ mod tests {
let len = 0_usize;
BlockWeight::mutate(|current_weight| {
current_weight.put(128, DispatchClass::Normal)
current_weight.set(0, DispatchClass::Mandatory);
current_weight.set(128, DispatchClass::Normal);
});
let pre = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &info, len).unwrap();
assert_eq!(
BlockWeight::get().total(),
info.weight + 128 + <Test as Config>::ExtrinsicBaseWeight::get(),
info.weight + 128 + block_weights().get(DispatchClass::Normal).base_extrinsic,
);
assert!(
@@ -632,7 +616,7 @@ mod tests {
);
assert_eq!(
BlockWeight::get().total(),
info.weight + 128 + <Test as Config>::ExtrinsicBaseWeight::get(),
info.weight + 128 + block_weights().get(DispatchClass::Normal).base_extrinsic,
);
})
}
@@ -640,17 +624,81 @@ mod tests {
#[test]
fn zero_weight_extrinsic_still_has_base_weight() {
new_test_ext().execute_with(|| {
let weights = block_weights();
let free = DispatchInfo { weight: 0, ..Default::default() };
let len = 0_usize;
// Initial weight from `BlockExecutionWeight`
assert_eq!(System::block_weight().total(), <Test as Config>::BlockExecutionWeight::get());
// Initial weight from `weights.base_block`
assert_eq!(
System::block_weight().total(),
weights.base_block
);
let r = CheckWeight::<Test>(PhantomData).pre_dispatch(&1, CALL, &free, len);
assert!(r.is_ok());
assert_eq!(
System::block_weight().total(),
<Test as Config>::ExtrinsicBaseWeight::get() + <Test as Config>::BlockExecutionWeight::get()
weights.get(DispatchClass::Normal).base_extrinsic + weights.base_block
);
})
}
#[test]
fn normal_and_mandatory_tracked_separately() {
new_test_ext().execute_with(|| {
// Max block is 1024
// Max normal is 768 (75%)
// Max mandatory is unlimited
let max_normal = DispatchInfo { weight: 753, ..Default::default() };
let mandatory = DispatchInfo { weight: 1019, class: DispatchClass::Mandatory, ..Default::default() };
let len = 0_usize;
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
assert_eq!(System::block_weight().total(), 768);
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&mandatory, len));
assert_eq!(block_weight_limit(), 1024);
assert_eq!(System::block_weight().total(), 1024 + 768);
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&mandatory), Ok(()));
});
}
#[test]
fn no_max_total_should_still_be_limited_by_max_block() {
// given
let maximum_weight = BlockWeights::builder()
.base_block(0)
.for_class(DispatchClass::non_mandatory(), |w| {
w.base_extrinsic = 0;
w.max_total = Some(20);
})
.for_class(DispatchClass::Mandatory, |w| {
w.base_extrinsic = 0;
w.reserved = Some(5);
w.max_total = None;
})
.build_or_panic();
let all_weight = crate::ConsumedWeight::new(|class| match class {
DispatchClass::Normal => 10,
DispatchClass::Operational => 10,
DispatchClass::Mandatory => 0,
});
assert_eq!(maximum_weight.max_block, all_weight.total());
// fits into reserved
let mandatory1 = DispatchInfo { weight: 5, class: DispatchClass::Mandatory, ..Default::default() };
// does not fit into reserved and the block is full.
let mandatory2 = DispatchInfo { weight: 6, class: DispatchClass::Mandatory, ..Default::default() };
// when
let result1 = calculate_consumed_weight::<<Test as Config>::Call>(
maximum_weight.clone(), all_weight.clone(), &mandatory1
);
let result2 = calculate_consumed_weight::<<Test as Config>::Call>(
maximum_weight, all_weight, &mandatory2
);
// then
assert!(result2.is_err());
assert!(result1.is_ok());
}
}
+27 -43
View File
@@ -122,7 +122,7 @@ use frame_support::{
},
weights::{
Weight, RuntimeDbWeight, DispatchInfo, DispatchClass,
extract_actual_weight,
extract_actual_weight, PerDispatchClass,
},
dispatch::DispatchResultWithPostInfo,
};
@@ -132,15 +132,16 @@ use codec::{Encode, Decode, FullCodec, EncodeLike};
use sp_io::TestExternalities;
pub mod offchain;
pub mod limits;
#[cfg(test)]
pub(crate) mod mock;
mod extensions;
mod weight;
pub mod weights;
#[cfg(test)]
mod tests;
pub use extensions::{
check_mortality::CheckMortality, check_genesis::CheckGenesis, check_nonce::CheckNonce,
check_spec_version::CheckSpecVersion, check_tx_version::CheckTxVersion,
@@ -160,11 +161,20 @@ pub fn extrinsics_data_root<H: Hash>(xts: Vec<Vec<u8>>) -> H::Output {
H::ordered_trie_root(xts)
}
/// An object to track the currently used extrinsic weight in a block.
pub type ConsumedWeight = PerDispatchClass<Weight>;
pub trait Config: 'static + Eq + Clone {
/// The basic call filter to use in Origin. All origins are built with this filter as base,
/// except Root.
type BaseCallFilter: Filter<Self::Call>;
/// Block & extrinsics weights: base values and limits.
type BlockWeights: Get<limits::BlockWeights>;
/// The maximum length of a block (in bytes).
type BlockLength: Get<limits::BlockLength>;
/// The `Origin` type used by dispatchable calls.
type Origin:
Into<Result<RawOrigin<Self::AccountId>, Self::Origin>>
@@ -219,31 +229,9 @@ pub trait Config: 'static + Eq + Clone {
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount: Get<Self::BlockNumber>;
/// The maximum weight of a block.
type MaximumBlockWeight: Get<Weight>;
/// The weight of runtime database operations the runtime can invoke.
type DbWeight: Get<RuntimeDbWeight>;
/// The base weight of executing a block, independent of the transactions in the block.
type BlockExecutionWeight: Get<Weight>;
/// The base weight of an Extrinsic in the block, independent of the of extrinsic being executed.
type ExtrinsicBaseWeight: Get<Weight>;
/// The maximal weight of a single Extrinsic. This should be set to at most
/// `MaximumBlockWeight - AverageOnInitializeWeight`. The limit only applies to extrinsics
/// containing `Normal` dispatch class calls.
type MaximumExtrinsicWeight: Get<Weight>;
/// The maximum length of a block (in bytes).
type MaximumBlockLength: Get<u32>;
/// The portion of the block that is available to normal transaction. The rest can only be used
/// by operational transactions. This can be applied to any resource limit managed by the system
/// module, including weight and length.
type AvailableBlockRatio: Get<Perbill>;
/// Get the chain's current version.
type Version: Get<RuntimeVersion>;
@@ -399,7 +387,7 @@ decl_storage! {
ExtrinsicCount: Option<u32>;
/// The current weight for the block.
BlockWeight get(fn block_weight): weight::ExtrinsicsWeight;
BlockWeight get(fn block_weight): ConsumedWeight;
/// Total length (in bytes) for all extrinsics put together, for the current block.
AllExtrinsicsLen: Option<u32>;
@@ -519,20 +507,11 @@ decl_module! {
/// The maximum number of blocks to allow in mortal eras.
const BlockHashCount: T::BlockNumber = T::BlockHashCount::get();
/// The maximum weight of a block.
const MaximumBlockWeight: Weight = T::MaximumBlockWeight::get();
/// The weight of runtime database operations the runtime can invoke.
const DbWeight: RuntimeDbWeight = T::DbWeight::get();
/// The base weight of executing a block, independent of the transactions in the block.
const BlockExecutionWeight: Weight = T::BlockExecutionWeight::get();
/// The base weight of an Extrinsic in the block, independent of the of extrinsic being executed.
const ExtrinsicBaseWeight: Weight = T::ExtrinsicBaseWeight::get();
/// The maximum length of a block (in bytes).
const MaximumBlockLength: u32 = T::MaximumBlockLength::get();
/// The weight configuration (limits & base values) for each class of extrinsics and block.
const BlockWeights: limits::BlockWeights = T::BlockWeights::get();
fn on_runtime_upgrade() -> frame_support::weights::Weight {
if !UpgradedToU32RefCount::get() {
@@ -540,16 +519,22 @@ decl_module! {
Some(AccountInfo { nonce, refcount: rc as RefCount, data })
);
UpgradedToU32RefCount::put(true);
T::MaximumBlockWeight::get()
T::BlockWeights::get().max_block
} else {
0
}
}
fn integrity_test() {
T::BlockWeights::get()
.validate()
.expect("The weights are invalid.");
}
/// A dispatch that will fill the block weight up to the given ratio.
// TODO: This should only be available for testing, rather than in general usage, but
// that's not possible at present (since it's within the decl_module macro).
#[weight = *_ratio * T::MaximumBlockWeight::get()]
#[weight = *_ratio * T::BlockWeights::get().max_block]
fn fill_block(origin, _ratio: Perbill) {
ensure_root(origin)?;
}
@@ -590,7 +575,7 @@ decl_module! {
/// The weight of this function is dependent on the runtime, but generally this is very expensive.
/// We will treat this as a full block.
/// # </weight>
#[weight = (T::MaximumBlockWeight::get(), DispatchClass::Operational)]
#[weight = (T::BlockWeights::get().max_block, DispatchClass::Operational)]
pub fn set_code(origin, code: Vec<u8>) {
ensure_root(origin)?;
Self::can_set_code(&code)?;
@@ -607,7 +592,7 @@ decl_module! {
/// - 1 event.
/// The weight of this function is dependent on the runtime. We will treat this as a full block.
/// # </weight>
#[weight = (T::MaximumBlockWeight::get(), DispatchClass::Operational)]
#[weight = (T::BlockWeights::get().max_block, DispatchClass::Operational)]
pub fn set_code_without_checks(origin, code: Vec<u8>) {
ensure_root(origin)?;
storage::unhashed::put_raw(well_known_keys::CODE, &code);
@@ -1120,9 +1105,9 @@ impl<T: Config> Module<T> {
/// Set the current block weight. This should only be used in some integration tests.
#[cfg(any(feature = "std", test))]
pub fn set_block_limits(weight: Weight, len: usize) {
pub fn set_block_consumed_resources(weight: Weight, len: usize) {
BlockWeight::mutate(|current_weight| {
current_weight.put(weight, DispatchClass::Normal)
current_weight.set(weight, DispatchClass::Normal)
});
AllExtrinsicsLen::put(len as u32);
}
@@ -1348,7 +1333,6 @@ pub fn split_inner<T, R, S>(option: Option<T>, splitter: impl FnOnce(T) -> (R, S
}
}
impl<T: Config> IsDeadAccount<T::AccountId> for Module<T> {
fn is_dead_account(who: &T::AccountId) -> bool {
!Account::<T>::contains_key(who)
+434
View File
@@ -0,0 +1,434 @@
// This file is part of Substrate.
// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Block resource limits configuration structures.
//!
//! FRAME defines two resources that are limited within a block:
//! - Weight (execution cost/time)
//! - Length (block size)
//!
//! `frame_system` tracks consumption of each of these resources separately for each
//! `DispatchClass`. This module contains configuration object for both resources,
//! which should be passed to `frame_system` configuration when runtime is being set up.
use frame_support::weights::{Weight, DispatchClass, constants, PerDispatchClass, OneOrMany};
use sp_runtime::{RuntimeDebug, Perbill};
/// Block length limit configuration.
#[derive(RuntimeDebug, Clone)]
pub struct BlockLength {
/// Maximal total length in bytes for each extrinsic class.
///
/// In the worst case, the total block length is going to be:
/// `MAX(max)`
pub max: PerDispatchClass<u32>,
}
impl Default for BlockLength {
fn default() -> Self {
BlockLength::max_with_normal_ratio(
5 * 1024 * 1024,
DEFAULT_NORMAL_RATIO,
)
}
}
impl BlockLength {
/// Create new `BlockLength` with `max` for every class.
pub fn max(max: u32) -> Self {
Self {
max: PerDispatchClass::new(|_| max),
}
}
/// Create new `BlockLength` with `max` for `Operational` & `Mandatory`
/// and `normal * max` for `Normal`.
pub fn max_with_normal_ratio(max: u32, normal: Perbill) -> Self {
Self {
max: PerDispatchClass::new(|class| if class == DispatchClass::Normal {
normal * max
} else {
max
}),
}
}
}
#[derive(Default, RuntimeDebug)]
pub struct ValidationErrors {
pub has_errors: bool,
#[cfg(feature = "std")]
pub errors: Vec<String>,
}
macro_rules! error_assert {
($cond : expr, $err : expr, $format : expr $(, $params: expr )*$(,)*) => {
if !$cond {
$err.has_errors = true;
#[cfg(feature = "std")]
{ $err.errors.push(format!($format $(, &$params )*)); }
}
}
}
/// A result of validating `BlockWeights` correctness.
pub type ValidationResult = Result<BlockWeights, ValidationErrors>;
/// A ratio of `Normal` dispatch class within block, used as default value for
/// `BlockWeight` and `BlockLength`. The `Default` impls are provided mostly for convenience
/// to use in tests.
const DEFAULT_NORMAL_RATIO: Perbill = Perbill::from_percent(75);
/// `DispatchClass`-specific weight configuration.
#[derive(RuntimeDebug, Clone, codec::Encode, codec::Decode)]
pub struct WeightsPerClass {
/// Base weight of single extrinsic of given class.
pub base_extrinsic: Weight,
/// Maximal weight of single extrinsic. Should NOT include `base_extrinsic` cost.
///
/// `None` indicates that this class of extrinsics doesn't have a limit.
pub max_extrinsic: Option<Weight>,
/// Block maximal total weight for all extrinsics of given class.
///
/// `None` indicates that weight sum of this class of extrinsics is not
/// restricted. Use this value carefully, since it might produce heavily oversized
/// blocks.
///
/// In the worst case, the total weight consumed by the class is going to be:
/// `MAX(max_total) + MAX(reserved)`.
pub max_total: Option<Weight>,
/// Block reserved allowance for all extrinsics of a particular class.
///
/// Setting to `None` indicates that extrinsics of that class are allowed
/// to go over total block weight (but at most `max_total` for that class).
/// Setting to `Some(x)` guarantees that at least `x` weight of particular class
/// is processed in every block.
pub reserved: Option<Weight>,
}
/// Block weight limits & base values configuration.
///
/// This object is responsible for defining weight limits and base weight values tracked
/// during extrinsic execution.
///
/// Each block starts with `base_block` weight being consumed right away. Next up the
/// `on_initialize` pallet callbacks are invoked and their cost is added before any extrinsic
/// is executed. This cost is tracked as `Mandatory` dispatch class.
///
/// | | `max_block` | |
/// | | | |
/// | | | |
/// | | | |
/// | | | #| `on_initialize`
/// | #| `base_block` | #|
/// |NOM| |NOM|
/// ||\_ Mandatory
/// |\__ Operational
/// \___ Normal
///
/// The remaining capacity can be used to dispatch extrinsics. Note that each dispatch class
/// is being tracked separately, but the sum can't exceed `max_block` (except for `reserved`).
/// Below you can see a picture representing full block with 3 extrinsics (two `Operational` and
/// one `Normal`). Each class has it's own limit `max_total`, but also the sum cannot exceed
/// `max_block` value.
/// -- `Mandatory` limit (unlimited)
/// | # | | |
/// | # | `Ext3` | - - `Operational` limit
/// |# | `Ext2` |- - `Normal` limit
/// | # | `Ext1` | # |
/// | #| `on_initialize` | ##|
/// | #| `base_block` |###|
/// |NOM| |NOM|
///
/// It should be obvious now that it's possible for one class to reach it's limit (say `Normal`),
/// while the block has still capacity to process more transactions (`max_block` not reached,
/// `Operational` transactions can still go in). Setting `max_total` to `None` disables the
/// per-class limit. This is generally highly recommended for `Mandatory` dispatch class, while it
/// can be dangerous for `Normal` class and should only be done with extra care and consideration.
///
/// Often it's desirable for some class of transactions to be added to the block despite it being
/// full. For instance one might want to prevent high-priority `Normal` transactions from pushing
/// out lower-priority `Operational` transactions. In such cases you might add a `reserved` capacity
/// for given class.
/// _
/// # \
/// # `Ext8` - `reserved`
/// # _/
/// | # | `Ext7 | - - `Operational` limit
/// |# | `Ext6` | |
/// |# | `Ext5` |-# - `Normal` limit
/// |# | `Ext4` |## |
/// | #| `on_initialize` |###|
/// | #| `base_block` |###|
/// |NOM| |NOM|
///
/// In the above example, `Ext4-6` fill up the block almost up to `max_block`. `Ext7` would not fit
/// if there wasn't the extra `reserved` space for `Operational` transactions. Note that `max_total`
/// limit applies to `reserved` space as well (i.e. the sum of weights of `Ext7` & `Ext8` mustn't
/// exceed it). Setting `reserved` to `None` allows the extrinsics to always get into the block up
/// to their `max_total` limit. If `max_total` is set to `None` as well, all extrinsics witch
/// dispatchables of given class will always end up in the block (recommended for `Mandatory`
/// dispatch class).
///
/// As a consequence of `reserved` space, total consumed block weight might exceed `max_block`
/// value, so this parameter should rather be thought of as "target block weight" than a hard limit.
#[derive(RuntimeDebug, Clone, codec::Encode, codec::Decode)]
pub struct BlockWeights {
/// Base weight of block execution.
pub base_block: Weight,
/// Maximal total weight consumed by all kinds of extrinsics (without `reserved` space).
pub max_block: Weight,
/// Weight limits for extrinsics of given dispatch class.
pub per_class: PerDispatchClass<WeightsPerClass>,
}
impl Default for BlockWeights {
fn default() -> Self {
Self::with_sensible_defaults(
1 * constants::WEIGHT_PER_SECOND,
DEFAULT_NORMAL_RATIO,
)
}
}
impl BlockWeights {
/// Get per-class weight settings.
pub fn get(&self, class: DispatchClass) -> &WeightsPerClass {
self.per_class.get(class)
}
/// Verifies correctness of this `BlockWeights` object.
pub fn validate(self) -> ValidationResult {
fn or_max(w: Option<Weight>) -> Weight {
w.unwrap_or_else(|| Weight::max_value())
}
let mut error = ValidationErrors::default();
for class in DispatchClass::all() {
let weights = self.per_class.get(*class);
let max_for_class = or_max(weights.max_total);
let base_for_class = weights.base_extrinsic;
let reserved = or_max(weights.reserved);
// Make sure that if total is set it's greater than base_block &&
// base_for_class
error_assert!(
(max_for_class > self.base_block && max_for_class > base_for_class)
|| max_for_class == 0,
&mut error,
"[{:?}] {:?} (total) has to be greater than {:?} (base block) & {:?} (base extrinsic)",
class, max_for_class, self.base_block, base_for_class,
);
// Max extrinsic can't be greater than max_for_class.
error_assert!(
weights.max_extrinsic.unwrap_or(0) <= max_for_class.saturating_sub(base_for_class),
&mut error,
"[{:?}] {:?} (max_extrinsic) can't be greater than {:?} (max for class)",
class, weights.max_extrinsic,
max_for_class.saturating_sub(base_for_class),
);
// Max extrinsic should not be 0
error_assert!(
weights.max_extrinsic.unwrap_or_else(|| Weight::max_value()) > 0,
&mut error,
"[{:?}] {:?} (max_extrinsic) must not be 0. Check base cost and average initialization cost.",
class, weights.max_extrinsic,
);
// Make sure that if reserved is set it's greater than base_for_class.
error_assert!(
reserved > base_for_class || reserved == 0,
&mut error,
"[{:?}] {:?} (reserved) has to be greater than {:?} (base extrinsic) if set",
class, reserved, base_for_class,
);
// Make sure max block is greater than max_total if it's set.
error_assert!(
self.max_block >= weights.max_total.unwrap_or(0),
&mut error,
"[{:?}] {:?} (max block) has to be greater than {:?} (max for class)",
class, self.max_block, weights.max_total,
);
// Make sure we can fit at least one extrinsic.
error_assert!(
self.max_block > base_for_class + self.base_block,
&mut error,
"[{:?}] {:?} (max block) must fit at least one extrinsic {:?} (base weight)",
class, self.max_block, base_for_class + self.base_block,
);
}
if error.has_errors {
Err(error)
} else {
Ok(self)
}
}
/// Create new weights definition, with both `Normal` and `Operational`
/// classes limited to given weight.
///
/// Note there is no reservation for `Operational` class, so this constructor
/// is not suitable for production deployments.
pub fn simple_max(block_weight: Weight) -> Self {
Self::builder()
.base_block(0)
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = 0;
})
.for_class(DispatchClass::non_mandatory(), |weights| {
weights.max_total = block_weight.into();
})
.build()
.expect("We only specify max_total and leave base values as defaults; qed")
}
/// Create a sensible default weights system given only expected maximal block weight and the
/// ratio that `Normal` extrinsics should occupy.
///
/// Assumptions:
/// - Average block initialization is assumed to be `10%`.
/// - `Operational` transactions have reserved allowance (`1.0 - normal_ratio`)
pub fn with_sensible_defaults(
expected_block_weight: Weight,
normal_ratio: Perbill,
) -> Self {
let normal_weight = normal_ratio * expected_block_weight;
Self::builder()
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = normal_weight.into();
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = expected_block_weight.into();
weights.reserved = (expected_block_weight - normal_weight).into();
})
.avg_block_initialization(Perbill::from_percent(10))
.build()
.expect("Sensible defaults are tested to be valid; qed")
}
/// Start constructing new `BlockWeights` object.
///
/// By default all kinds except of `Mandatory` extrinsics are disallowed.
pub fn builder() -> BlockWeightsBuilder {
BlockWeightsBuilder {
weights: BlockWeights {
base_block: constants::BlockExecutionWeight::get(),
max_block: 0,
per_class: PerDispatchClass::new(|class| {
let initial = if class == DispatchClass::Mandatory { None } else { Some(0) };
WeightsPerClass {
base_extrinsic: constants::ExtrinsicBaseWeight::get(),
max_extrinsic: None,
max_total: initial,
reserved: initial,
}
}),
},
init_cost: None,
}
}
}
/// An opinionated builder for `Weights` object.
pub struct BlockWeightsBuilder {
weights: BlockWeights,
init_cost: Option<Perbill>,
}
impl BlockWeightsBuilder {
/// Set base block weight.
pub fn base_block(mut self, base_block: Weight) -> Self {
self.weights.base_block = base_block;
self
}
/// Average block initialization weight cost.
///
/// This value is used to derive maximal allowed extrinsic weight for each
/// class, based on the allowance.
///
/// This is to make sure that extrinsics don't stay forever in the pool,
/// because they could seamingly fit the block (since they are below `max_block`),
/// but the cost of calling `on_initialize` alway prevents them from being included.
pub fn avg_block_initialization(mut self, init_cost: Perbill) -> Self {
self.init_cost = Some(init_cost);
self
}
/// Set parameters for particular class.
///
/// Note: `None` values of `max_extrinsic` will be overwritten in `build` in case
/// `avg_block_initialization` rate is set to a non-zero value.
pub fn for_class(
mut self,
class: impl OneOrMany<DispatchClass>,
action: impl Fn(&mut WeightsPerClass),
) -> Self {
for class in class.into_iter() {
action(self.weights.per_class.get_mut(class));
}
self
}
/// Construct the `BlockWeights` object.
pub fn build(self) -> ValidationResult {
// compute max extrinsic size
let Self { mut weights, init_cost } = self;
// compute max block size.
for class in DispatchClass::all() {
weights.max_block = match weights.per_class.get(*class).max_total {
Some(max) if max > weights.max_block => max,
_ => weights.max_block,
};
}
// compute max size of single extrinsic
if let Some(init_weight) = init_cost.map(|rate| rate * weights.max_block) {
for class in DispatchClass::all() {
let per_class = weights.per_class.get_mut(*class);
if per_class.max_extrinsic.is_none() && init_cost.is_some() {
per_class.max_extrinsic = per_class.max_total
.map(|x| x.saturating_sub(init_weight))
.map(|x| x.saturating_sub(per_class.base_extrinsic));
}
}
}
// Validate the result
weights.validate()
}
/// Construct the `BlockWeights` object or panic if it's invalid.
///
/// This is a convenience method to be called whenever you construct a runtime.
pub fn build_or_panic(self) -> BlockWeights {
self.build().expect(
"Builder finished with `build_or_panic`; The panic is expected if runtime weights are not correct"
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_weights_are_valid() {
BlockWeights::default()
.validate()
.unwrap();
}
}
+24 -13
View File
@@ -34,12 +34,11 @@ impl_outer_origin! {
#[derive(Clone, Eq, PartialEq, Debug, Default)]
pub struct Test;
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
const MAX_BLOCK_WEIGHT: Weight = 1024;
parameter_types! {
pub const BlockHashCount: u64 = 10;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumExtrinsicWeight: Weight = 768;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub const MaximumBlockLength: u32 = 1024;
pub Version: RuntimeVersion = RuntimeVersion {
spec_name: sp_version::create_runtime_str!("test"),
impl_name: sp_version::create_runtime_str!("system-test"),
@@ -49,12 +48,28 @@ parameter_types! {
apis: sp_version::create_apis_vec!([]),
transaction_version: 1,
};
pub const BlockExecutionWeight: Weight = 10;
pub const ExtrinsicBaseWeight: Weight = 5;
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 10,
write: 100,
};
pub RuntimeBlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(10)
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = 5;
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAX_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAX_BLOCK_WEIGHT);
weights.reserved = Some(
MAX_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAX_BLOCK_WEIGHT
);
})
.avg_block_initialization(Perbill::from_percent(0))
.build_or_panic();
pub RuntimeBlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(1024, NORMAL_DISPATCH_RATIO);
}
thread_local!{
@@ -82,6 +97,8 @@ impl Dispatchable for Call {
impl Config for Test {
type BaseCallFilter = ();
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
type Origin = Origin;
type Call = Call;
type Index = u64;
@@ -93,13 +110,7 @@ impl Config for Test {
type Header = Header;
type Event = Event<Self>;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = DbWeight;
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = Version;
type PalletInfo = ();
type AccountData = u32;
@@ -118,7 +129,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
let mut ext: sp_io::TestExternalities = GenesisConfig::default().build_storage::<Test>().unwrap().into();
// Add to each test the initial weight of a block
ext.execute_with(|| System::register_extra_weight_unchecked(
<Test as Config>::BlockExecutionWeight::get(),
<Test as crate::Config>::BlockWeights::get().base_block,
DispatchClass::Mandatory
));
ext
-76
View File
@@ -1,76 +0,0 @@
// This file is part of Substrate.
// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use codec::{Encode, Decode};
use frame_support::weights::{Weight, DispatchClass};
use sp_runtime::RuntimeDebug;
/// An object to track the currently used extrinsic weight in a block.
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
pub struct ExtrinsicsWeight {
normal: Weight,
operational: Weight,
}
impl ExtrinsicsWeight {
/// Returns the total weight consumed by all extrinsics in the block.
pub fn total(&self) -> Weight {
self.normal.saturating_add(self.operational)
}
/// Add some weight of a specific dispatch class, saturating at the numeric bounds of `Weight`.
pub fn add(&mut self, weight: Weight, class: DispatchClass) {
let value = self.get_mut(class);
*value = value.saturating_add(weight);
}
/// Try to add some weight of a specific dispatch class, returning Err(()) if overflow would
/// occur.
pub fn checked_add(&mut self, weight: Weight, class: DispatchClass) -> Result<(), ()> {
let value = self.get_mut(class);
*value = value.checked_add(weight).ok_or(())?;
Ok(())
}
/// Subtract some weight of a specific dispatch class, saturating at the numeric bounds of
/// `Weight`.
pub fn sub(&mut self, weight: Weight, class: DispatchClass) {
let value = self.get_mut(class);
*value = value.saturating_sub(weight);
}
/// Get the current weight of a specific dispatch class.
pub fn get(&self, class: DispatchClass) -> Weight {
match class {
DispatchClass::Operational => self.operational,
DispatchClass::Normal | DispatchClass::Mandatory => self.normal,
}
}
/// Get a mutable reference to the current weight of a specific dispatch class.
fn get_mut(&mut self, class: DispatchClass) -> &mut Weight {
match class {
DispatchClass::Operational => &mut self.operational,
DispatchClass::Normal | DispatchClass::Mandatory => &mut self.normal,
}
}
/// Set the weight of a specific dispatch class.
pub fn put(&mut self, new: Weight, class: DispatchClass) {
*self.get_mut(class) = new;
}
}
+7 -12
View File
@@ -292,10 +292,10 @@ impl<T: Config> UnixTime for Module<T> {
mod tests {
use super::*;
use frame_support::{impl_outer_origin, assert_ok, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, assert_ok, parameter_types};
use sp_io::TestExternalities;
use sp_core::H256;
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
@@ -310,12 +310,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -327,13 +329,6 @@ mod tests {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = ();
+61 -33
View File
@@ -40,7 +40,7 @@ use frame_support::{
traits::Get,
weights::{
Weight, DispatchInfo, PostDispatchInfo, GetDispatchInfo, Pays, WeightToFeePolynomial,
WeightToFeeCoefficient,
WeightToFeeCoefficient, DispatchClass,
},
dispatch::DispatchResult,
};
@@ -158,14 +158,14 @@ impl<T, S, V, M> Convert<Multiplier, Multiplier> for TargetedFeeAdjustment<T, S,
let min_multiplier = M::get();
let previous = previous.max(min_multiplier);
let weights = T::BlockWeights::get();
// the computed ratio is only among the normal class.
let normal_max_weight =
<T as frame_system::Config>::AvailableBlockRatio::get() *
<T as frame_system::Config>::MaximumBlockWeight::get();
let normal_block_weight =
<frame_system::Module<T>>::block_weight()
.get(frame_support::weights::DispatchClass::Normal)
.min(normal_max_weight);
let normal_max_weight = weights.get(DispatchClass::Normal).max_total
.unwrap_or_else(|| weights.max_block);
let current_block_weight = <frame_system::Module<T>>::block_weight();
let normal_block_weight = *current_block_weight
.get(DispatchClass::Normal)
.min(&normal_max_weight);
let s = S::get();
let v = V::get();
@@ -257,13 +257,13 @@ decl_module! {
fn integrity_test() {
// given weight == u64, we build multipliers from `diff` of two weight values, which can
// at most be MaximumBlockWeight. Make sure that this can fit in a multiplier without
// at most be maximum block weight. Make sure that this can fit in a multiplier without
// loss.
use sp_std::convert::TryInto;
assert!(
<Multiplier as sp_runtime::traits::Bounded>::max_value() >=
Multiplier::checked_from_integer(
<T as frame_system::Config>::MaximumBlockWeight::get().try_into().unwrap()
T::BlockWeights::get().max_block.try_into().unwrap()
).unwrap(),
);
@@ -272,9 +272,11 @@ decl_module! {
// that if we collapse to minimum, the trend will be positive with a weight value
// which is 1% more than the target.
let min_value = T::FeeMultiplierUpdate::min();
let mut target =
T::FeeMultiplierUpdate::target() *
(T::AvailableBlockRatio::get() * T::MaximumBlockWeight::get());
let mut target = T::FeeMultiplierUpdate::target() *
T::BlockWeights::get().get(DispatchClass::Normal).max_total.expect(
"Setting `max_total` for `Normal` dispatch class is not compatible with \
`transaction-payment` pallet."
);
// add 1 percent;
let addition = target / 100;
@@ -285,7 +287,7 @@ decl_module! {
target += addition;
sp_io::TestExternalities::new_empty().execute_with(|| {
<frame_system::Module<T>>::set_block_limits(target, 0);
<frame_system::Module<T>>::set_block_consumed_resources(target, 0);
let next = T::FeeMultiplierUpdate::convert(min_value);
assert!(next > min_value, "The minimum bound of the multiplier is too low. When \
block saturation is more than target by 1% and multiplier is minimal then \
@@ -357,7 +359,13 @@ impl<T: Config> Module<T> where
) -> BalanceOf<T> where
T::Call: Dispatchable<Info=DispatchInfo>,
{
Self::compute_fee_raw(len, info.weight, tip, info.pays_fee)
Self::compute_fee_raw(
len,
info.weight,
tip,
info.pays_fee,
info.class,
)
}
/// Compute the actual post dispatch fee for a particular transaction.
@@ -372,7 +380,13 @@ impl<T: Config> Module<T> where
) -> BalanceOf<T> where
T::Call: Dispatchable<Info=DispatchInfo,PostInfo=PostDispatchInfo>,
{
Self::compute_fee_raw(len, post_info.calc_actual_weight(info), tip, post_info.pays_fee(info))
Self::compute_fee_raw(
len,
post_info.calc_actual_weight(info),
tip,
post_info.pays_fee(info),
info.class,
)
}
fn compute_fee_raw(
@@ -380,6 +394,7 @@ impl<T: Config> Module<T> where
weight: Weight,
tip: BalanceOf<T>,
pays_fee: Pays,
class: DispatchClass,
) -> BalanceOf<T> {
if pays_fee == Pays::Yes {
let len = <BalanceOf<T>>::from(len);
@@ -394,7 +409,7 @@ impl<T: Config> Module<T> where
// final adjusted weight fee.
let adjusted_weight_fee = multiplier.saturating_mul_int(unadjusted_weight_fee);
let base_fee = Self::weight_to_fee(T::ExtrinsicBaseWeight::get());
let base_fee = Self::weight_to_fee(T::BlockWeights::get().get(class).base_extrinsic);
base_fee
.saturating_add(fixed_len_fee)
.saturating_add(adjusted_weight_fee)
@@ -407,7 +422,7 @@ impl<T: Config> Module<T> where
fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
// cap the weight to the maximum defined in runtime, otherwise it will be the
// `Bounded` maximum of its data type, which is not desired.
let capped_weight = weight.min(<T as frame_system::Config>::MaximumBlockWeight::get());
let capped_weight = weight.min(T::BlockWeights::get().max_block);
T::WeightToFee::calc(&capped_weight)
}
}
@@ -471,8 +486,9 @@ impl<T: Config + Send + Sync> ChargeTransactionPayment<T> where
/// that the transaction which consumes more resources (either length or weight) with the same
/// `fee` ends up having lower priority.
fn get_priority(len: usize, info: &DispatchInfoOf<T::Call>, final_fee: BalanceOf<T>) -> TransactionPriority {
let weight_saturation = T::MaximumBlockWeight::get() / info.weight.max(1);
let len_saturation = T::MaximumBlockLength::get() as u64 / (len as u64).max(1);
let weight_saturation = T::BlockWeights::get().max_block / info.weight.max(1);
let max_block_length = *T::BlockLength::get().max.get(DispatchClass::Normal);
let len_saturation = max_block_length as u64 / (len as u64).max(1);
let coefficient: BalanceOf<T> = weight_saturation.min(len_saturation).saturated_into::<BalanceOf<T>>();
final_fee.saturating_mul(coefficient).saturated_into::<TransactionPriority>()
}
@@ -571,6 +587,7 @@ mod tests {
traits::{BlakeTwo256, IdentityLookup},
Perbill,
};
use std::cell::RefCell;
use smallvec::smallvec;
const CALL: &<Runtime as frame_system::Config>::Call =
@@ -598,18 +615,36 @@ mod tests {
pub enum Origin for Runtime {}
}
thread_local! {
static EXTRINSIC_BASE_WEIGHT: RefCell<u64> = RefCell::new(0);
}
pub struct BlockWeights;
impl Get<frame_system::limits::BlockWeights> for BlockWeights {
fn get() -> frame_system::limits::BlockWeights {
frame_system::limits::BlockWeights::builder()
.base_block(0)
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = EXTRINSIC_BASE_WEIGHT.with(|v| *v.borrow()).into();
})
.for_class(DispatchClass::non_mandatory(), |weights| {
weights.max_total = 1024.into();
})
.build_or_panic()
}
}
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub static ExtrinsicBaseWeight: u64 = 0;
pub static TransactionByteFee: u64 = 1;
pub static WeightToFee: u64 = 1;
}
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -621,13 +656,6 @@ mod tests {
type Header = Header;
type Event = 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 = pallet_balances::AccountData<u64>;
@@ -841,7 +869,7 @@ mod tests {
// fee will be proportional to what is the actual maximum weight in the runtime.
assert_eq!(
Balances::free_balance(&1),
(10000 - <Runtime as frame_system::Config>::MaximumBlockWeight::get()) as u64
(10000 - <Runtime as frame_system::Config>::BlockWeights::get().max_block) as u64
);
});
}
@@ -939,7 +967,7 @@ mod tests {
partial_fee:
5 * 2 /* base * weight_fee */
+ len as u64 /* len * 1 */
+ info.weight.min(MaximumBlockWeight::get()) as u64 * 2 * 3 / 2 /* weight */
+ info.weight.min(BlockWeights::get().max_block) as u64 * 2 * 3 / 2 /* weight */
},
);
+7 -12
View File
@@ -22,12 +22,12 @@
use super::*;
use std::cell::RefCell;
use frame_support::{
assert_noop, assert_ok, impl_outer_origin, impl_outer_event, parameter_types, weights::Weight,
assert_noop, assert_ok, impl_outer_origin, impl_outer_event, parameter_types,
traits::{Contains, OnInitialize}
};
use sp_core::H256;
use sp_runtime::{
Perbill, ModuleId,
ModuleId,
testing::Header,
traits::{BlakeTwo256, IdentityLookup, BadOrigin},
};
@@ -55,12 +55,14 @@ impl_outer_event! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -72,13 +74,6 @@ impl frame_system::Config for Test {
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = pallet_balances::AccountData<u64>;
+7 -11
View File
@@ -30,7 +30,7 @@ use frame_support::{
storage,
};
use sp_core::H256;
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use crate as utility;
// example module to test behaviors.
@@ -93,12 +93,14 @@ impl_outer_dispatch! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = Weight::max_value();
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::max_value());
}
impl frame_system::Config for Test {
type BaseCallFilter = TestBaseCallFilter;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -110,13 +112,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<u64>;
@@ -350,6 +345,7 @@ fn batch_early_exit_works() {
#[test]
fn batch_weight_calculation_doesnt_overflow() {
use sp_runtime::Perbill;
new_test_ext().execute_with(|| {
let big_call = Call::System(SystemCall::fill_block(Perbill::from_percent(50)));
assert_eq!(big_call.get_dispatch_info().weight, Weight::max_value() / 2);
+6 -12
View File
@@ -391,11 +391,10 @@ mod tests {
use super::*;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight,
assert_ok, assert_noop, impl_outer_origin, parameter_types,
};
use sp_core::H256;
use sp_runtime::{
Perbill,
testing::Header,
traits::{BlakeTwo256, IdentityLookup, Identity, BadOrigin},
};
@@ -409,12 +408,14 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
}
impl frame_system::Config for Test {
type BaseCallFilter = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -426,13 +427,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>;
+11 -11
View File
@@ -42,9 +42,11 @@ use sp_runtime::{
},
traits::{
BlindCheckable, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT,
GetNodeBlockType, GetRuntimeBlockType, NumberFor, Verify, IdentityLookup,
GetNodeBlockType, GetRuntimeBlockType, Verify, IdentityLookup,
},
};
#[cfg(feature = "std")]
use sp_runtime::traits::NumberFor;
use sp_version::RuntimeVersion;
pub use sp_core::hash::H256;
#[cfg(any(feature = "std", test))]
@@ -52,8 +54,9 @@ use sp_version::NativeVersion;
use frame_support::{
impl_outer_origin, parameter_types,
traits::KeyOwnerProofSystem,
weights::{RuntimeDbWeight, Weight},
weights::RuntimeDbWeight,
};
use frame_system::limits::{BlockWeights, BlockLength};
use sp_inherents::{CheckInherentsResult, InherentData};
use cfg_if::cfg_if;
@@ -427,17 +430,20 @@ impl From<frame_system::Event<Runtime>> for Event {
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
pub const MinimumPeriod: u64 = 5;
pub const MaximumBlockWeight: Weight = 4 * 1024 * 1024;
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 100,
write: 1000,
};
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub RuntimeBlockLength: BlockLength =
BlockLength::max(4 * 1024 * 1024);
pub RuntimeBlockWeights: BlockWeights =
BlockWeights::with_sensible_defaults(4 * 1024 * 1024, Perbill::from_percent(75));
}
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type BlockWeights = RuntimeBlockWeights;
type BlockLength = RuntimeBlockLength;
type Origin = Origin;
type Call = Extrinsic;
type Index = u64;
@@ -449,13 +455,7 @@ impl frame_system::Config for Runtime {
type Header = Header;
type Event = 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 = ();