-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add overhead benchmark to frame-omni-bencher (#5891)
# Benchmark Overhead Command for Parachains This implements the `benchmark overhead` command for parachains. Full context is available at: #5303. Previous attempt was this #5283, but here we have integration into frame-omni-bencher and improved tooling. ## Changes Overview Users are now able to use `frame-omni-bencher` to generate `extrinsic_weight.rs` and `block_weight.rs` files for their runtime. The core logic for generating these remains untouched; this PR provides mostly machinery to make it work for parachains at all. Similar to the pallet benchmarks, we gain the option to benchmark based on just a runtime: ``` frame-omni-bencher v1 benchmark overhead --runtime {{runtime}} ``` or with a spec: ``` frame-omni-bencher v1 benchmark overhead --chain {{spec}} --genesis-builder spec ``` In this case, the genesis state is generated from the runtime presets. However, it is also possible to use `--chain` and genesis builder `spec` to generate the genesis state from the chain spec. Additionally, we use metadata to perform some checks based on the pallets the runtime exposes: - If we see the `ParaInherent` pallet, we assume that we are dealing with a relay chain. This means that we don't need proof recording during import (since there is no storage weight). - If we detect the `ParachainSystem` pallet, we assume that we are dealing with a parachain and take corresponding actions like patching a para id into the genesis state. On the inherent side, I am currently supplying the standard inherents every parachain needs. In the current state, `frame-omni-bencher` supports all system chains. In follow-up PRs, we could add additional inherents to increase compatibility. Since we are building a block during the benchmark, we also need to build an extrinsic. By default, I am leveraging subxt to build the xt dynamically. If a chain is not compatible with the `SubstrateConfig` that comes with `subxt`, it can provide a custom extrinsic builder to benchmarking-cli. This requires either a custom bencher implementation or an integration into the parachains node. Also cumulus-test-runtime has been migrated to provide genesis configs. ## Chain Compatibility The current version here is compatible with the system chains and common substrate chains. The way to go for others would be to customize the frame-omni-bencher by providing a custom extrinsicbuilder. I did an example implementation that works for mythical: https://github.com/skunert/mythical-bencher ## Follow-Ups - After #6040 is finished, we should integrate this here to make the tooling truly useful. In the current form, the state is fairly small and not representative. ## How to Review I recommend starting from [here](https://github.com/paritytech/polkadot-sdk/pull/5891/files#diff-50830ff756b3ac3403b7739d66c9e3a5185dbea550669ca71b28d19c7a2a54ecR264), this method is the main entry point for omni-bencher and `polkadot` binary. TBD: - [x] PRDoc --------- Co-authored-by: Michal Kucharczyk <[email protected]>
- Loading branch information
1 parent
6f96f72
commit 40547f9
Showing
44 changed files
with
2,201 additions
and
590 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Cumulus. | ||
|
||
// Cumulus is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Cumulus is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use super::{ | ||
AccountId, AuraConfig, AuraId, BalancesConfig, ParachainInfoConfig, RuntimeGenesisConfig, | ||
SudoConfig, | ||
}; | ||
use alloc::{vec, vec::Vec}; | ||
|
||
use cumulus_primitives_core::ParaId; | ||
use frame_support::build_struct_json_patch; | ||
use sp_genesis_builder::PresetId; | ||
use sp_keyring::Sr25519Keyring; | ||
|
||
fn cumulus_test_runtime( | ||
invulnerables: Vec<AuraId>, | ||
endowed_accounts: Vec<AccountId>, | ||
id: ParaId, | ||
) -> serde_json::Value { | ||
build_struct_json_patch!(RuntimeGenesisConfig { | ||
balances: BalancesConfig { | ||
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), | ||
}, | ||
sudo: SudoConfig { key: Some(Sr25519Keyring::Alice.public().into()) }, | ||
parachain_info: ParachainInfoConfig { parachain_id: id }, | ||
aura: AuraConfig { authorities: invulnerables }, | ||
}) | ||
} | ||
|
||
fn testnet_genesis_with_default_endowed(self_para_id: ParaId) -> serde_json::Value { | ||
let endowed = Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect::<Vec<_>>(); | ||
|
||
let invulnerables = | ||
Sr25519Keyring::invulnerable().map(|x| x.public().into()).collect::<Vec<_>>(); | ||
cumulus_test_runtime(invulnerables, endowed, self_para_id) | ||
} | ||
|
||
/// List of supported presets. | ||
pub fn preset_names() -> Vec<PresetId> { | ||
vec![ | ||
PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET), | ||
PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET), | ||
] | ||
} | ||
|
||
/// Provides the JSON representation of predefined genesis config for given `id`. | ||
pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> { | ||
let patch = match id.try_into() { | ||
Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) | | ||
Ok(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) => | ||
testnet_genesis_with_default_endowed(100.into()), | ||
_ => return None, | ||
}; | ||
Some( | ||
serde_json::to_string(&patch) | ||
.expect("serialization to json is expected to work. qed.") | ||
.into_bytes(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.