-
Notifications
You must be signed in to change notification settings - Fork 40
feat: benchmark existing runtime binary and select policy, presets #411
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
feat: benchmark existing runtime binary and select policy, presets #411
Conversation
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## chungquantin/feat-pop_bench #411 +/- ##
==============================================================
Coverage ? 75.35%
==============================================================
Files ? 67
Lines ? 14399
Branches ? 14399
==============================================================
Hits ? 10850
Misses ? 2144
Partials ? 1405
|
<runtime-name>.wasm or trigger build if needed
AlexD10S
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks very clean and well-structured, great job!
However, I encountered a couple of issues during manual testing:
- If the node has already been built without the
--runtime-benchmarksfeature, it fails to build again because it detects the existing runtime. It throws an error (from benchmarking-cli), yet still displays a success message:
⚙ Benchmarking and generating weight file....
│
[2025-02-15T07:41:13Z INFO pallet_collator_selection::pallet] assembling new collators for new session 0 at #0
[2025-02-15T07:41:13Z INFO pallet_collator_selection::pallet] assembling new collators for new session 1 at #0
[2025-02-15T07:41:13Z INFO polkadot_sdk_frame::benchmark::pallet] Loading WASM from file
└ Failed to run benchmarking: Invalid input: Could not call runtime API to Did not find the benchmarking metadata. This could mean that you either did not build the node correctly with the `--features runtime-benchmarks` flag, or the chain spec that you are using was not created by a node that was compiled with the flag: Other: Exported method Benchmark_benchmark_metadata is not found
└ Benchmark completed successfully!Probably we can't verify whether the runtime has been build with --runtime-benchmarks at this point right? It would be ideal if we could, but if not, we should at least prevent the misleading success message. I can see here, it shows a message with the error but continue the execution: https://github.com/r0gue-io/pop-cli/blob/chugnquantin/feat-build_runtime/crates/pop-cli/src/commands/bench/mod.rs#L68
- The second issue relates to locating the WASM file, see my comment below.
Out of scope for this PR, but once the benchmarking logic is merged into main, we could consider adding a flag in pop build to handle building with the --runtime-benchmarks feature.
Scenarios
Context: The
pop bench palletcommand is run at the root directory of the parachain projectStage 1: Locating and building a
runtimebinaryruntime_path(Path to the runtime, hard-coded to "runtime" folder) is not a Rust project, list all directories in theruntime_path(similar topop-nodewhich has multiple runtimes inside theruntimefolder). After user select the runtime, we check if the runtime binary exists or not. If not, we build the runtime withruntime-benchmarksfeature.runtime_pathis a Rust project, located inside theruntimefolder, which means it is a runtime codebase (Note: There could be a chance that this is a workspace?). We will throwNo runtime foundif the workspace is not valid. We check if the runtime binary exists or not. If not, we build the runtime withruntime-benchmarksfeature.runtimefound, we throwsNo runtime found.(See diagram).Stage 2: Select genesis builder policy and input the preset.
After the runtime binary is ready, we prompts user to select the genesis builder (There are two options currently:
noneandruntime, more details can be found here). As we only support the runtime, no chain spec is provided so other genesis builder policies are not valid.noneis selected: We do nothing.runtimeis selected: The runtime must be configured withsp-genesis-builder). We prompt the user to select the available genesis builder presets (presets will be registered on the runtime usingBuildGenesisConfigruntime API).By calling sc-chain-spec::GenesisConfigBuilderRuntimeCaller
get_preset_namesmethod, we list all genesis builder presets and expect the user to select one of them. If there is no builder preset found, the CLI throwsNo preset found(can be reproduced withpop-node).--runtime=is provided, we don't locate the runtime.--genesis-builder=is provided, we don't prompt user to select the genesis builder policy.--genesis-config-preset=is provided, we don't prompt user to input the genesis config preset.How to test the PR?
Stage 1 | Scenario 1:
runtimefolder is the runtime../base-parachainor any parachain template.pop bench pallet --pallet=pallet_timestamp --extrinsic=(No runtime provided)Stage 1 | Scenario 2:
runtimecontains multiple runtime folders../pop-nodeor any parachain that has multiple runtimespop bench pallet --pallet=pallet_timestamp --extrinsic=(No runtime provided)Stage 2
genesis-builder = runtimewith available presets../base-parachainor any parachain template.pop bench pallet --pallet=pallet_timestamp --extrinsic=(No runtime provided)genesis-builder = runtimewith unavailable presets../pop-nodeor any parachain template.pop bench pallet --pallet=pallet_timestamp --extrinsic=(No runtime provided)Changelog
runtime, genesis builder policy and genesis config preset.build_projectto build any Rust projects with features and target, required for the tests of this PR. The method is shared withbuild_parachain.build_binary_pathto locate the binary path of the provided Rust project. The method is shared withbinary_pathmethod.<runtime-name>.wasmto benchmark. The path of the runtime WASM blob follows:build_projectmethod for the runtime, we build the mock project withwasm32-unknown-unknownas target and locates the.wasmfile.[sc-2931]