mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
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:
@@ -70,14 +70,13 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_support::weights::MINIMUM_WEIGHT;
|
||||
/// # use frame_system::{self as system, Trait, ensure_signed};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
///
|
||||
/// // Private functions are dispatchable, but not available to other
|
||||
/// // FRAME pallets.
|
||||
/// #[weight = MINIMUM_WEIGHT]
|
||||
/// #[weight = 0]
|
||||
/// fn my_function(origin, var: u64) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
@@ -85,7 +84,7 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
///
|
||||
/// // Public functions are both dispatchable and available to other
|
||||
/// // FRAME pallets.
|
||||
/// #[weight = MINIMUM_WEIGHT]
|
||||
/// #[weight = 0]
|
||||
/// pub fn my_public_function(origin) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
@@ -113,17 +112,16 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_support::weights::MINIMUM_WEIGHT;
|
||||
/// # use frame_system::{self as system, Trait, ensure_signed};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// #[weight = MINIMUM_WEIGHT]
|
||||
/// #[weight = 0]
|
||||
/// fn my_long_function(origin) -> dispatch::DispatchResult {
|
||||
/// // Your implementation
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// #[weight = MINIMUM_WEIGHT]
|
||||
/// #[weight = 0]
|
||||
/// fn my_short_function(origin) {
|
||||
/// // Your implementation
|
||||
/// }
|
||||
@@ -177,11 +175,10 @@ impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::dispatch;
|
||||
/// # use frame_support::weights::MINIMUM_WEIGHT;
|
||||
/// # use frame_system::{self as system, Trait, ensure_signed, ensure_root};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// #[weight = MINIMUM_WEIGHT]
|
||||
/// #[weight = 0]
|
||||
/// fn my_privileged_function(origin) -> dispatch::DispatchResult {
|
||||
/// ensure_root(origin)?;
|
||||
/// // Your implementation
|
||||
@@ -2045,7 +2042,7 @@ macro_rules! __check_reserved_fn_name {
|
||||
#[allow(dead_code)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::weights::{MINIMUM_WEIGHT, DispatchInfo, DispatchClass, Pays};
|
||||
use crate::weights::{DispatchInfo, DispatchClass, Pays};
|
||||
use crate::traits::{
|
||||
CallMetadata, GetCallMetadata, GetCallName, OnInitialize, OnFinalize, OnRuntimeUpgrade
|
||||
};
|
||||
@@ -2071,22 +2068,22 @@ mod tests {
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin, T::AccountId: From<u32> {
|
||||
/// Hi, this is a comment.
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
#[weight = 0]
|
||||
fn aux_0(_origin) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
#[weight = 0]
|
||||
fn aux_1(_origin, #[compact] _data: u32,) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
#[weight = 0]
|
||||
fn aux_2(_origin, _data: i32, _data2: String) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = 3]
|
||||
fn aux_3(_origin) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
#[weight = 0]
|
||||
fn aux_4(_origin, _data: i32) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
#[weight = 0]
|
||||
fn aux_5(_origin, _data: i32, #[compact] _data2: u32,) -> DispatchResult { unreachable!() }
|
||||
|
||||
#[weight = (5, DispatchClass::Operational)]
|
||||
|
||||
@@ -35,7 +35,7 @@ pub use frame_metadata::{ModuleErrorMetadata, ErrorMetadata, DecodeDifferent};
|
||||
///
|
||||
/// ```
|
||||
/// # use frame_support::{decl_error, decl_module};
|
||||
/// # use frame_support::weights::MINIMUM_WEIGHT;
|
||||
/// #
|
||||
/// decl_error! {
|
||||
/// /// Errors that can occur in my module.
|
||||
/// pub enum MyError for Module<T: Trait> {
|
||||
@@ -55,7 +55,7 @@ pub use frame_metadata::{ModuleErrorMetadata, ErrorMetadata, DecodeDifferent};
|
||||
/// pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
/// type Error = MyError<T>;
|
||||
///
|
||||
/// #[weight = MINIMUM_WEIGHT]
|
||||
/// #[weight = 0]
|
||||
/// fn do_something(origin) -> frame_support::dispatch::DispatchResult {
|
||||
/// Err(MyError::<T>::YouAreNotCoolEnough.into())
|
||||
/// }
|
||||
|
||||
@@ -334,7 +334,6 @@ mod tests {
|
||||
|
||||
mod event_module {
|
||||
use crate::dispatch::DispatchResult;
|
||||
use crate::weights::MINIMUM_WEIGHT;
|
||||
|
||||
pub trait Trait: super::system::Trait {
|
||||
type Balance;
|
||||
@@ -352,7 +351,7 @@ mod tests {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
type Error = Error<T>;
|
||||
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
#[weight = 0]
|
||||
fn aux_0(_origin) -> DispatchResult { unreachable!() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,9 +141,6 @@ pub use sp_runtime::transaction_validity::TransactionPriority;
|
||||
/// Numeric range of a transaction weight.
|
||||
pub type Weight = u64;
|
||||
|
||||
/// The smallest total weight an extrinsic should have.
|
||||
pub const MINIMUM_WEIGHT: Weight = 10_000_000;
|
||||
|
||||
/// Means of weighing some particular kind of data (`T`).
|
||||
pub trait WeighData<T> {
|
||||
/// Weigh the data `T` given by `target`. When implementing this for a dispatchable, `T` will be
|
||||
|
||||
Reference in New Issue
Block a user