Skip to content

Commit afe696b

Browse files
bkonturbkchr
andauthored
Short benchmarking in CI with frame-omni-bencher + extract chain-spec-builder stuff to get_preset (#379)
This PR introduces a new CI pipeline for checking and running runtime benchmarks as part of the test pipelines. This means we will now know if any changes break the benchmarks. The pipeline is based on downloading `frame-omni-bencher` (building it in-place is too expensive for every matrix run) and running it with a minimal setup: `--steps 2 --repeat 1`. Another part of this PR splits the default genesis setups from `chain-spec-generator` and moves them to the `sp_genesis_builder::GenesisBuilder::get_preset` runtime API implementation for every runtime, which is required by `frame-omni-bencher`. Closes: #197 Relates to: #298 Relates to: #324 <!-- Remember that you can run `/merge` to enable auto-merge in the PR --> <!-- Remember to modify the changelog. If you don't need to modify it, you can check the following box. Instead, if you have already modified it, simply delete the following line. --> - [X] Does not require a CHANGELOG entry ## Future works When [this issue](paritytech/polkadot-sdk#5083) is fixed, I will rewrite [weight-generation.md](https://github.com/polkadot-fellows/runtimes/blob/main/docs/weight-generation.md). The new version will be significantly simplified, with instructions to simply download `frame-omni-bencher`, build the runtime WASM, and run it—no other steps will be necessary. ``` 2024-07-18 14:45:51 Using the chain spec instead of the runtime to generate the genesis state is deprecated. Please remove the `--chain`/`--dev`/`--local` argument, point `--runtime` to your runtime blob and set `--genesis-builder=runtime`. This warning may become a hard error any time after December 2024. ``` --------- Co-authored-by: Bastian Köcher <[email protected]>
1 parent 7674917 commit afe696b

File tree

50 files changed

+1679
-1337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1679
-1337
lines changed

.github/workflows/test.yml

+24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
pull_request:
1010
workflow_dispatch:
1111

12+
env:
13+
FRAME_OMNI_BENCHER_RELEASE_VERSION: polkadot-v1.13.0
14+
1215
# cancel previous runs
1316
concurrency:
1417
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -82,6 +85,13 @@ jobs:
8285
with:
8386
shared-key: "fellowship-cache-tests"
8487

88+
- name: Download frame-omni-bencher
89+
run: |
90+
curl -sL https://github.com/paritytech/polkadot-sdk/releases/download/$FRAME_OMNI_BENCHER_RELEASE_VERSION/frame-omni-bencher -o frame-omni-bencher
91+
chmod +x ./frame-omni-bencher
92+
./frame-omni-bencher --version
93+
shell: bash
94+
8595
- name: Test ${{ matrix.runtime.name }}
8696
run: cargo test -p ${{ matrix.runtime.package }} --release --locked -q
8797
env:
@@ -93,6 +103,20 @@ jobs:
93103
RUSTFLAGS: "-C debug-assertions -D warnings"
94104
SKIP_WASM_BUILD: 1
95105

106+
- name: Test benchmarks ${{ matrix.runtime.name }}
107+
run: |
108+
PACKAGE_NAME=${{ matrix.runtime.package }}
109+
RUNTIME_BLOB_NAME=$(echo $PACKAGE_NAME | sed 's/-/_/g').compact.compressed.wasm
110+
RUNTIME_BLOB_PATH=./target/production/wbuild/$PACKAGE_NAME/$RUNTIME_BLOB_NAME
111+
# build wasm
112+
echo "Preparing wasm for benchmarking RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH"
113+
cargo build --profile production -p ${{ matrix.runtime.package }} --features=runtime-benchmarks -q --locked
114+
# run benchmarking
115+
echo "Running benchmarking for RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH"
116+
./frame-omni-bencher v1 benchmark pallet --runtime $RUNTIME_BLOB_PATH --all --steps 2 --repeat 1
117+
env:
118+
RUSTFLAGS: "-C debug-assertions -D warnings"
119+
96120
# Job required by "confirmTestPassed"
97121
integration-test:
98122
needs: [integration-test-matrix]

Cargo.lock

+13-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ sc-chain-spec = { version = "34.0.0" }
191191
scale-info = { version = "2.10.0", default-features = false }
192192
separator = { version = "0.4.1" }
193193
serde = { version = "1.0.196" }
194-
serde_json = { version = "1.0.113" }
194+
serde_json = { version = "1.0.113", default-features = false }
195195
smallvec = { version = "1.13.1" }
196196
snowbridge-beacon-primitives = { version = "0.7.0", default-features = false }
197197
snowbridge-core = { version = "0.7.0", default-features = false }
@@ -271,6 +271,7 @@ members = [
271271
"integration-tests/emulated/tests/coretime/coretime-kusama",
272272
"integration-tests/emulated/tests/people/people-kusama",
273273
"integration-tests/emulated/tests/people/people-polkadot",
274+
"integration-tests/zombienet",
274275
"relay/kusama",
275276
"relay/kusama/constants",
276277
"relay/polkadot",
@@ -291,7 +292,6 @@ members = [
291292
"system-parachains/gluttons/glutton-kusama",
292293
"system-parachains/people/people-kusama",
293294
"system-parachains/people/people-polkadot",
294-
"integration-tests/zombienet",
295295
]
296296

297297
[profile.release]

chain-spec-generator/Cargo.toml

-21
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,9 @@ serde_json = { workspace = true }
1212
serde = { features = ["derive"], workspace = true }
1313

1414
polkadot-runtime = { workspace = true }
15-
polkadot-runtime-constants = { workspace = true, default-features = true }
1615
kusama-runtime = { workspace = true }
17-
kusama-runtime-constants = { workspace = true, default-features = true }
1816

1917
sc-chain-spec = { workspace = true }
20-
runtime-parachains = { default-features = true, workspace = true }
21-
polkadot-primitives = { workspace = true, default-features = true }
22-
babe-primitives = { workspace = true, default-features = true }
23-
authority-discovery-primitives = { workspace = true, default-features = true }
24-
sp-core = { workspace = true, default-features = true }
25-
pallet-staking = { workspace = true, default-features = true }
26-
grandpa = { workspace = true }
27-
sp-runtime = { workspace = true, default-features = true }
28-
beefy-primitives = { workspace = true, default-features = true }
29-
xcm = { workspace = true, default-features = true }
30-
parachains-common = { workspace = true, default-features = true }
31-
cumulus-primitives-core = { workspace = true, default-features = true }
3218

3319
asset-hub-polkadot-runtime = { workspace = true }
3420
asset-hub-kusama-runtime = { workspace = true }
@@ -50,17 +36,10 @@ runtime-benchmarks = [
5036
"bridge-hub-polkadot-runtime/runtime-benchmarks",
5137
"collectives-polkadot-runtime/runtime-benchmarks",
5238
"coretime-kusama-runtime/runtime-benchmarks",
53-
"cumulus-primitives-core/runtime-benchmarks",
5439
"encointer-kusama-runtime/runtime-benchmarks",
5540
"glutton-kusama-runtime/runtime-benchmarks",
5641
"kusama-runtime/runtime-benchmarks",
57-
"pallet-staking/runtime-benchmarks",
58-
"parachains-common/runtime-benchmarks",
5942
"people-kusama-runtime/runtime-benchmarks",
6043
"people-polkadot-runtime/runtime-benchmarks",
61-
"polkadot-primitives/runtime-benchmarks",
6244
"polkadot-runtime/runtime-benchmarks",
63-
"runtime-parachains/runtime-benchmarks",
64-
"sp-runtime/runtime-benchmarks",
65-
"encointer-kusama-runtime/runtime-benchmarks"
6645
]

chain-spec-generator/src/common.rs

+5-37
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,12 @@ use crate::{
1919
relay_chain_specs::{KusamaChainSpec, PolkadotChainSpec},
2020
system_parachains_specs::{
2121
AssetHubKusamaChainSpec, AssetHubPolkadotChainSpec, BridgeHubKusamaChainSpec,
22-
BridgeHubPolkadotChainSpec, CollectivesPolkadotChainSpec, EncointerKusamaChainSpec,
23-
GluttonKusamaChainSpec, PeopleKusamaChainSpec, PeoplePolkadotChainSpec,
22+
BridgeHubPolkadotChainSpec, CollectivesPolkadotChainSpec, CoretimeKusamaChainSpec,
23+
EncointerKusamaChainSpec, GluttonKusamaChainSpec, PeopleKusamaChainSpec,
24+
PeoplePolkadotChainSpec,
2425
},
2526
ChainSpec,
2627
};
27-
use polkadot_primitives::{AccountId, AccountPublic};
28-
use sp_core::{sr25519, Pair, Public};
29-
use sp_runtime::traits::IdentifyAccount;
30-
31-
pub fn testnet_accounts() -> Vec<AccountId> {
32-
vec![
33-
get_account_id_from_seed::<sr25519::Public>("Alice"),
34-
get_account_id_from_seed::<sr25519::Public>("Bob"),
35-
get_account_id_from_seed::<sr25519::Public>("Charlie"),
36-
get_account_id_from_seed::<sr25519::Public>("Dave"),
37-
get_account_id_from_seed::<sr25519::Public>("Eve"),
38-
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
39-
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
40-
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
41-
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
42-
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
43-
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
44-
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
45-
]
46-
}
47-
48-
/// Helper function to generate a crypto pair from seed
49-
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
50-
TPublic::Pair::from_string(&format!("//{}", seed), None)
51-
.expect("static values are valid; qed")
52-
.public()
53-
}
54-
55-
/// Helper function to generate an account ID from seed
56-
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
57-
where
58-
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
59-
{
60-
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
61-
}
6228

6329
#[derive(Debug, serde::Deserialize)]
6430
struct EmptyChainSpecWithId {
@@ -86,6 +52,8 @@ pub fn from_json_file(filepath: &str, supported: String) -> Result<Box<dyn Chain
8652
Ok(Box::new(BridgeHubPolkadotChainSpec::from_json_file(path)?)),
8753
x if x.starts_with("bridge-hub-kusama") =>
8854
Ok(Box::new(BridgeHubKusamaChainSpec::from_json_file(path)?)),
55+
x if x.starts_with("coretime-kusama") =>
56+
Ok(Box::new(CoretimeKusamaChainSpec::from_json_file(path)?)),
8957
x if x.starts_with("glutton-kusama") =>
9058
Ok(Box::new(GluttonKusamaChainSpec::from_json_file(path)?)),
9159
x if x.starts_with("encointer-kusama") =>

0 commit comments

Comments
 (0)