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
+8 -9
View File
@@ -54,7 +54,6 @@
//!
//! ```
//! use frame_support::{decl_module, dispatch};
//! use frame_support::weights::MINIMUM_WEIGHT;
//! use frame_system::{self as system, ensure_signed};
//! use pallet_scored_pool::{self as scored_pool};
//!
@@ -62,7 +61,7 @@
//!
//! decl_module! {
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! #[weight = MINIMUM_WEIGHT]
//! #[weight = 0]
//! pub fn candidate(origin) -> dispatch::DispatchResult {
//! let who = ensure_signed(origin)?;
//!
@@ -98,7 +97,7 @@ use sp_std::{
use frame_support::{
decl_module, decl_storage, decl_event, ensure, decl_error,
traits::{EnsureOrigin, ChangeMembers, InitializeMembers, Currency, Get, ReservableCurrency},
weights::{Weight, MINIMUM_WEIGHT},
weights::Weight,
};
use frame_system::{self as system, ensure_root, ensure_signed};
use sp_runtime::{
@@ -253,7 +252,7 @@ decl_module! {
let pool = <Pool<T, I>>::get();
<Module<T, I>>::refresh_members(pool, ChangeReceiver::MembershipChanged);
}
MINIMUM_WEIGHT
0
}
/// Add `origin` to the pool of candidates.
@@ -267,7 +266,7 @@ decl_module! {
///
/// The `index` parameter of this function must be set to
/// the index of the transactor in the `Pool`.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn submit_candidacy(origin) {
let who = ensure_signed(origin)?;
ensure!(!<CandidateExists<T, I>>::contains_key(&who), Error::<T, I>::AlreadyInPool);
@@ -297,7 +296,7 @@ decl_module! {
///
/// The `index` parameter of this function must be set to
/// the index of the transactor in the `Pool`.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn withdraw_candidacy(
origin,
index: u32
@@ -317,7 +316,7 @@ decl_module! {
///
/// The `index` parameter of this function must be set to
/// the index of `dest` in the `Pool`.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn kick(
origin,
dest: <T::Lookup as StaticLookup>::Source,
@@ -342,7 +341,7 @@ decl_module! {
///
/// The `index` parameter of this function must be set to
/// the index of the `dest` in the `Pool`.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn score(
origin,
dest: <T::Lookup as StaticLookup>::Source,
@@ -383,7 +382,7 @@ decl_module! {
/// (this happens each `Period`).
///
/// May only be called from root.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
pub fn change_member_count(origin, count: u32) {
ensure_root(origin)?;
<MemberCount<I>>::put(&count);
+2
View File
@@ -67,6 +67,8 @@ impl frame_system::Trait for Test {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();