Skip to content

Commit ccdc46d

Browse files
authored
feat: build spec runtime (#647)
* feat(cli): allow build spec command to be non-interactive * feat(cli): allow build spec command to specify the base directory * fix(cli): lifecycle test * test(cli): display error in conflictive test * refactor: specify default locations at core logic * test(cli): avoid hanging node process * fix(cli): compilation issues * ci: exclude integration tests from coverage * test(cli): run coverage with nextest * fix(cli): path canonicalization * refactor(cli): simplify functions * feat: adapt the build-spec command to use the runtime * refactor(common): do not add unnecessary log entries * fix: import errors * fix: required chainspec parameters * fix(cli): relay_chain field in raw chain specs * test(chains): address some chainspec-related errors * refactor(cli): do not use full path but alias * feat(cli): use canonical path and display them as info * fix(cli): use the correct node binary path * fix: documentation tests * feat(cli): allow to generate spec with node/runtime features * refactor: clippy issues * fix: compilation issues * fix(cli): do not make features mandatory * feat(cli): allow to skip the build * fix: clippy issues * fix: doc tests * test(chain): add tests for ChainSpecBuilder * feat(cli): get to choose the runtime preset to build * fix(cli): correctly generate the raw chainspec if using runtime * chore: add extra message for fetching presets * fix: test for para id replacement * fix: clippy issuefix: clippy issues * fix: misssing import * fix: documentation * fix: correct fallback version of polkadot-omni-node * fix: add tag pattern to polkadot-omni-node * feat: reuse an existing spiner when fetching binaries * fix: compilation issue * test: add tests for the new build-spec command * fix(cli): correctly set the default runtime location * fix: some tests * fix: release version ordering * fix(cli): remove unused dependency * refactor(chains): update build-spec documentation
1 parent 38c0fc0 commit ccdc46d

Some content is hidden

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

56 files changed

+1844
-570
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ srtool-lib = { version = "0.13.2", default-features = false }
7777
zombienet-configuration = { version = "0.3.1", default-features = false }
7878
zombienet-sdk = { version = "0.3.1", default-features = false }
7979
git2_credentials = "0.13.0"
80+
cumulus-client-cli = { version = "0.22.0", default-features = false }
8081

8182
# benchmarking
8283
cumulus-primitives-proof-size-hostfunction = "0.12.0"

crates/pop-chains/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ srtool-lib.workspace = true
3333
symlink.workspace = true
3434
toml_edit.workspace = true
3535
walkdir.workspace = true
36+
cumulus-client-cli.workspace = true
37+
3638
# Zombienet
3739
zombienet-configuration.workspace = true
3840
zombienet-sdk.workspace = true

crates/pop-chains/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,34 @@ Build a chain:
2525

2626
```rust,no_run
2727
use pop_common::Profile;
28-
use pop_chains::build_chain;
28+
use pop_chains::ChainSpecBuilder;
2929
use std::path::Path;
3030
3131
let path = Path::new("./");
32-
let package = None; // The optional package to be built.
33-
let binary_path = build_chain(&path, package, &Profile::Release, None, vec![]).unwrap();
32+
let builder = ChainSpecBuilder::Node { node_path: path.join("node"), default_bootnode: false, profile: Profile::Release };
33+
let binary_path = builder.build(&[]).unwrap();
3434
```
3535

3636
Build a chain with `runtime-benchmarks` feature:
3737

3838
```rs
39-
let binary_path = build_chain(&path, package, &Profile::Release, None, vec!["runtime-benchmarks"]).unwrap();
39+
let binary_path = builder.build(&["runtime-benchmarks".to_string()]).unwrap();
4040
```
4141

4242
Generate a plain chain specification file and customize it with your specific chain values:
4343

4444
```rust,no_run
4545
use pop_common::Profile;
46-
use pop_chains::{build_chain, export_wasm_file, generate_plain_chain_spec, generate_raw_chain_spec, generate_genesis_state_file, ChainSpec};
46+
use pop_chains::{ChainSpecBuilder, ChainSpec};
4747
use std::path::Path;
4848
4949
let path = Path::new("./"); // Location of the parachain project.
50-
let package = None; // The optional package to be built.
51-
// The path to the node binary executable.
52-
let binary_path = build_chain(&path, package, &Profile::Release, None, vec![]).unwrap();;
50+
let builder = ChainSpecBuilder::Node { node_path: path.join("node"), default_bootnode: false, profile: Profile::Release };
51+
// Build the node binary first
52+
builder.build(&[]).unwrap();
5353
// Generate a plain chain specification file of a parachain
5454
let plain_chain_spec_path = path.join("plain-parachain-chainspec.json");
55-
generate_plain_chain_spec(&binary_path, &plain_chain_spec_path, true, "dev");
55+
builder.generate_plain_chain_spec("dev", &plain_chain_spec_path).unwrap();
5656
// Customize your chain specification
5757
let mut chain_spec = ChainSpec::from(&plain_chain_spec_path).unwrap();
5858
chain_spec.replace_para_id(2002);
@@ -67,22 +67,22 @@ Generate a raw chain specification file and export the WASM and genesis state fi
6767

6868
```rust,no_run
6969
use pop_common::Profile;
70-
use pop_chains::{build_chain, export_wasm_file, generate_plain_chain_spec, generate_raw_chain_spec, generate_genesis_state_file};
70+
use pop_chains::{ChainSpecBuilder, generate_genesis_state_file_with_node};
7171
use std::path::Path;
7272
7373
let path = Path::new("./"); // Location of the parachain project.
74-
let package = None; // The optional package to be built.
75-
// The path to the node binary executable.
76-
let binary_path = build_chain(&path, package, &Profile::Release, None, vec![]).unwrap();;
74+
let builder = ChainSpecBuilder::Node { node_path: path.join("node"), default_bootnode: false, profile: Profile::Release };
75+
// Build the node binary first
76+
let binary_path = builder.build(&[]).unwrap();
7777
// Generate a plain chain specification file of a parachain
7878
let plain_chain_spec_path = path.join("plain-parachain-chainspec.json");
79-
generate_plain_chain_spec(&binary_path, &plain_chain_spec_path, true, "dev");
79+
builder.generate_plain_chain_spec("dev", &plain_chain_spec_path).unwrap();
8080
// Generate a raw chain specification file of a parachain
81-
let chain_spec = generate_raw_chain_spec(&binary_path, &plain_chain_spec_path, "raw-parachain-chainspec.json").unwrap();
81+
let chain_spec = builder.generate_raw_chain_spec(&plain_chain_spec_path, "raw-parachain-chainspec.json").unwrap();
8282
// Export the WebAssembly runtime for the parachain.
83-
let wasm_file = export_wasm_file(&binary_path, &chain_spec, "para-2000-wasm").unwrap();
83+
let wasm_file = builder.export_wasm_file(&chain_spec, "para-2000-wasm").unwrap();
8484
// Generate the parachain genesis state.
85-
let genesis_state_file = generate_genesis_state_file(&binary_path, &chain_spec, "para-2000-genesis-state").unwrap();
85+
let genesis_state_file = generate_genesis_state_file_with_node(&binary_path, &chain_spec, "para-2000-genesis-state").unwrap();
8686
```
8787

8888
Run a chain:

crates/pop-chains/src/bench/mod.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
// SPDX-License-Identifier: GPL-3.0
22

3-
use crate::Error;
3+
use crate::{Error, utils::helpers::HostFunctions};
44
use clap::Parser;
55
use duct::cmd;
66
use frame_benchmarking_cli::PalletCmd;
77
pub use frame_benchmarking_cli::{BlockCmd, MachineCmd, OverheadCmd, StorageCmd};
8-
use sc_chain_spec::GenesisConfigBuilderRuntimeCaller;
98
use serde::{Deserialize, Serialize};
109
use sp_runtime::traits::BlakeTwo256;
1110
use std::{
1211
collections::BTreeMap,
1312
fmt::Display,
14-
fs,
1513
io::Read,
1614
path::{Path, PathBuf},
1715
};
@@ -27,11 +25,6 @@ pub mod binary;
2725
/// (Recommended for testing with a single node, e.g., for benchmarking)
2826
pub const GENESIS_BUILDER_DEV_PRESET: &str = "development";
2927

30-
type HostFunctions = (
31-
sp_statement_store::runtime_api::HostFunctions,
32-
cumulus_primitives_proof_size_hostfunction::storage_proof_size::HostFunctions,
33-
);
34-
3528
/// Type alias for records where the key is the pallet name and the value is an array of its
3629
/// extrinsics.
3730
pub type PalletExtrinsicsRegistry = BTreeMap<String, Vec<String>>;
@@ -106,18 +99,6 @@ impl TryFrom<String> for GenesisBuilderPolicy {
10699
}
107100
}
108101

109-
/// Get genesis builder preset names of the runtime.
110-
///
111-
/// # Arguments
112-
/// * `binary_path` - Path to the runtime binary.
113-
pub fn get_preset_names(binary_path: &PathBuf) -> Result<Vec<String>, Error> {
114-
let binary = fs::read(binary_path)?;
115-
let genesis_config_builder = GenesisConfigBuilderRuntimeCaller::<HostFunctions>::new(&binary);
116-
genesis_config_builder
117-
.preset_names()
118-
.map_err(|e| Error::GenesisBuilderError(e.to_string()))
119-
}
120-
121102
/// Get the runtime folder path and throws error if it does not exist.
122103
///
123104
/// # Arguments
@@ -263,6 +244,7 @@ pub fn generate_omni_bencher_benchmarks(
263244
mod tests {
264245
use super::*;
265246
use binary::omni_bencher_generator;
247+
use std::fs;
266248
use tempfile::tempdir;
267249

268250
#[test]

0 commit comments

Comments
 (0)