Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[omni-bencher] Make all runtimes work #5872

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3631111
Set genesis state after each benchmark run
ggwpez Sep 9, 2024
a2cc75a
Add test
ggwpez Sep 9, 2024
50ce303
Add PrDoc (auto generated)
ggwpez Sep 9, 2024
6e87e57
Use DEV_RUNTIME_PRESET instead of hard-coding
ggwpez Sep 10, 2024
9aa865f
INSTALL WITH LOCKED FFS
ggwpez Sep 10, 2024
6bb2cb5
Revert "INSTALL WITH LOCKED FFS"
ggwpez Sep 10, 2024
c846cf5
Only test in std
ggwpez Sep 13, 2024
8809ce5
omni-bencher: Fix runtime genesis generation
ggwpez Sep 13, 2024
a9ec975
Update substrate/utils/frame/benchmarking-cli/src/pallet/command.rs
ggwpez Sep 16, 2024
f205230
Update substrate/utils/frame/benchmarking-cli/src/pallet/command.rs
ggwpez Sep 16, 2024
669c88a
Update substrate/utils/frame/benchmarking-cli/src/pallet/command.rs
ggwpez Sep 16, 2024
a539e2a
Update substrate/utils/frame/benchmarking-cli/src/pallet/command.rs
ggwpez Sep 16, 2024
f641517
Stay backwards compatible
ggwpez Sep 16, 2024
1da1213
Rename to GenesisBuilderPolicy
ggwpez Sep 20, 2024
b98d341
Merge branch 'master' into oty-omni-bencher-fix
ggwpez Sep 20, 2024
68413fa
clippy
ggwpez Sep 21, 2024
8b97944
clippy
ggwpez Sep 21, 2024
41cb2bf
clippy
ggwpez Sep 21, 2024
b3e8e15
fix bench test
ggwpez Sep 21, 2024
f7bfa0a
Merge branch 'master' into oty-omni-bencher-fix
bkontur Sep 22, 2024
4fd7581
Enable also new GHA for short-benchmarks
bkontur Sep 22, 2024
516ca5c
use correct runner for benches
alvicsam Sep 23, 2024
26d9379
Merge branch 'master' into bko-enable-gha-short-benchmarks
bkontur Sep 25, 2024
96540cb
[omni-bencher] Make work with --runtime and genesis-builder-policy=none
ggwpez Sep 30, 2024
f5f67d6
[omni-bencher] Add --exclude-pallets option
ggwpez Sep 30, 2024
2256664
CI use matrix for args
ggwpez Sep 30, 2024
59fc11f
Merge remote-tracking branch 'origin/bko-enable-gha-short-benchmarks'…
ggwpez Sep 30, 2024
d18d0a7
post merge fixes
ggwpez Sep 30, 2024
30ee680
Merge branch 'master' into oty-omni-bencher-fix2
ggwpez Sep 30, 2024
82a1ca8
fix ci
ggwpez Sep 30, 2024
e836ab4
fix ci
ggwpez Sep 30, 2024
f7e6a1d
fix ci
ggwpez Sep 30, 2024
c667d9c
fix ci
ggwpez Sep 30, 2024
f25e1f1
quiet
ggwpez Sep 30, 2024
710723c
fix
ggwpez Sep 30, 2024
aab1444
Fix missing
ggwpez Sep 30, 2024
3a42eb4
Fix missing
ggwpez Sep 30, 2024
1c70dd5
Add PrDoc (auto generated)
ggwpez Sep 30, 2024
0a8ae23
Remove old migration and fix benchmarks
ggwpez Oct 1, 2024
f4fd151
Dont exclude pallet-contracts anymore
ggwpez Oct 1, 2024
c2c4894
Merge remote-tracking branch 'origin/master' into oty-omni-bencher-fix2
ggwpez Oct 1, 2024
69d6321
add bench_flags to /cmd
mordamax Oct 1, 2024
00f7e9d
prdoc
ggwpez Oct 2, 2024
5d0d5ab
dont canonicalize path
ggwpez Oct 7, 2024
2ec7f9e
Apply suggestions from code review
ggwpez Oct 7, 2024
1235303
Merge branch 'master' into oty-omni-bencher-fix2
ggwpez Oct 7, 2024
63125fe
Add log target and better error message
ggwpez Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions .github/workflows/check-frame-omni-bencher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ env:
ARTIFACTS_NAME: frame-omni-bencher-artifacts

