Skip to content
  • Oliver Tale-Yazdi's avatar
    [FRAME] Runtime Omni Bencher (#3512) · 9543d314
    Oliver Tale-Yazdi authored
    
    
    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: default avatarOliver Tale-Yazdi <[email protected]>
    Co-authored-by: default avatarLiam Aharon <[email protected]>
    9543d314