Skip to content

Commit

Permalink
BACKPORT-CONFLICT
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianbarbu authored and github-actions[bot] committed Dec 13, 2024
1 parent 981d6c0 commit c593bca
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 11 deletions.
65 changes: 65 additions & 0 deletions cumulus/polkadot-omni-node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Polkadot Omni Node

This is a white labeled implementation based on [`polkadot-omni-node-lib`](https://crates.io/crates/polkadot-omni-node-lib).
It can be used to start a parachain node from a provided chain spec file. It is only compatible with runtimes that use block
number `u32` and `Aura` consensus.

## Installation

Download & expose it via `PATH`:

```bash
# Download and set it on PATH.
wget https://github.com/paritytech/polkadot-sdk/releases/download/<stable_release_tag>/polkadot-omni-node
chmod +x polkadot-omni-node
export PATH="$PATH:`pwd`"
```

Compile & install via `cargo`:

```bash
# Assuming ~/.cargo/bin is on the PATH
cargo install polkadot-omni-node
```

## Usage

A basic example for an Omni Node run starts from a runtime which implements the [`sp_genesis_builder::GenesisBuilder`](https://docs.rs/sp-genesis-builder/latest/sp_genesis_builder/trait.GenesisBuilder.html).
The interface mandates the runtime to expose a [`named-preset`](https://docs.rs/staging-chain-spec-builder/latest/staging_chain_spec_builder/#generate-chain-spec-using-runtime-provided-genesis-config-preset).

### 1. Install chain-spec-builder

**Note**: `chain-spec-builder` binary is published on [`crates.io`](https://crates.io) under
[`staging-chain-spec-builder`](https://crates.io/crates/staging-chain-spec-builder) due to a name conflict.
Install it with `cargo` like bellow :

```bash
cargo install staging-chain-spec-builder
```

### 2. Generate a chain spec

Omni Node expects for the chain spec to contain parachains related fields like `relay_chain` and `para_id`.
These fields can be introduced by running [`staging-chain-spec-builder`](https://crates.io/crates/staging-chain-spec-builder)
with additional flags:

```bash
chain-spec-builder create --relay-chain <relay_chain_id> --para-id <id> -r <runtime.wasm> named-preset <preset_name>
```

### 3. Run Omni Node

And now with the generated chain spec we can start the node in development mode like so:

```bash
polkadot-omni-node --dev --chain <chain_spec.json>
```

## Useful links

* [`Omni Node Polkadot SDK Docs`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/omni_node/index.html)
* [`Chain Spec Genesis Reference Docs`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/chain_spec_genesis/index.html)
* [`polkadot-parachain-bin`](https://crates.io/crates/polkadot-parachain-bin)
* [`polkadot-sdk-parachain-template`](https://github.com/paritytech/polkadot-sdk-parachain-template)
* [`frame-omni-bencher`](https://crates.io/crates/frame-omni-bencher)
* [`staging-chain-spec-builder`](https://crates.io/crates/staging-chain-spec-builder)
16 changes: 16 additions & 0 deletions cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ pub struct Cli<Config: CliConfig> {
#[command(flatten)]
pub run: cumulus_client_cli::RunCmd,

<<<<<<< HEAD:cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs
=======
/// Start a dev node that produces a block each `dev_block_time` ms.
///
/// This is a dev option. It enables a manual sealing, meaning blocks are produced manually
/// rather than being part of an actual network consensus process. Using the option won't
/// result in starting or connecting to a parachain network. The resulting node will work on
/// its own, running the wasm blob and artificially producing a block each `dev_block_time` ms,
/// as if it was part of a parachain.
///
/// The `--dev` flag sets the `dev_block_time` to a default value of 3000ms unless explicitly
/// provided.
#[arg(long)]
pub dev_block_time: Option<u64>,

>>>>>>> 48c28d4c (omni-node: --dev sets manual seal and allows --chain to be set (#6646)):cumulus/polkadot-omni-node/lib/src/cli.rs
/// EXPERIMENTAL: Use slot-based collator which can handle elastic scaling.
///
/// Use with care, this flag is unstable and subject to change.
Expand Down
30 changes: 29 additions & 1 deletion cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunc
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use log::info;
use sc_cli::{Result, SubstrateCli};
use sc_cli::{CliConfiguration, Result, SubstrateCli};
use sp_runtime::traits::AccountIdConversion;
#[cfg(feature = "runtime-benchmarks")]
use sp_runtime::traits::HashingFor;
use std::panic::{RefUnwindSafe, UnwindSafe};

const DEFAULT_DEV_BLOCK_TIME_MS: u64 = 3000;

/// Structure that can be used in order to provide customizers for different functionalities of the
/// node binary that is being built using this library.
pub struct RunConfig {
Expand Down Expand Up @@ -216,6 +218,32 @@ pub fn run<CliConfig: crate::cli::CliConfig>(cmd_config: RunConfig) -> Result<()
let collator_options = cli.run.collator_options();

runner.run_node_until_exit(|config| async move {
<<<<<<< HEAD:cumulus/polkadot-parachain/polkadot-parachain-lib/src/command.rs
=======
let node_spec =
new_node_spec(&config, &cmd_config.runtime_resolver, &cli.node_extra_args())?;
let para_id = ParaId::from(
Extensions::try_get(&*config.chain_spec)
.map(|e| e.para_id)
.ok_or("Could not find parachain extension in chain-spec.")?,
);

if cli.run.base.is_dev()? {
// Set default dev block time to 3000ms if not set.
// TODO: take block time from AURA config if set.
let dev_block_time = cli.dev_block_time.unwrap_or(DEFAULT_DEV_BLOCK_TIME_MS);
return node_spec
.start_manual_seal_node(config, para_id, dev_block_time)
.map_err(Into::into);
}

if let Some(dev_block_time) = cli.dev_block_time {
return node_spec
.start_manual_seal_node(config, para_id, dev_block_time)
.map_err(Into::into);
}

>>>>>>> 48c28d4c (omni-node: --dev sets manual seal and allows --chain to be set (#6646)):cumulus/polkadot-omni-node/lib/src/command.rs
// If Statemint (Statemine, Westmint, Rockmine) DB exists and we're using the
// asset-hub chain spec, then rename the base path to the new chain ID. In the case
// that both file paths exist, the node will exit, as the user must decide (by
Expand Down
19 changes: 19 additions & 0 deletions prdoc/pr_6646.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: OmniNode --dev flag starts node with manual seal

doc:
- audience: [ Runtime Dev, Node Dev ]
description: |
`polkadot-omni-node` lib supports `--dev` flag now by allowing also to pass over a chain spec,
and starts the node with manual seal. It will seal the node at each `dev_block_time` milliseconds,
which can be set via `--dev-block-time`, and if not set will default to `3000ms`.

crates:
- name: sc-cli
bump: patch
- name: polkadot-omni-node-lib
bump: patch
- name: polkadot-omni-node
bump: patch
18 changes: 8 additions & 10 deletions substrate/client/cli/src/params/shared_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ pub struct SharedParams {

/// Specify the development chain.
///
/// This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`,
/// `--alice`, and `--tmp` flags, unless explicitly overridden.
/// It also disables local peer discovery (see --no-mdns and --discover-local)
#[arg(long, conflicts_with_all = &["chain"])]
/// This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`, `--alice`, and `--tmp`
/// flags, unless explicitly overridden. It also disables local peer discovery (see `--no-mdns`
/// and `--discover-local`). With this flag some nodes might start with manual seal, producing
/// blocks at certain events (e.g. `polkadot-omni-node`, which produces blocks at certain
/// intervals dictated by `--dev-block-time`).
#[arg(long)]
pub dev: bool,

/// Specify custom base path.
Expand Down Expand Up @@ -109,12 +111,8 @@ impl SharedParams {
pub fn chain_id(&self, is_dev: bool) -> String {
match self.chain {
Some(ref chain) => chain.clone(),
None =>
if is_dev {
"dev".into()
} else {
"".into()
},
None if is_dev => "dev".into(),
_ => "".into(),
}
}

Expand Down
93 changes: 93 additions & 0 deletions templates/minimal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,63 @@ packages required to compile this template - please take note of the Rust compil
cargo build --release
```

<<<<<<< HEAD
🐳 Alternatively, build the docker image:
=======
## Starting a Minimal Template Chain

### Omni Node

[Omni Node](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/omni_node/index.html) can
be used to run the minimal template's runtime. `polkadot-omni-node` binary crate usage is described at a high-level
[on crates.io](https://crates.io/crates/polkadot-omni-node).

#### Install `polkadot-omni-node`

Please see installation section on [crates.io/omni-node](https://crates.io/crates/polkadot-omni-node).

#### Build `minimal-template-runtime`

```sh
cargo build -p minimal-template-runtime --release
```

#### Install `staging-chain-spec-builder`

Please see the installation section at [`crates.io/staging-chain-spec-builder`](https://crates.io/crates/staging-chain-spec-builder).

#### Use chain-spec-builder to generate the chain_spec.json file

```sh
chain-spec-builder create --relay-chain "dev" --para-id 1000 --runtime \
target/release/wbuild/minimal-template-runtime/minimal_template_runtime.wasm named-preset development
```

**Note**: the `relay-chain` and `para-id` flags are extra bits of information required to
configure the node for the case of representing a parachain that is connected to a relay chain.
They are not relevant to minimal template business logic, but they are mandatory information for
Omni Node, nonetheless.

#### Run Omni Node

Start Omni Node in development mode (sets up block production and finalization based on manual seal,
sealing a new block every 3 seconds), with a minimal template runtime chain spec.

```sh
polkadot-omni-node --chain <path/to/chain_spec.json> --dev
```

### Minimal Template Node

#### Build both node & runtime

```sh
cargo build --workspace --release
```

🐳 Alternatively, build the docker image which builds all the workspace members,
and has as entry point the node binary:
>>>>>>> 48c28d4c (omni-node: --dev sets manual seal and allows --chain to be set (#6646))
```sh
docker build . -t polkadot-sdk-minimal-template
Expand All @@ -64,9 +120,46 @@ docker run --rm polkadot-sdk-minimal-template --dev

Development chains:

<<<<<<< HEAD
* 🧹 Do not persist the state.
* 💰 Are pre-configured with a genesis state that includes several pre-funded development accounts.
* 🧑‍⚖️ One development account (`ALICE`) is used as `sudo` accounts.
=======
#### Install `zombienet`

We can install `zombienet` as described [here](https://paritytech.github.io/zombienet/install.html#installation),
and `zombienet-omni-node.toml` contains the network specification we want to start.

#### Update `zombienet-omni-node.toml` with a valid chain spec path

Before starting the network with zombienet we must update the network specification
with a valid chain spec path. If we need to generate one, we can look up at the previous
section for chain spec creation [here](#use-chain-spec-builder-to-generate-the-chain_specjson-file).

Then make the changes in the network specification like so:

```toml
# ...
chain = "dev"
chain_spec_path = "<TO BE UPDATED WITH A VALID PATH>"
default_args = ["--dev"]
# ..
```

#### Start the network

```sh
zombienet --provider native spawn zombienet-omni-node.toml
```

### Zombienet with `minimal-template-node`

For this one we just need to have `zombienet` installed and run:

```sh
zombienet --provider native spawn zombienet-multi-node.toml
```
>>>>>>> 48c28d4c (omni-node: --dev sets manual seal and allows --chain to be set (#6646))
### Connect with the Polkadot-JS Apps Front-End

Expand Down
9 changes: 9 additions & 0 deletions templates/minimal/zombienet-omni-node.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[relaychain]
default_command = "polkadot-omni-node"
chain = "dev"
chain_spec_path = "<path/to/chain_spec.json>"
default_args = ["--dev"]

[[relaychain.nodes]]
name = "alice"
ws_port = 9944
Loading

0 comments on commit c593bca

Please sign in to comment.