Introduce BlockExecutionWeight and ExtrinsicBaseWeight (#5722)

* Introduce `BlockExectionWeight` and `ExtrinsicBaseWeight`

* Add new traits everywhere

* Missed one update

* fix tests

* Update `check_weight` logic

* introduce `max_extrinsic_weight` function

* fix + add tests

* format nits

* remove println

* make test a bit more clear

* Remove minimum weight

* newlines left over from find/replace

* Fix test, improve clarity

* Fix executor tests

* Extrinsic base weight same as old `MINIMUM_WEIGHT`

* fix example test

* Expose constants

* Add test for full block with operational and normal

* Initiate test environment with `BlockExecutionWeight` weight

* format nit

* Update frame/system/src/lib.rs

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

* Replace `TransactionBaseFee` with `ExtrinsicBaseWeight` (#5761)

* Replace `TransactionBaseFee` with `ExtrinsicBaseFee`

* Fix stuff

* Fix and make tests better

* Forgot to update this test

* Fix priority number in test

* Remove minimum weight from merge

* Fix weight in contracts

* remove `TransactionBaseFee` from contract tests

* Let `register_extra_weight_unchecked` go past `MaximumBlockWeight`

* address feedback

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2020-04-25 07:59:54 +02:00
committed by GitHub
parent 3793fbf9cc
commit 8a33c297b4
74 changed files with 518 additions and 301 deletions
+13 -14
View File
@@ -21,7 +21,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::{decl_module, decl_storage, decl_event, decl_error};
use frame_support::weights::MINIMUM_WEIGHT;
use frame_support::traits::Currency;
use frame_system::{self as system, ensure_signed};
use codec::{Encode, Decode};
@@ -71,7 +70,7 @@ decl_module! {
fn deposit_event() = default;
/// Do nothing.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn do_nothing(_origin, input: u32) {
if input > 0 {
return Ok(());
@@ -83,7 +82,7 @@ decl_module! {
/// storage database, however, the `repeat` calls will all pull from the
/// storage overlay cache. You must consider this when analyzing the
/// results of the benchmark.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn read_value(_origin, repeat: u32) {
for _ in 0..repeat {
MyValue::get();
@@ -91,7 +90,7 @@ decl_module! {
}
/// Put a value into a storage value.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn put_value(_origin, repeat: u32) {
for r in 0..repeat {
MyValue::put(r);
@@ -103,7 +102,7 @@ decl_module! {
/// storage database, however, the `repeat` calls will all pull from the
/// storage overlay cache. You must consider this when analyzing the
/// results of the benchmark.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn exists_value(_origin, repeat: u32) {
for _ in 0..repeat {
MyValue::exists();
@@ -111,7 +110,7 @@ decl_module! {
}
/// Remove a value from storage `repeat` number of times.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn remove_value(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::remove(r);
@@ -119,7 +118,7 @@ decl_module! {
}
/// Read a value from storage map `repeat` number of times.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn read_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::get(r);
@@ -127,7 +126,7 @@ decl_module! {
}
/// Insert a value into a map.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn insert_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::insert(r, r);
@@ -135,7 +134,7 @@ decl_module! {
}
/// Check is a map contains a value `repeat` number of times.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn contains_key_map(_origin, repeat: u32) {
for r in 0..repeat {
MyMap::contains_key(r);
@@ -143,7 +142,7 @@ decl_module! {
}
/// Read a value from storage `repeat` number of times.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn remove_prefix(_origin, repeat: u32) {
for r in 0..repeat {
MyDoubleMap::remove_prefix(r);
@@ -151,21 +150,21 @@ decl_module! {
}
/// Add user to the list.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn add_member_list(origin) {
let who = ensure_signed(origin)?;
MyMemberList::<T>::mutate(|x| x.push(who));
}
/// Append user to the list.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn append_member_list(origin) {
let who = ensure_signed(origin)?;
MyMemberList::<T>::append(&[who])?;
}
/// Encode a vector of accounts to bytes.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn encode_accounts(_origin, accounts: Vec<T::AccountId>) {
let bytes = accounts.encode();
@@ -177,7 +176,7 @@ decl_module! {
}
/// Decode bytes into a vector of accounts.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn decode_accounts(_origin, bytes: Vec<u8>) {
let accounts: Vec<T::AccountId> = Decode::decode(&mut bytes.as_slice()).map_err(|_| "Could not decode")?;