Maximum extrinsic weight limit (#6067)

* Only check single extrinsics weight limit in validate_transaction.

* Add missing parameter to all pallets.

* Add tests, fix default configuration.

* Bump spec version.

* Use AvailableBlockRation to calculate MaxExtrinsicWeight
This commit is contained in:
Tomasz Drwięga
2020-05-20 15:05:16 +02:00
committed by GitHub
parent 9e01d4feaa
commit f74a7171be
50 changed files with 129 additions and 13 deletions
@@ -16,6 +16,7 @@ use sp_runtime::{
};
use sp_runtime::traits::{
BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount, NumberFor,
Saturating,
};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
@@ -127,6 +128,9 @@ parameter_types! {
/// 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 const MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
.saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION;
}
@@ -164,6 +168,10 @@ impl system::Trait for Runtime {
/// 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.