jobs:

preflight:
# TODO: remove once migration is complete or this workflow is fully stable
if: contains(github.event.label.name, 'GHA-migration')
uses: ./.github/workflows/reusable-preflight.yml

quick-benchmarks-omni:
runs-on: ${{ needs.preflight.outputs.RUNNER }}
runs-on: parity-benchmark
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
needs: [preflight]
if: ${{ needs.preflight.outputs.changes_rust }}
env:
RUSTFLAGS: "-C debug-assertions"
RUST_BACKTRACE: "full"
WASM_BUILD_NO_COLOR: 1
WASM_BUILD_RUSTFLAGS: "-C debug-assertions"
RUST_LOG: "frame_omni_bencher=info,polkadot_sdk_frame=info"
timeout-minutes: 30
container:
image: ${{ needs.preflight.outputs.IMAGE }}
Expand All @@ -42,33 +40,41 @@ jobs:
forklift cargo build --locked --quiet --release -p asset-hub-westend-runtime --features runtime-benchmarks
forklift cargo run --locked --release -p frame-omni-bencher --quiet -- v1 benchmark pallet --runtime target/release/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.compact.compressed.wasm --all --steps 2 --repeat 1 --quiet

runtime-matrix:
runs-on: ubuntu-latest
needs: [preflight]
if: ${{ needs.preflight.outputs.changes_rust }}
timeout-minutes: 30
outputs:
runtime: ${{ steps.runtime.outputs.runtime }}
container:
image: ${{ needs.preflight.outputs.IMAGE }}
name: Extract runtimes from matrix
steps:
- uses: actions/checkout@v4
- id: runtime
run: |
RUNTIMES=$(jq '[.[] | select(.package != null)]' .github/workflows/runtimes-matrix.json)

RUNTIMES=$(echo $RUNTIMES | jq -c .)
echo "runtime=$RUNTIMES"
echo "runtime=$RUNTIMES" >> $GITHUB_OUTPUT

run-frame-omni-bencher:
runs-on: ${{ needs.preflight.outputs.RUNNER }}
needs: [preflight] # , build-frame-omni-bencher ]
runs-on: parity-benchmark
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
needs: [preflight, runtime-matrix]
if: ${{ needs.preflight.outputs.changes_rust }}
timeout-minutes: 30
strategy:
fail-fast: false # keep running other workflows even if one fails, to see the logs of all possible failures
matrix:
runtime:
[
westend-runtime,
rococo-runtime,
asset-hub-rococo-runtime,
asset-hub-westend-runtime,
bridge-hub-rococo-runtime,
bridge-hub-westend-runtime,
collectives-westend-runtime,
coretime-rococo-runtime,
coretime-westend-runtime,
people-rococo-runtime,
people-westend-runtime,
glutton-westend-runtime,
]
runtime: ${{ fromJSON(needs.runtime-matrix.outputs.runtime) }}
container:
image: ${{ needs.preflight.outputs.IMAGE }}
env:
PACKAGE_NAME: ${{ matrix.runtime }}
PACKAGE_NAME: ${{ matrix.runtime.package }}
FLAGS: ${{ matrix.runtime.bench_flags }}
RUST_LOG: "frame_omni_bencher=info,polkadot_sdk_frame=info"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -77,10 +83,13 @@ jobs:
run: |
RUNTIME_BLOB_NAME=$(echo $PACKAGE_NAME | sed 's/-/_/g').compact.compressed.wasm
RUNTIME_BLOB_PATH=./target/release/wbuild/$PACKAGE_NAME/$RUNTIME_BLOB_NAME
forklift cargo build --release --locked -p $PACKAGE_NAME -p frame-omni-bencher --features runtime-benchmarks
forklift cargo build --release --locked -p $PACKAGE_NAME -p frame-omni-bencher --features runtime-benchmarks --quiet
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
echo "Running short benchmarking for PACKAGE_NAME=$PACKAGE_NAME and RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH"
ls -lrt $RUNTIME_BLOB_PATH
./target/release/frame-omni-bencher v1 benchmark pallet --runtime $RUNTIME_BLOB_PATH --all --steps 2 --repeat 1

