mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 14:21:11 +00:00
9543d31474
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>
150 lines
4.4 KiB
Rust
150 lines
4.4 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use clap::Parser;
|
|
use frame_benchmarking_cli::BenchmarkCmd;
|
|
use sc_cli::Result;
|
|
use sp_runtime::traits::BlakeTwo256;
|
|
|
|
/// # Polkadot Omni Benchmarking CLI
|
|
///
|
|
/// The Polkadot Omni benchmarker allows to benchmark the extrinsics of any Polkadot runtime. It is
|
|
/// meant to replace the current manual integration of the `benchmark pallet` into every parachain
|
|
/// node. This reduces duplicate code and makes maintenance for builders easier. The CLI is
|
|
/// currently only able to benchmark extrinsics. In the future it is planned to extend this to some
|
|
/// other areas.
|
|
///
|
|
/// General FRAME runtimes could also be used with this benchmarker, as long as they don't utilize
|
|
/// any host functions that are not part of the Polkadot host specification.
|
|
///
|
|
/// ## Installation
|
|
///
|
|
/// Directly via crates.io:
|
|
///
|
|
/// ```sh
|
|
/// cargo install --locked frame-omni-bencher
|
|
/// ```
|
|
///
|
|
/// or when the sources are locally checked out:
|
|
///
|
|
/// ```sh
|
|
/// cargo install --locked --path substrate/utils/frame/omni-bencher --profile=production
|
|
/// ```
|
|
///
|
|
/// Check the installed version and print the docs:
|
|
///
|
|
/// ```sh
|
|
/// frame-omni-bencher --help
|
|
/// ```
|
|
///
|
|
/// ## Usage
|
|
///
|
|
/// First we need to ensure that there is a runtime available. As example we will build the Westend
|
|
/// runtime:
|
|
///
|
|
/// ```sh
|
|
/// cargo build -p westend-runtime --profile production --features runtime-benchmarks
|
|
/// ```
|
|
///
|
|
/// Now as example we benchmark `pallet_balances`:
|
|
///
|
|
/// ```sh
|
|
/// frame-omni-bencher v1 benchmark pallet \
|
|
/// --runtime target/release/wbuild/westend-runtime/westend-runtime.compact.compressed.wasm \
|
|
/// --pallet "pallet_balances" --extrinsic ""
|
|
/// ```
|
|
///
|
|
/// For the exact arguments of the `pallet` command, please refer to the `pallet` sub-module.
|
|
///
|
|
/// ## Backwards Compatibility
|
|
///
|
|
/// The exposed pallet sub-command is identical as the node-integrated CLI. The only difference is
|
|
/// that it needs to be prefixed with a `v1` to ensure drop-in compatibility.
|
|
#[derive(Parser, Debug)]
|
|
#[clap(author, version, about, verbatim_doc_comment)]
|
|
pub struct Command {
|
|
#[command(subcommand)]
|
|
sub: SubCommand,
|
|
}
|
|
|
|
/// Root-level subcommands.
|
|
#[derive(Debug, clap::Subcommand)]
|
|
pub enum SubCommand {
|
|
/// Compatibility syntax with the old benchmark runner.
|
|
V1(V1Command),
|
|
// NOTE: Here we can add new commands in a forward-compatible way. For example when
|
|
// transforming the CLI from a monolithic design to a data driven pipeline, there could be
|
|
// commands like `measure`, `analyze` and `render`.
|
|
}
|
|
|
|
/// A command that conforms to the legacy `benchmark` argument syntax.
|
|
#[derive(Parser, Debug)]
|
|
pub struct V1Command {
|
|
#[command(subcommand)]
|
|
sub: V1SubCommand,
|
|
}
|
|
|
|
/// The `v1 benchmark` subcommand.
|
|
#[derive(Debug, clap::Subcommand)]
|
|
pub enum V1SubCommand {
|
|
Benchmark(V1BenchmarkCommand),
|
|
}
|
|
|
|
/// Subcommands for `v1 benchmark`.
|
|
#[derive(Parser, Debug)]
|
|
pub struct V1BenchmarkCommand {
|
|
#[command(subcommand)]
|
|
sub: BenchmarkCmd,
|
|
}
|
|
|
|
type HostFunctions = (
|
|
sp_statement_store::runtime_api::HostFunctions,
|
|
cumulus_primitives_proof_size_hostfunction::storage_proof_size::HostFunctions,
|
|
);
|
|
|
|
impl Command {
|
|
pub fn run(self) -> Result<()> {
|
|
match self.sub {
|
|
SubCommand::V1(V1Command { sub }) => sub.run(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl V1SubCommand {
|
|
pub fn run(self) -> Result<()> {
|
|
let pallet = match self {
|
|
V1SubCommand::Benchmark(V1BenchmarkCommand { sub }) => match sub {
|
|
BenchmarkCmd::Pallet(pallet) => pallet,
|
|
_ =>
|
|
return Err(
|
|
"Only the `v1 benchmark pallet` command is currently supported".into()
|
|
),
|
|
},
|
|
};
|
|
|
|
if let Some(spec) = pallet.shared_params.chain {
|
|
return Err(format!(
|
|
"Chain specs are not supported. Please remove `--chain={spec}` and use \
|
|
`--runtime=<PATH>` instead"
|
|
)
|
|
.into())
|
|
}
|
|
|
|
pallet.run_with_spec::<BlakeTwo256, HostFunctions>(None)
|
|
}
|
|
}
|