Skip to content

Commit 152f444

Browse files
xlczjb0807
andauthored
update to use omni bencher (#2787)
* update to use omni bencher * update * update --------- Co-authored-by: zjb0807 <zjb0807@qq.com>
1 parent 70cc666 commit 152f444

File tree

12 files changed

+441
-21
lines changed

12 files changed

+441
-21
lines changed

.github/workflows/benchmark.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
if: ${{ github.event.issue.pull_request && contains(fromJson('["MEMBER", "OWNER"]'), github.event.comment.author_association) && startsWith(github.event.comment.body, '/bench ') }}
1212
runs-on: [self-hosted, linux]
1313
steps:
14-
- uses: actions/github-script@v6
14+
- uses: actions/github-script@v7
1515
name: Get PR branch
1616
id: issue
1717
with:
@@ -30,7 +30,7 @@ jobs:
3030
with:
3131
submodules: recursive
3232
ref: ${{ fromJson(steps.issue.outputs.result).sha }}
33-
- uses: actions/github-script@v6
33+
- uses: actions/github-script@v7
3434
name: Prepare command
3535
id: command
3636
with:
@@ -54,7 +54,7 @@ jobs:
5454
default:
5555
throw new Error('Invalid command')
5656
}
57-
- uses: actions/github-script@v6
57+
- uses: actions/github-script@v7
5858
name: Post comment
5959
id: comment
6060
with:
@@ -82,13 +82,15 @@ jobs:
8282
- name: Install toolchain
8383
uses: dtolnay/rust-toolchain@nightly
8484
- name: Install weight-gen
85-
run: cargo install --git https://github.com/open-web3-stack/wasm-bencher.git --bin weight-gen --force
85+
run: cargo install --git https://github.com/open-web3-stack/wasm-bencher.git --bin weight-gen
86+
- name: Install omni-bencher
87+
run: cargo install frame-omni-bencher
8688
- name: Setup cmake
8789
uses: jwlawson/actions-setup-cmake@v1.12
8890
- name: Use Node.js
8991
uses: actions/setup-node@v4
9092
with:
91-
node-version: 18.x
93+
node-version: 22.x
9294
- name: Run benchmarks
9395
run: ${{steps.command.outputs.result}} > ${{runner.temp}}/out.txt
9496
- name: Commit
@@ -98,7 +100,7 @@ jobs:
98100
git add .
99101
git commit -m '${{github.event.comment.body}}' --allow-empty
100102
git push origin HEAD:${{ fromJson(steps.issue.outputs.result).ref }}
101-
- uses: actions/github-script@v6
103+
- uses: actions/github-script@v7
102104
name: Update comment
103105
with:
104106
script: |

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,23 @@ endif
229229
ifeq ($(words $(pallet_folder)), 0)
230230
$(error pallet_folder not defined)
231231
endif
232-
cargo run $(options) --release --bin=acala --features=runtime-benchmarks --features=with-mandala-runtime -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=$(pallet) --extrinsic="*" --wasm-execution=compiled --heap-pages=4096 --output=./modules/$(pallet_folder)/src/weights.rs --template=./templates/module-weight-template.hbs
232+
cargo build $(options) --release --features=runtime-benchmarks,genesis-builder -p mandala-runtime
233+
frame-omni-bencher v1 benchmark pallet --runtime target/release/wbuild/mandala-runtime/mandala_runtime.compact.compressed.wasm --steps=50 --repeat=20 --pallet=$(pallet) --extrinsic="*" --heap-pages=4096 --output=./modules/$(pallet_folder)/src/weights.rs --template=./templates/module-weight-template.hbs
233234