cmd="./target/release/frame-omni-bencher v1 benchmark pallet --runtime $RUNTIME_BLOB_PATH --all --steps 2 --repeat 1 $FLAGS"
echo "Running command: $cmd"
eval "$cmd"
confirm-frame-omni-benchers-passed:
runs-on: ubuntu-latest
name: All benchmarks passed
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/runtimes-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "kitchensink-runtime",
"path": "substrate/frame",
"header": "substrate/HEADER-APACHE2",
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic,pallet_nomination_pools,pallet_remark,pallet_transaction_storage",
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
"template": "substrate/.maintain/frame-weight-template.hbs",
"bench_features": "runtime-benchmarks,riscv",
"uri": null,
Expand Down Expand Up @@ -84,6 +85,7 @@
"path": "cumulus/parachains/runtimes/contracts/contracts-rococo",
"header": "cumulus/file_header.txt",
"bench_features": "runtime-benchmarks",
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_contracts",
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
"template": "cumulus/templates/xcm-bench-template.hbs",
"uri": "wss://rococo-contracts-rpc.polkadot.io:443",
"is_relay": false
Expand All @@ -94,6 +96,7 @@
"path": "cumulus/parachains/runtimes/coretime/coretime-rococo",
"header": "cumulus/file_header.txt",
"bench_features": "runtime-benchmarks",
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
"template": "cumulus/templates/xcm-bench-template.hbs",
"uri": "wss://rococo-coretime-rpc.polkadot.io:443",
"is_relay": false
Expand All @@ -104,6 +107,7 @@
"path": "cumulus/parachains/runtimes/coretime/coretime-westend",
"header": "cumulus/file_header.txt",
"bench_features": "runtime-benchmarks",
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
"template": "cumulus/templates/xcm-bench-template.hbs",
"uri": "wss://westend-coretime-rpc.polkadot.io:443",
"is_relay": false
Expand All @@ -114,6 +118,7 @@
"path": "cumulus/parachains/runtimes/gluttons/glutton-westend",
"header": "cumulus/file_header.txt",
"bench_features": "runtime-benchmarks",
"bench_flags": "--genesis-builder-policy=none",
"template": "cumulus/templates/xcm-bench-template.hbs",
"uri": null,
"is_relay": false
Expand All @@ -124,6 +129,7 @@
"path": "cumulus/parachains/runtimes/people/people-rococo",
"header": "cumulus/file_header.txt",
"bench_features": "runtime-benchmarks",
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
"template": "cumulus/templates/xcm-bench-template.hbs",
"uri": "wss://rococo-people-rpc.polkadot.io:443",
"is_relay": false
Expand All @@ -134,6 +140,7 @@
"path": "cumulus/parachains/runtimes/people/people-westend",
"header": "cumulus/file_header.txt",
"bench_features": "runtime-benchmarks",
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
"template": "cumulus/templates/xcm-bench-template.hbs",
"uri": "wss://westend-people-rpc.polkadot.io:443",
"is_relay": false
Expand Down
13 changes: 13 additions & 0 deletions prdoc/pr_5872.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: '[omni-bencher] Make all runtimes work'
doc:
- audience: Runtime Dev
description: |-
Changes:
- Add `--exclude-pallets` to exclude some pallets from runtimes where we dont have genesis presets yet
- Make `--genesis-builder-policy=none` work with `--runtime`
- CI: Run the frame-omni-bencher for all runtimes
crates:
- name: frame-benchmarking-cli
bump: patch
- name: frame-benchmarking-pallet-pov
bump: patch
68 changes: 41 additions & 27 deletions substrate/utils/frame/benchmarking-cli/src/pallet/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use sp_core::{
testing::{TestOffchainExt, TestTransactionPoolExt},
OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,
},
traits::{CallContext, CodeExecutor, ReadRuntimeVersionExt},
traits::{CallContext, CodeExecutor, ReadRuntimeVersionExt, WrappedRuntimeCode},
Hasher,
};
use sp_externalities::Extensions;
Expand All @@ -47,6 +47,7 @@ use sp_storage::{well_known_keys::CODE, Storage};
use sp_trie::{proof_size_extension::ProofSizeExt, recorder::Recorder};
use sp_wasm_interface::HostFunctions;
use std::{
borrow::Cow,
collections::{BTreeMap, BTreeSet, HashMap},
fmt::Debug,
fs,
Expand Down Expand Up @@ -502,33 +503,28 @@ impl PalletCmd {
}

fn select_benchmarks_to_run(&self, list: Vec<BenchmarkList>) -> Result<Vec<SelectedBenchmark>> {
let pallet = self.pallet.clone().unwrap_or_default();
let pallet = pallet.as_bytes();

let extrinsic = self.extrinsic.clone().unwrap_or_default();
let extrinsic_split: Vec<&str> = extrinsic.split(',').collect();
let extrinsics: Vec<_> = extrinsic_split.iter().map(|x| x.trim().as_bytes()).collect();

// Use the benchmark list and the user input to determine the set of benchmarks to run.
let mut benchmarks_to_run = Vec::new();
list.iter()
.filter(|item| pallet.is_empty() || pallet == &b"*"[..] || pallet == &item.pallet[..])
.for_each(|item| {
for benchmark in &item.benchmarks {
let benchmark_name = &benchmark.name;
if extrinsic.is_empty() ||
extrinsic.as_bytes() == &b"*"[..] ||
extrinsics.contains(&&benchmark_name[..])
{
benchmarks_to_run.push((
item.pallet.clone(),
benchmark.name.clone(),
benchmark.components.clone(),
benchmark.pov_modes.clone(),
))
}
list.iter().filter(|item| self.pallet_selected(&item.pallet)).for_each(|item| {
for benchmark in &item.benchmarks {
let benchmark_name = &benchmark.name;
if extrinsic.is_empty() ||
extrinsic.as_bytes() == &b"*"[..] ||
extrinsics.contains(&&benchmark_name[..])
{
benchmarks_to_run.push((
item.pallet.clone(),
benchmark.name.clone(),
benchmark.components.clone(),
benchmark.pov_modes.clone(),
))
}
});
}
});
// Convert `Vec<u8>` to `String` for better readability.
let benchmarks_to_run: Vec<_> = benchmarks_to_run
.into_iter()
Expand Down Expand Up @@ -558,6 +554,16 @@ impl PalletCmd {
Ok(benchmarks_to_run)
}

/// Whether this pallet should be run.
fn pallet_selected(&self, pallet: &Vec<u8>) -> bool {
let include = self.pallet.clone().unwrap_or_default();

let included = include.is_empty() || include == "*" || include.as_bytes() == pallet;
let excluded = self.exclude_pallets.iter().any(|p| p.as_bytes() == pallet);

included && !excluded
}

/// Build the genesis storage by either the Genesis Builder API, chain spec or nothing.
///
/// Behaviour can be controlled by the `--genesis-builder` flag.
Expand All @@ -566,8 +572,7 @@ impl PalletCmd {
chain_spec: &Option<Box<dyn ChainSpec>>,
) -> Result<sp_storage::Storage> {
Ok(match (self.genesis_builder, self.runtime.as_ref()) {
(Some(GenesisBuilderPolicy::None), Some(_)) => return Err("Cannot use `--genesis-builder=none` with `--runtime` since the runtime would be ignored.".into()),
(Some(GenesisBuilderPolicy::None), None) => Storage::default(),
(Some(GenesisBuilderPolicy::None), _) => Storage::default(),
(Some(GenesisBuilderPolicy::SpecGenesis | GenesisBuilderPolicy::Spec), Some(_)) =>
return Err("Cannot use `--genesis-builder=spec-genesis` with `--runtime` since the runtime would be ignored.".into()),
(Some(GenesisBuilderPolicy::SpecGenesis | GenesisBuilderPolicy::Spec), None) | (None, None) => {
Expand Down Expand Up @@ -690,10 +695,19 @@ impl PalletCmd {
&self,
state: &'a BenchmarkingState<H>,
) -> Result<FetchedCode<'a, BenchmarkingState<H>, H>> {
log::info!("Loading WASM from state");
let state = sp_state_machine::backend::BackendRuntimeCode::new(state);

Ok(FetchedCode { state })
if let Some(runtime) = self.runtime.as_ref() {
log::info!("Loading WASM from file");
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
let code = fs::read(runtime)?;
let hash = sp_core::blake2_256(&code).to_vec();
let wrapped_code = WrappedRuntimeCode(Cow::Owned(code));

Ok(FetchedCode::FromFile { wrapped_code, heap_pages: self.heap_pages, hash })
} else {
log::info!("Loading WASM from state");
let state = sp_state_machine::backend::BackendRuntimeCode::new(state);

Ok(FetchedCode::FromGenesis { state })
}
}

/// Allocation strategy for pallet benchmarking.
Expand Down
4 changes: 4 additions & 0 deletions substrate/utils/frame/benchmarking-cli/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ pub struct PalletCmd {
#[arg(short, long, required_unless_present_any = ["list", "json_input", "all"], default_value_if("all", "true", Some("*".into())))]
pub extrinsic: Option<String>,

/// Comma separated list of pallets that should be excluded from the benchmark.
#[arg(long, value_parser, num_args = 1.., value_delimiter = ',')]
pub exclude_pallets: Vec<String>,

/// Run benchmarks for all pallets and extrinsics.
///
/// This is equivalent to running `--pallet * --extrinsic *`.
Expand Down
16 changes: 12 additions & 4 deletions substrate/utils/frame/benchmarking-cli/src/pallet/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Various types used by this crate.

use sc_cli::Result;
use sp_core::traits::RuntimeCode;
use sp_core::traits::{RuntimeCode, WrappedRuntimeCode};
use sp_runtime::traits::Hash;

/// How the genesis state for benchmarking should be build.
Expand All @@ -43,8 +43,9 @@ pub enum GenesisBuilderPolicy {
/// A runtime blob that was either fetched from genesis storage or loaded from a file.
// NOTE: This enum is only needed for the annoying lifetime bounds on `RuntimeCode`. Otherwise we
// could just directly return the blob.
pub struct FetchedCode<'a, B, H> {
pub state: sp_state_machine::backend::BackendRuntimeCode<'a, B, H>,
pub enum FetchedCode<'a, B, H> {
FromGenesis { state: sp_state_machine::backend::BackendRuntimeCode<'a, B, H> },
FromFile { wrapped_code: WrappedRuntimeCode<'a>, heap_pages: Option<u64>, hash: Vec<u8> },
}

impl<'a, B, H> FetchedCode<'a, B, H>
Expand All @@ -54,7 +55,14 @@ where
{
/// The runtime blob.
pub fn code(&'a self) -> Result<RuntimeCode<'a>> {
self.state.runtime_code().map_err(Into::into)
match self {
Self::FromGenesis { state } => state.runtime_code().map_err(Into::into),
Self::FromFile { wrapped_code, heap_pages, hash } => Ok(RuntimeCode {
code_fetcher: wrapped_code,
heap_pages: *heap_pages,
hash: hash.clone(),
}),
}
}
}

Expand Down