mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 05:51:02 +00:00
[FRAME] Runtime Omni Bencher (#3512)
This MR contains two major changes and some maintenance cleanup. ## 1. Free Standing Pallet Benchmark Runner Closes https://github.com/paritytech/polkadot-sdk/issues/3045, depends on your runtime exposing the `GenesisBuilderApi` (like https://github.com/paritytech/polkadot-sdk/pull/1492). Introduces a new binary crate: `frame-omni-bencher`. It allows to directly benchmark a WASM blob - without needing a node or chain spec. This makes it much easier to generate pallet weights and should allow us to remove bloaty code from the node. It should work for all FRAME runtimes that dont use 3rd party host calls or non `BlakeTwo256` block hashing (basically all polkadot parachains should work). It is 100% backwards compatible with the old CLI args, when the `v1` compatibility command is used. This is done to allow for forwards compatible addition of new commands. ### Example (full example in the Rust docs) Installing the CLI: ```sh cargo install --locked --path substrate/utils/frame/omni-bencher frame-omni-bencher --help ``` Building the Westend runtime: ```sh cargo build -p westend-runtime --release --features runtime-benchmarks ``` Benchmarking the runtime: ```sh frame-omni-bencher v1 benchmark pallet --runtime target/release/wbuild/westend-runtime/westend_runtime.compact.compressed.wasm --all ``` ## 2. Building the Benchmark Genesis State in the Runtime Closes https://github.com/paritytech/polkadot-sdk/issues/2664 This adds `--runtime` and `--genesis-builder=none|runtime|spec` arguments to the `benchmark pallet` command to make it possible to generate the genesis storage by the runtime. This can be used with both the node and the freestanding benchmark runners. It utilizes the new `GenesisBuilder` RA and depends on having https://github.com/paritytech/polkadot-sdk/pull/3412 deployed. ## 3. Simpler args for `PalletCmd::run` You can do three things here to integrate the changes into your node: - nothing: old code keeps working as before but emits a deprecated warning - delete: remove the pallet benchmarking code from your node and use the omni-bencher instead - patch: apply the patch below and keep using as currently. This emits a deprecated warning at runtime, since it uses the old way to generate a genesis state, but is the smallest change. ```patch runner.sync_run(|config| cmd - .run::<HashingFor<Block>, ReclaimHostFunctions>(config) + .run_with_spec::<HashingFor<Block>, ReclaimHostFunctions>(Some(config.chain_spec)) ) ``` ## 4. Maintenance Change - `pallet-nis` get a `BenchmarkSetup` config item to prepare its counterparty asset. - Add percent progress print when running benchmarks. - Dont immediately exit on benchmark error but try to run as many as possible and print errors last. --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
This commit is contained in:
committed by
GitHub
parent
216509dbaa
commit
9543d31474
@@ -106,6 +106,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
fund_deficit {
|
||||
T::BenchmarkSetup::create_counterpart_asset();
|
||||
let origin =
|
||||
T::FundOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
@@ -126,6 +127,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
communify {
|
||||
T::BenchmarkSetup::create_counterpart_asset();
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let bid = T::MinBid::get().max(One::one()) * 100u32.into();
|
||||
let ed = T::Currency::minimum_balance();
|
||||
@@ -139,6 +141,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
privatize {
|
||||
T::BenchmarkSetup::create_counterpart_asset();
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let bid = T::MinBid::get().max(One::one());
|
||||
let ed = T::Currency::minimum_balance();
|
||||
@@ -153,6 +156,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
thaw_private {
|
||||
T::BenchmarkSetup::create_counterpart_asset();
|
||||
let whale: T::AccountId = account("whale", 0, SEED);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let bid = T::MinBid::get().max(One::one());
|
||||
@@ -170,6 +174,7 @@ benchmarks! {
|
||||
}
|
||||
|
||||
thaw_communal {
|
||||
T::BenchmarkSetup::create_counterpart_asset();
|
||||
let whale: T::AccountId = account("whale", 0, SEED);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let bid = T::MinBid::get().max(One::one());
|
||||
|
||||
@@ -155,6 +155,18 @@ impl<T> Convert<Perquintill, u32> for NoCounterpart<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Setup the empty genesis state for benchmarking.
|
||||
pub trait BenchmarkSetup {
|
||||
/// Create the counterpart asset. Should panic on error.
|
||||
///
|
||||
/// This is called prior to assuming that a counterpart balance exists.
|
||||
fn create_counterpart_asset();
|
||||
}
|
||||
|
||||
impl BenchmarkSetup for () {
|
||||
fn create_counterpart_asset() {}
|
||||
}
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::{FunInspect, FunMutate};
|
||||
@@ -297,6 +309,10 @@ pub mod pallet {
|
||||
/// The maximum proportion which may be thawed and the period over which it is reset.
|
||||
#[pallet::constant]
|
||||
type ThawThrottle: Get<(Perquintill, BlockNumberFor<Self>)>;
|
||||
|
||||
/// Setup the state for benchmarking.
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkSetup: crate::BenchmarkSetup;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
|
||||
@@ -121,6 +121,8 @@ impl pallet_nis::Config for Test {
|
||||
type MinReceipt = MinReceipt;
|
||||
type ThawThrottle = ThawThrottle;
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkSetup = ();
|
||||
}
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
|
||||
Reference in New Issue
Block a user