234235
.PHONY: benchmark-mandala
235236
benchmark-mandala:
236-
cargo run $(options) --bin=acala --profile production --features=runtime-benchmarks --features=with-mandala-runtime -- benchmark pallet --chain=dev --steps=50 --repeat=20 '--pallet=$(or $(pallet),*)' '--extrinsic=*' --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/mandala/src/weights/
237+
cargo build $(options) --release --features=runtime-benchmarks,genesis-builder -p mandala-runtime
238+
frame-omni-bencher v1 benchmark pallet --runtime target/release/wbuild/mandala-runtime/mandala_runtime.compact.compressed.wasm --steps=50 --repeat=20 '--pallet=$(or $(pallet),*)' '--extrinsic=*' --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/mandala/src/weights/
237239

238240
.PHONY: benchmark-karura
239241
benchmark-karura:
240-
cargo run $(options) --bin=acala --profile production --features=runtime-benchmarks --features=with-karura-runtime -- benchmark pallet --chain=karura-dev --steps=50 --repeat=20 '--pallet=$(or $(pallet),*)' '--extrinsic=*' --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/karura/src/weights/
242+
cargo build $(options) --release --features=runtime-benchmarks,genesis-builder -p karura-runtime
243+
frame-omni-bencher v1 benchmark pallet --runtime target/release/wbuild/karura-runtime/karura_runtime.compact.compressed.wasm --steps=50 --repeat=20 '--pallet=$(or $(pallet),*)' '--extrinsic=*' --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/karura/src/weights/
241244

242245
.PHONY: benchmark-acala
243246
benchmark-acala:
244-
cargo run $(options) --bin=acala --profile production --features=runtime-benchmarks --features=with-acala-runtime -- benchmark pallet --chain=acala-dev --steps=50 --repeat=20 '--pallet=$(or $(pallet),*)' '--extrinsic=*' --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/acala/src/weights/
245-
246-
.PHONY: benchmark-machine
247-
benchmark-machine:
248-
cargo run --profile production --features=with-acala-runtime -- benchmark machine --chain=acala-dev
247+
cargo build $(options) --release --features=runtime-benchmarks,genesis-builder -p acala-runtime
248+
frame-omni-bencher v1 benchmark pallet --runtime target/release/wbuild/acala-runtime/acala_runtime.compact.compressed.wasm --steps=50 --repeat=20 '--pallet=$(or $(pallet),*)' '--extrinsic=*' --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/acala/src/weights/
249249

250250
.PHONY: clippy-fix
251251
clippy-fix:

