Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 8 additions & 6 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
if: ${{ github.event.issue.pull_request && contains(fromJson('["MEMBER", "OWNER"]'), github.event.comment.author_association) && startsWith(github.event.comment.body, '/bench ') }}
runs-on: [self-hosted, linux]
steps:
- uses: actions/github-script@v6
- uses: actions/github-script@v7
name: Get PR branch
id: issue
with:
Expand All @@ -30,7 +30,7 @@ jobs:
with:
submodules: recursive
ref: ${{ fromJson(steps.issue.outputs.result).sha }}
- uses: actions/github-script@v6
- uses: actions/github-script@v7
name: Prepare command
id: command
with:
Expand All @@ -54,7 +54,7 @@ jobs:
default:
throw new Error('Invalid command')
}
- uses: actions/github-script@v6
- uses: actions/github-script@v7
name: Post comment
id: comment
with:
Expand Down Expand Up @@ -82,13 +82,15 @@ jobs:
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Install weight-gen
run: cargo install --git https://github.com/open-web3-stack/wasm-bencher.git --bin weight-gen --force
run: cargo install --git https://github.com/open-web3-stack/wasm-bencher.git --bin weight-gen
- name: Install omni-bencher
run: cargo install frame-omni-bencher
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.12
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 22.x
- name: Run benchmarks
run: ${{steps.command.outputs.result}} > ${{runner.temp}}/out.txt
- name: Commit
Expand All @@ -98,7 +100,7 @@ jobs:
git add .
git commit -m '${{github.event.comment.body}}' --allow-empty
git push origin HEAD:${{ fromJson(steps.issue.outputs.result).ref }}
- uses: actions/github-script@v6
- uses: actions/github-script@v7
name: Update comment
with:
script: |
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,23 @@ endif
ifeq ($(words $(pallet_folder)), 0)
$(error pallet_folder not defined)
endif
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
cargo build $(options) --release --features=runtime-benchmarks,genesis-builder -p mandala-runtime
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

.PHONY: benchmark-mandala
benchmark-mandala:
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/
cargo build $(options) --release --features=runtime-benchmarks,genesis-builder -p mandala-runtime
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/

.PHONY: benchmark-karura
benchmark-karura:
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/
cargo build $(options) --release --features=runtime-benchmarks,genesis-builder -p karura-runtime
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/

.PHONY: benchmark-acala
benchmark-acala:
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/

.PHONY: benchmark-machine
benchmark-machine:
cargo run --profile production --features=with-acala-runtime -- benchmark machine --chain=acala-dev
cargo build $(options) --release --features=runtime-benchmarks,genesis-builder -p acala-runtime
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/

.PHONY: clippy-fix
clippy-fix:
Expand Down
1 change: 1 addition & 0 deletions runtime/acala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sp-consensus-aura = { workspace = true }
sp-core = { workspace = true }
sp-inherents = { workspace = true }
sp-io = { workspace = true }
sp-keyring = { workspace = true }
sp-offchain = { workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }
Expand Down
136 changes: 136 additions & 0 deletions runtime/acala/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// This file is part of Acala.

// Copyright (C) 2020-2025 Acala Foundation.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program 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.

// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
AccountId, BalancesConfig, CollatorSelectionConfig, NativeTokenExistentialDeposit, ParachainInfoConfig,
PolkadotXcmConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig, XCM_VERSION,
};

use alloc::{vec, vec::Vec};

use cumulus_primitives_core::ParaId;
use frame_support::build_struct_json_patch;
use parachains_common::AuraId;
use serde_json::Value;
use sp_genesis_builder::PresetId;
use sp_keyring::Sr25519Keyring;
use xcm::prelude::XCM_VERSION;

/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = XCM_VERSION;
/// Parachain id used for genesis config presets of parachain template.
pub const PARACHAIN_ID: u32 = 2000;

/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
pub fn template_session_keys(keys: AuraId) -> SessionKeys {
SessionKeys { aura: keys }
}

fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
root: AccountId,
id: ParaId,
) -> Value {
build_struct_json_patch!(RuntimeGenesisConfig {
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1u128 << 60))
.collect::<Vec<_>>(),
},
parachain_info: ParachainInfoConfig { parachain_id: id },
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(),
candidacy_bond: NativeTokenExistentialDeposit::get() * 16,
},
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
template_session_keys(aura), // session keys
)
})
.collect::<Vec<_>>(),
},
polkadot_xcm: PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION)
},
sudo: SudoConfig { key: Some(root) },
})
}

fn local_testnet_genesis() -> Value {
testnet_genesis(
// initial collators.
vec![
(
Sr25519Keyring::Alice.to_account_id(),
Sr25519Keyring::Alice.public().into(),
),
(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
],
Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
Sr25519Keyring::Alice.to_account_id(),
PARACHAIN_ID.into(),
)
}

fn development_config_genesis() -> Value {
testnet_genesis(
// initial collators.
vec![
(
Sr25519Keyring::Alice.to_account_id(),
Sr25519Keyring::Alice.public().into(),
),
(Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()),
],
Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(),
Sr25519Keyring::Alice.to_account_id(),
PARACHAIN_ID.into(),
)
}

/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &PresetId) -> Option<vec::Vec<u8>> {
let patch = match id.as_ref() {
sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => local_testnet_genesis(),
sp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(),
_ => return None,
};
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}

/// 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),
]
}
6 changes: 4 additions & 2 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ use runtime_common::{
mod authority;
mod benchmarking;
pub mod constants;
#[cfg(feature = "genesis-builder")]
mod genesis_config_presets;
/// Weights for pallets used in the runtime.
mod weights;
pub mod xcm_config;
Expand Down Expand Up @@ -2559,11 +2561,11 @@ sp_api::impl_runtime_apis! {
}

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

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![]
genesis_config_presets::preset_names()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions runtime/karura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sp-consensus-aura = { workspace = true }
sp-core = { workspace = true }
sp-inherents = { workspace = true }
sp-io = { workspace = true }
sp-keyring = { workspace = true }
sp-offchain = { workspace = true }
sp-runtime = { workspace = true }
sp-session = { workspace = true }
Expand Down
Loading