migrate new benchmarking syntax from frame_support::benchmarking to frame_benchmarking::v2 (#13235)

* * re-export frame_support::benchmarking in frame_benchmarking::
* prefer use frame_benchmarking::*; in examples, etc

* switch to frame_benchmarking::v2

* completely migrate new benchmarking code out of frame_support

* fix doc links

* remove unneeded return

Co-authored-by: Bastian Köcher <git@kchr.de>

* remove another unneeded return

Co-authored-by: Bastian Köcher <git@kchr.de>

* properly export all macros in v1

* refactor existing frame_benchmarking imports to use ::v1

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Sam Johnson
2023-01-27 15:59:39 -05:00
committed by GitHub
parent ae8ef86ec0
commit c9361bed1a
69 changed files with 2317 additions and 2266 deletions
+2 -1
View File
@@ -2138,6 +2138,7 @@ version = "4.0.0-dev"
dependencies = [
"array-bytes",
"frame-support",
"frame-support-procedural",
"frame-system",
"linregress",
"log",
@@ -2155,6 +2156,7 @@ dependencies = [
"sp-runtime-interface",
"sp-std",
"sp-storage",
"static_assertions",
]
[[package]]
@@ -2351,7 +2353,6 @@ dependencies = [
"sp-std",
"sp-tracing",
"sp-weights",
"static_assertions",
"tt-call",
]
@@ -4,7 +4,7 @@ use super::*;
#[allow(unused)]
use crate::Pallet as Template;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{benchmarks, whitelisted_caller};
use frame_system::RawOrigin;
benchmarks! {
+1 -1
View File
@@ -25,7 +25,7 @@ use sp_std::{
prelude::*,
};
use frame_benchmarking::{account, benchmarks_instance_pallet};
use frame_benchmarking::v1::{account, benchmarks_instance_pallet};
use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable};
use frame_system::{Pallet as System, RawOrigin as SystemOrigin};
+1 -1
View File
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller,
};
use frame_support::{
+1 -1
View File
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::benchmarks;
use frame_benchmarking::v1::benchmarks;
type Header = sp_runtime::generic::Header<u64, sp_runtime::traits::BlakeTwo256>;
+4 -2
View File
@@ -19,13 +19,15 @@
use super::*;
use crate::list::List;
use frame_benchmarking::{account, whitelist_account, whitelisted_caller};
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller,
};
use frame_election_provider_support::ScoreProvider;
use frame_support::{assert_ok, traits::Get};
use frame_system::RawOrigin as SystemOrigin;
use sp_runtime::traits::One;
frame_benchmarking::benchmarks_instance_pallet! {
benchmarks_instance_pallet! {
rebag_non_terminal {
// An expensive case for rebag-ing (rebag a non-terminal node):
//
+1 -2
View File
@@ -22,8 +22,7 @@
use super::*;
use crate::Pallet as Balances;
use frame_benchmarking::{account, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
const SEED: u32 = 0;
+2
View File
@@ -20,6 +20,7 @@ paste = "1.0"
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0.136", optional = true }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-support-procedural = { version = "4.0.0-dev", default-features = false, path = "../support/procedural" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" }
sp-application-crypto = { version = "7.0.0", default-features = false, path = "../../primitives/application-crypto" }
@@ -29,6 +30,7 @@ sp-runtime = { version = "7.0.0", default-features = false, path = "../../primit
sp-runtime-interface = { version = "7.0.0", default-features = false, path = "../../primitives/runtime-interface" }
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
sp-storage = { version = "7.0.0", default-features = false, path = "../../primitives/storage" }
static_assertions = "1.1.0"
[dev-dependencies]
array-bytes = "4.1"
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -21,7 +21,9 @@
use super::*;
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError};
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError,
};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
@@ -21,7 +21,7 @@
use super::*;
use frame_benchmarking::{account, benchmarks, whitelisted_caller, BenchmarkError};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError};
use frame_system::RawOrigin;
use crate::Pallet as ChildBounties;
@@ -23,7 +23,7 @@ use crate::Pallet as Collective;
use sp_runtime::traits::Bounded;
use sp_std::mem::size_of;
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelisted_caller};
use frame_system::{Call as SystemCall, Pallet as System, RawOrigin as SystemOrigin};
const SEED: u32 = 0;
@@ -37,7 +37,7 @@ use crate::{
Pallet as Contracts, *,
};
use codec::{Encode, MaxEncodedLen};
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_support::weights::Weight;
use frame_system::RawOrigin;
use sp_runtime::{
@@ -20,7 +20,7 @@
use super::*;
use assert_matches::assert_matches;
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist_account};
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelist_account};
use frame_support::{
dispatch::RawOrigin,
traits::{fungible, Currency, Get},
@@ -19,7 +19,7 @@
use super::*;
use frame_benchmarking::{account, benchmarks, whitelist_account};
use frame_benchmarking::v1::{account, benchmarks, whitelist_account};
use frame_support::{
assert_noop, assert_ok,
traits::{Currency, EnsureOrigin, Get, OnInitialize, UnfilteredDispatchable},
@@ -22,7 +22,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use codec::Decode;
use frame_benchmarking::{benchmarks, Vec};
use frame_benchmarking::v1::{benchmarks, Vec};
use frame_election_provider_support::{NposSolver, PhragMMS, SequentialPhragmen};
pub struct Pallet<T: Config>(frame_system::Pallet<T>);
@@ -21,7 +21,7 @@
use super::*;
use frame_benchmarking::{account, benchmarks, whitelist, BenchmarkError, BenchmarkResult};
use frame_benchmarking::v1::{account, benchmarks, whitelist, BenchmarkError, BenchmarkResult};
use frame_support::{dispatch::DispatchResultWithPostInfo, traits::OnInitialize};
use frame_system::RawOrigin;
@@ -21,8 +21,11 @@
#![cfg(feature = "runtime-benchmarks")]
use crate::*;
use frame_benchmarking::{impl_benchmark_test_suite, whitelisted_caller};
use frame_support::benchmarking::{benchmarks, Linear};
use frame_benchmarking::v1::{
impl_benchmark_test_suite,
v2::{benchmarks, Linear},
whitelisted_caller,
};
use frame_system::RawOrigin;
// To actually run this benchmark on pallet-example-basic, we need to put this pallet into the
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use crate::{types::*, Pallet as FastUnstake, *};
use frame_benchmarking::{benchmarks, whitelist_account};
use frame_benchmarking::v1::{benchmarks, whitelist_account};
use frame_support::{
assert_ok,
traits::{Currency, EnsureOrigin, Get, Hooks},
+1 -1
View File
@@ -18,7 +18,7 @@
//! Benchmarks for the GRANDPA pallet.
use super::{Pallet as Grandpa, *};
use frame_benchmarking::benchmarks;
use frame_benchmarking::v1::benchmarks;
use frame_system::RawOrigin;
use sp_core::H256;
+1 -1
View File
@@ -22,7 +22,7 @@
use super::*;
use crate::Pallet as Identity;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_support::{
ensure,
traits::{EnsureOrigin, Get},
@@ -21,7 +21,7 @@
use super::*;
use frame_benchmarking::benchmarks;
use frame_benchmarking::v1::benchmarks;
use frame_support::{traits::UnfilteredDispatchable, WeakBoundedVec};
use frame_system::RawOrigin;
use sp_core::{offchain::OpaqueMultiaddr, OpaquePeerId};
+1 -1
View File
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
+1 -1
View File
@@ -21,7 +21,7 @@
use super::*;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_support::{
storage::bounded_vec::BoundedVec,
traits::{EnsureOrigin, OnInitialize},
+1 -1
View File
@@ -362,7 +362,7 @@ impl<T: Config<I>, I: 'static> SortedMembers<T::AccountId> for Pallet<T, I> {
#[cfg(feature = "runtime-benchmarks")]
mod benchmark {
use super::{Pallet as Membership, *};
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist};
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelist};
use frame_support::{assert_ok, traits::EnsureOrigin};
use frame_system::RawOrigin;
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use crate::*;
use frame_benchmarking::benchmarks_instance_pallet;
use frame_benchmarking::v1::benchmarks_instance_pallet;
use frame_support::traits::OnInitialize;
benchmarks_instance_pallet! {
@@ -22,8 +22,8 @@
use super::{mock_helpers::*, Pallet as MessageQueue, *};
use frame_benchmarking::{impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{benchmarking::*, traits::Get};
use frame_benchmarking::v2::*;
use frame_support::traits::Get;
use frame_system::RawOrigin;
use sp_std::prelude::*;
+1 -1
View File
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{account, benchmarks};
use frame_benchmarking::v1::{account, benchmarks};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
+1 -1
View File
@@ -21,7 +21,7 @@
use super::*;
use enumflags2::{BitFlag, BitFlags};
use frame_benchmarking::{
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller,
};
use frame_support::{
+1 -1
View File
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_support::traits::{nonfungible::Inspect, Currency, EnsureOrigin, Get};
use frame_system::RawOrigin;
use sp_arithmetic::Perquintill;
@@ -23,7 +23,9 @@
#[cfg(test)]
mod mock;
use frame_benchmarking::{account, frame_support::traits::Currency, vec, whitelist_account, Vec};
use frame_benchmarking::v1::{
account, frame_support::traits::Currency, vec, whitelist_account, Vec,
};
use frame_election_provider_support::SortedListProvider;
use frame_support::{assert_ok, ensure, traits::Get};
use frame_system::RawOrigin as RuntimeOrigin;
@@ -24,7 +24,7 @@ mod mock;
use sp_std::{prelude::*, vec};
use frame_benchmarking::{account, benchmarks};
use frame_benchmarking::v1::{account, benchmarks};
use frame_support::traits::{Currency, Get, ValidatorSet, ValidatorSetWithIdentification};
use frame_system::{Config as SystemConfig, Pallet as System, RawOrigin};
+1 -1
View File
@@ -18,7 +18,7 @@
//! Preimage pallet benchmarking.
use super::*;
use frame_benchmarking::{account, benchmarks, whitelist_account};
use frame_benchmarking::v1::{account, benchmarks, whitelist_account};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
+1 -1
View File
@@ -21,7 +21,7 @@
use super::*;
use crate::Pallet as Proxy;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
@@ -21,7 +21,7 @@ use super::*;
#[allow(unused_imports)]
use crate::Pallet as RankedCollective;
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelisted_caller};
use frame_support::{assert_ok, dispatch::UnfilteredDispatchable};
use frame_system::RawOrigin as SystemOrigin;
+1 -1
View File
@@ -20,7 +20,7 @@
use super::*;
use crate::Pallet;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_support::traits::{Currency, Get};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
@@ -20,7 +20,7 @@
use super::*;
use crate::Pallet as Referenda;
use assert_matches::assert_matches;
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist_account};
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelist_account};
use frame_support::{
assert_ok,
dispatch::UnfilteredDispatchable,
+1 -1
View File
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{benchmarks, whitelisted_caller};
use frame_system::{EventRecord, Pallet as System, RawOrigin};
use sp_std::*;
@@ -18,7 +18,7 @@
//! Scheduler pallet benchmarking.
use super::*;
use frame_benchmarking::{account, benchmarks};
use frame_benchmarking::v1::{account, benchmarks};
use frame_support::{
ensure,
traits::{schedule::Priority, BoundedInline},
@@ -26,7 +26,7 @@ mod mock;
use sp_runtime::traits::{One, StaticLookup, TrailingZeroInput};
use sp_std::{prelude::*, vec};
use frame_benchmarking::benchmarks;
use frame_benchmarking::v1::benchmarks;
use frame_support::{
codec::Decode,
traits::{Get, KeyOwnerProofSystem, OnInitialize},
+1 -1
View File
@@ -35,7 +35,7 @@ use sp_runtime::{
use sp_staking::SessionIndex;
use sp_std::prelude::*;
pub use frame_benchmarking::{
pub use frame_benchmarking::v1::{
account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller,
};
use frame_system::RawOrigin;
-1
View File
@@ -27,7 +27,6 @@ sp-arithmetic = { version = "6.0.0", default-features = false, path = "../../pri
sp-inherents = { version = "4.0.0-dev", default-features = false, path = "../../primitives/inherents" }
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" }
sp-weights = { version = "4.0.0", default-features = false, path = "../../primitives/weights" }
static_assertions = "1.1.0"
tt-call = "1.0.8"
frame-support-procedural = { version = "4.0.0-dev", default-features = false, path = "./procedural" }
paste = "1.0"
@@ -638,7 +638,7 @@ fn expand_benchmark(
Ok(ident) => ident,
Err(err) => return err.to_compile_error().into(),
};
let home = quote!(#krate::frame_support::benchmarking);
let home = quote!(#krate::v2);
let codec = quote!(#krate::frame_support::codec);
let traits = quote!(#krate::frame_support::traits);
let setup_stmts = benchmark_def.setup_stmts;
@@ -483,7 +483,7 @@ pub fn pallet(attr: TokenStream, item: TokenStream) -> TokenStream {
/// An attribute macro that can be attached to a (non-empty) module declaration. Doing so will
/// designate that module as a benchmarking module.
///
/// See `frame_support::benchmarking` for more info.
/// See `frame_benchmarking::v2` for more info.
#[proc_macro_attribute]
pub fn benchmarks(attr: TokenStream, tokens: TokenStream) -> TokenStream {
match benchmark::benchmarks(attr, tokens, false) {
@@ -495,7 +495,7 @@ pub fn benchmarks(attr: TokenStream, tokens: TokenStream) -> TokenStream {
/// An attribute macro that can be attached to a (non-empty) module declaration. Doing so will
/// designate that module as an instance benchmarking module.
///
/// See `frame_support::benchmarking` for more info.
/// See `frame_benchmarking::v2` for more info.
#[proc_macro_attribute]
pub fn instance_benchmarks(attr: TokenStream, tokens: TokenStream) -> TokenStream {
match benchmark::benchmarks(attr, tokens, true) {
@@ -508,7 +508,7 @@ pub fn instance_benchmarks(attr: TokenStream, tokens: TokenStream) -> TokenStrea
/// attached to a function definition containing an `#[extrinsic_call]` or `#[block]`
/// attribute.
///
/// See `frame_support::benchmarking` for more info.
/// See `frame_benchmarking::v2` for more info.
#[proc_macro_attribute]
pub fn benchmark(_attrs: TokenStream, _tokens: TokenStream) -> TokenStream {
quote!(compile_error!(
@@ -521,7 +521,7 @@ pub fn benchmark(_attrs: TokenStream, _tokens: TokenStream) -> TokenStream {
/// used as a boundary designating where the benchmark setup code ends, and the benchmark
/// verification code begins.
///
/// See `frame_support::benchmarking` for more info.
/// See `frame_benchmarking::v2` for more info.
#[proc_macro_attribute]
pub fn extrinsic_call(_attrs: TokenStream, _tokens: TokenStream) -> TokenStream {
quote!(compile_error!(
@@ -534,7 +534,7 @@ pub fn extrinsic_call(_attrs: TokenStream, _tokens: TokenStream) -> TokenStream
/// enclosing benchmark function, This attribute is also used as a boundary designating where
/// the benchmark setup code ends, and the benchmark verification code begins.
///
/// See `frame_support::benchmarking` for more info.
/// See `frame_benchmarking::v2` for more info.
#[proc_macro_attribute]
pub fn block(_attrs: TokenStream, _tokens: TokenStream) -> TokenStream {
quote!(compile_error!(
-223
View File
@@ -2745,228 +2745,5 @@ pub mod pallet_macros {
};
}
/// Contains macros, structs, and traits associated with v2 of the pallet benchmarking syntax.
/// This module contains macros, structs, and traits associated with v2 of the pallet
/// benchmarking syntax.
///
/// The [`benchmarking::benchmarks`] and [`benchmarking::instance_benchmarks`] macros can be
/// used to designate a module as a benchmarking module that can contain benchmarks and
/// benchmark tests. The `#[benchmarks]` variant will set up a regular, non-instance
/// benchmarking module, and the `#[instance_benchmarks]` variant will set up the module in
/// instance benchmarking mode.
///
/// Benchmarking modules should be gated behind a `#[cfg(feature = "runtime-benchmarks")]`
/// feature gate to ensure benchmarking code that is only compiled when the
/// `runtime-benchmarks` feature is enabled is not referenced.
///
/// The following is the general syntax for a benchmarks (or instance benchmarks) module:
///
/// ## General Syntax
///
/// ```ignore
/// #![cfg(feature = "runtime-benchmarks")]
///
/// use super::{mock_helpers::*, Pallet as MyPallet};
/// use frame_support::benchmarking::*;
/// use frame_benchmarking::whitelisted_caller;
///
/// #[benchmarks]
/// mod benchmarks {
/// use super::*;
///
/// #[benchmark]
/// fn bench_name_1(x: Linear<7, 1_000>, y: Linear<1_000, 100_0000>) {
/// // setup code
/// let z = x + y;
/// let caller = whitelisted_caller();
///
/// #[extrinsic_call]
/// extrinsic_name(SystemOrigin::Signed(caller), other, arguments);
///
/// // verification code
/// assert_eq!(MyPallet::<T>::my_var(), z);
/// }
///
/// #[benchmark]
/// fn bench_name_2() {
/// // setup code
/// let caller = whitelisted_caller();
///
/// #[block]
/// {
/// something(some, thing);
/// my_extrinsic(RawOrigin::Signed(caller), some, argument);
/// something_else(foo, bar);
/// }
///
/// // verification code
/// assert_eq!(MyPallet::<T>::something(), 37);
/// }
/// }
/// ```
///
/// ## Benchmark Definitions
///
/// Within a `#[benchmarks]` or `#[instance_benchmarks]` module, you can define individual
/// benchmarks using the `#[benchmark]` attribute, as shown in the example above.
///
/// The `#[benchmark]` attribute expects a function definition with a blank return type and
/// zero or more arguments whose names are valid `frame_benchmarking::BenchmarkParamater`
/// parameters, such as `x`, `y`, `a`, `b`, etc., and whose param types must implement
/// [`benchmarking::ParamRange`]. At the moment the only valid type that implements
/// [`benchmarking::ParamRange`] is [`benchmarking::Linear`].
///
/// The valid syntax for defining a `Linear` is `Linear<A, B>` where `A`, and `B` are
/// valid integer literals (that fit in a `u32`), such that `B` >= `A`.
///
/// Note that the benchmark function definition does not actually expand as a function
/// definition, but rather is used to automatically create a number of impls and structs
/// required by the benchmarking engine. For this reason, the visibility of the function
/// definition as well as the return type are not used for any purpose and are discarded by the
/// expansion code.
///
/// Also note that the `// setup code` and `// verification code` comments shown above are not
/// required and are included simply for demonstration purposes.
///
/// ### `#[extrinsic_call]` and `#[block]`
///
/// Within the benchmark function body, either an `#[extrinsic_call]` or a `#[block]`
/// annotation is required. These attributes should be attached to a block (shown in
/// `bench_name_2` above) or a one-line function call (shown in `bench_name_1` above, in `syn`
/// parlance this should be an `ExprCall`), respectively.
///
/// The `#[block]` syntax is broad and will benchmark any code contained within the block the
/// attribute is attached to. If `#[block]` is attached to something other than a block, a
/// compiler error will be emitted.
///
/// The one-line `#[extrinsic_call]` syntax must consist of a function call to an extrinsic,
/// where the first argument is the origin. If `#[extrinsic_call]` is attached to an item that
/// doesn't meet these requirements, a compiler error will be emitted.
///
/// As a short-hand, you may substitute the name of the extrinsic call with `_`, such as the
/// following:
///
/// ```ignore
/// #[extrinsic_call]
/// _(RawOrigin::Signed(whitelisted_caller()), 0u32.into(), 0);
/// ```
///
/// The underscore will be substituted with the name of the benchmark (i.e. the name of the
/// function in the benchmark function definition).
///
/// Regardless of whether `#[extrinsic_call]` or `#[block]` is used, this attribute also serves
/// the purpose of designating the boundary between the setup code portion of the benchmark
/// (everything before the `#[extrinsic_call]` or `#[block]` attribute) and the verification
/// stage (everything after the item that the `#[extrinsic_call]` or `#[block]` attribute is
/// attached to). The setup code section should contain any code that needs to execute before
/// the measured portion of the benchmark executes. The verification section is where you can
/// perform assertions to verify that the extrinsic call (or whatever is happening in your
/// block, if you used the `#[block]` syntax) executed successfully.
///
/// Note that neither `#[extrinsic_call]` nor `#[block]` are real attribute macros and are
/// instead consumed by the outer macro pattern as part of the enclosing benchmark function
/// definition. This is why we are able to use `#[extrinsic_call]` and `#[block]` within a
/// function definition even though this behavior has not been stabilized
/// yet—`#[extrinsic_call]` and `#[block]` are parsed and consumed as part of the benchmark
/// definition parsing code, so they never expand as their own attribute macros.
///
/// ### Optional Attributes
///
/// The keywords `extra` and `skip_meta` can be provided as optional arguments to the
/// `#[benchmark]` attribute, i.e. `#[benchmark(extra, skip_meta)]`. Including either of these
/// will enable the `extra` or `skip_meta` option, respectively. These options enable the same
/// behavior they did in the old benchmarking syntax in `frame_benchmarking`, namely:
///
/// #### `extra`
///
/// Specifies that this benchmark should not normally run. To run benchmarks marked with
/// `extra`, you will need to invoke the `frame-benchmarking-cli` with `--extra`.
///
/// #### `skip_meta`
///
/// Specifies that the benchmarking framework should not analyze the storage keys that
/// benchmarked code read or wrote. This useful to suppress the prints in the form of unknown
/// 0x… in case a storage key that does not have metadata. Note that this skips the analysis
/// of all accesses, not just ones without metadata.
///
/// ## Where Clause
///
/// Some pallets require a where clause specifying constraints on their generics to make
/// writing benchmarks feasible. To accomodate this situation, you can provide such a where
/// clause as the (only) argument to the `#[benchmarks]` or `#[instance_benchmarks]` attribute
/// macros. Below is an example of this taken from the `message-queue` pallet.
///
/// ```ignore
/// #[benchmarks(
/// where
/// <<T as Config>::MessageProcessor as ProcessMessage>::Origin: From<u32> + PartialEq,
/// <T as Config>::Size: From<u32>,
/// )]
/// mod benchmarks {
/// use super::*;
/// // ...
/// }
/// ```
///
/// ## Benchmark Tests
///
/// Benchmark tests can be generated using the old syntax in `frame_benchmarking`,
/// including the `frame_benchmarking::impl_benchmark_test_suite` macro.
///
/// An example is shown below (taken from the `message-queue` pallet's `benchmarking` module):
/// ```ignore
/// #[benchmarks]
/// mod benchmarks {
/// use super::*;
/// // ...
/// impl_benchmark_test_suite!(
/// MessageQueue,
/// crate::mock::new_test_ext::<crate::integration_test::Test>(),
/// crate::integration_test::Test
/// );
/// }
/// ```
pub mod benchmarking {
pub use frame_support_procedural::{
benchmark, benchmarks, block, extrinsic_call, instance_benchmarks,
};
// Used in #[benchmark] implementation to ensure that benchmark function arguments
// implement [`ParamRange`].
#[doc(hidden)]
pub use static_assertions::assert_impl_all;
/// Used by the new benchmarking code to specify that a benchmarking variable is linear
/// over some specified range, i.e. `Linear<0, 1_000>` means that the corresponding variable
/// is allowed to range from `0` to `1000`, inclusive.
///
/// See [`frame_support::benchmarking`] for more info.
pub struct Linear<const A: u32, const B: u32>;
/// Trait that must be implemented by all structs that can be used as parameter range types
/// in the new benchmarking code (i.e. `Linear<0, 1_000>`). Right now there is just
/// [`Linear`] but this could later be extended to support additional non-linear parameter
/// ranges.
///
/// See [`frame_support::benchmarking`] for more info.
pub trait ParamRange {
/// Represents the (inclusive) starting number of this [`ParamRange`].
fn start(&self) -> u32;
/// Represents the (inclusive) ending number of this [`ParamRange`]
fn end(&self) -> u32;
}
impl<const A: u32, const B: u32> ParamRange for Linear<A, B> {
fn start(&self) -> u32 {
return A
}
fn end(&self) -> u32 {
return B
}
}
}
// Generate a macro that will enable/disable code based on `std` feature being active.
sp_core::generate_feature_enabled_macro!(std_enabled, feature = "std", $);
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,9 +1,9 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
#[benchmarks]
mod benches {
mod benchmarks {
#[benchmark]
fn bench(xx: Linear<1, 2>) {
#[block]
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[extrinsic_call]
mod stuff {}
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
use frame_support_test::Config;
#[benchmarks]
@@ -1,4 +1,4 @@
use frame_support::benchmarking::*;
use frame_benchmarking::v2::*;
#[allow(unused_imports)]
use frame_support_test::Config;
@@ -20,7 +20,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use codec::Encode;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{benchmarks, whitelisted_caller};
use frame_support::{dispatch::DispatchClass, storage, traits::Get};
use frame_system::{Call, Pallet as System, RawOrigin};
use sp_core::storage::well_known_keys;
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{benchmarks, TrackedStorageKey};
use frame_benchmarking::v1::{benchmarks, TrackedStorageKey};
use frame_support::{ensure, traits::OnFinalize};
use frame_system::RawOrigin;
+1 -1
View File
@@ -19,7 +19,7 @@
#![cfg(feature = "runtime-benchmarks")]
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelisted_caller};
use frame_support::ensure;
use frame_system::RawOrigin;
use sp_runtime::traits::Saturating;
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{benchmarks, whitelisted_caller};
use frame_support::traits::{Currency, Get, OnFinalize, OnInitialize};
use frame_system::{EventRecord, Pallet as System, RawOrigin};
use sp_runtime::traits::{Bounded, One, Zero};
+1 -1
View File
@@ -21,7 +21,7 @@
use super::{Pallet as Treasury, *};
use frame_benchmarking::{account, benchmarks_instance_pallet};
use frame_benchmarking::v1::{account, benchmarks_instance_pallet};
use frame_support::{
dispatch::UnfilteredDispatchable,
ensure,
+1 -1
View File
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller,
};
use frame_support::{
+1 -1
View File
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_system::RawOrigin;
const SEED: u32 = 0;
+1 -1
View File
@@ -19,7 +19,7 @@
#![cfg(feature = "runtime-benchmarks")]
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller};
use frame_support::assert_ok;
use frame_system::{Pallet as System, RawOrigin};
use sp_runtime::traits::{Bounded, CheckedDiv, CheckedMul};
@@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::benchmarks;
use frame_benchmarking::v1::benchmarks;
use frame_support::{ensure, traits::EnsureOrigin};
#[cfg(test)]