runtime/acala/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ sp-consensus-aura = { workspace = true }
4848
sp-core = { workspace = true }
4949
sp-inherents = { workspace = true }
5050
sp-io = { workspace = true }
51+
sp-keyring = { workspace = true }
5152
sp-offchain = { workspace = true }
5253
sp-runtime = { workspace = true }
5354
sp-session = { workspace = true }
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// This file is part of Acala.
2+
3+
// Copyright (C) 2020-2025 Acala Foundation.
4+
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5+
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
19+
use crate::{
20+
AccountId, BalancesConfig, CollatorSelectionConfig, NativeTokenExistentialDeposit, ParachainInfoConfig,
21+
PolkadotXcmConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig, XCM_VERSION,
22+
};
23+
24+
use alloc::{vec, vec::Vec};
25+
26+
use cumulus_primitives_core::ParaId;
27+
use frame_support::build_struct_json_patch;
28+
use parachains_common::AuraId;
29+
use serde_json::Value;
30+
use sp_genesis_builder::PresetId;
31+
use sp_keyring::Sr25519Keyring;
32+
use xcm::prelude::XCM_VERSION;
33+
34+
/// The default XCM version to set in genesis config.
35+
const SAFE_XCM_VERSION: u32 = XCM_VERSION;
36+
/// Parachain id used for genesis config presets of parachain template.
37+
pub const PARACHAIN_ID: u32 = 2000;
38+
39+
/// Generate the session keys from individual elements.
40+
///
41+
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
42+
pub fn template_session_keys(keys: AuraId) -> SessionKeys {
43+
SessionKeys { aura: keys }
44+
}
45+
46+
fn testnet_genesis(
47+
invulnerables: Vec<(AccountId, AuraId)>,
48+
endowed_accounts: Vec<AccountId>,
49+
root: AccountId,
50+
id: ParaId,
51+
) -> Value {
52+
build_struct_json_patch!(RuntimeGenesisConfig {
53+
balances: BalancesConfig {
54+
balances: endowed_accounts
55+
.iter()
56+
.cloned()
57+
.map(|k| (k, 1u128 << 60))
58+
.collect::<Vec<_>>(),
59+
},
60+
parachain_info: ParachainInfoConfig { parachain_id: id },
61+
collator_selection: CollatorSelectionConfig {
62+
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
63+
candidacy_bond: NativeTokenExistentialDeposit::get() * 16,
64+
},
65+
session: SessionConfig {
66+
keys: invulnerables
67+
.into_iter()
68+
.map(|(acc, aura)| {
69+
(
70+
acc.clone(), // account id
71+
acc, // validator id
72+
template_session_keys(aura), // session keys
73+
)
74+
})
75+
.collect::<Vec<_>>(),
76+
},
77+
polkadot_xcm: PolkadotXcmConfig {
78+
safe_xcm_version: Some(SAFE_XCM_VERSION)
79+
},
80+
sudo: SudoConfig { key: Some(root) },
81+
})
82+
}
83+
84+
fn local_testnet_genesis() -> Value {
85+
testnet_genesis(
86+
// initial collators.
87+
vec![
88+
(
89+
Sr25519Keyring::Alice.to_account_id(),
90+
Sr25519Keyring::Alice.public().into(),
91+
),
92+
(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
93+
],
94+
Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
95+
Sr25519Keyring::Alice.to_account_id(),
96+
PARACHAIN_ID.into(),
97+
)
98+
}
99+
100+
fn development_config_genesis() -> Value {
101+
testnet_genesis(
102+
// initial collators.
103+
vec![
104+
(
105+
Sr25519Keyring::Alice.to_account_id(),
106+
Sr25519Keyring::Alice.public().into(),
107+
),
108+
(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
109+
],
110+
Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
111+
Sr25519Keyring::Alice.to_account_id(),
112+
PARACHAIN_ID.into(),
113+
)
114+
}
115+
116+
/// Provides the JSON representation of predefined genesis config for given `id`.
117+
pub fn get_preset(id: &PresetId) -> Option<vec::Vec<u8>> {
118+
let patch = match id.as_ref() {
119+
sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => local_testnet_genesis(),
120+
sp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(),
121+
_ => return None,
122+
};
123+
Some(
124+
serde_json::to_string(&patch)
125+
.expect("serialization to json is expected to work. qed.")
126+
.into_bytes(),
127+
)
128+
}
129+
130+
/// List of supported presets.
131+
pub fn preset_names() -> Vec<PresetId> {
132+
vec![
133+
PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
134+
PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
135+
]
136+
}

runtime/acala/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ use runtime_common::{
128128
mod authority;
129129
mod benchmarking;
130130
pub mod constants;
131+
#[cfg(feature = "genesis-builder")]
132+
mod genesis_config_presets;
131133
/// Weights for pallets used in the runtime.
132134
mod weights;
133135
pub mod xcm_config;
@@ -2559,11 +2561,11 @@ sp_api::impl_runtime_apis! {
25592561
}
25602562

25612563
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
2562-
frame_support::genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(id, |_| None)
2564+
frame_support::genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
25632565
}
25642566

25652567
fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
2566-
vec![]
2568+
genesis_config_presets::preset_names()
25672569
}
25682570
}
25692571
}

runtime/karura/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ sp-consensus-aura = { workspace = true }
4848
sp-core = { workspace = true }
4949
sp-inherents = { workspace = true }
5050
sp-io = { workspace = true }
51+
sp-keyring = { workspace = true }
5152
sp-offchain = { workspace = true }
5253
sp-runtime = { workspace = true }
5354
sp-session = { workspace = true }

0 commit comments

Comments
 (0)