Skip to content

Commit

Permalink
omni-node: --dev sets manual seal and allows --chain to be set (#6646)
Browse files Browse the repository at this point in the history
# Description

This PR changes a few things:
* `--dev` flag will not conflict with `--chain` anymore, but if
`--chain` is not given will set `--chain=dev`.
* `--dev-block-time` is optional and it defaults to 3000ms if not set
after setting `--dev`.
* to start OmniNode with manual seal it is enough to pass just `--dev`.
* `--dev-block-time` can still be used to start a node with manual seal,
but it will not set it up as `--dev` does (it will not set a bunch of
flags which are enabled by default when `--dev` is set: e.g. `--tmp`,
`--alice` and `--force-authoring`.

Closes: #6537

## Integration

Relevant for node/runtime developers that use OmniNode lib, including
`polkadot-omni-node` binary, although the recommended way for runtime
development is to use `chopsticks`.

## Review Notes

* Decided to focus only on OmniNode & templates docs in relation to it,
and leave the `parachain-template-node` as is (meaning `--dev` isn't
usable and testing a runtime with the `parachain-template-node` still
needs a relay chain here). I am doing this because I think we want
either way to phase out `parachain-template-node` and adding manual seal
support for it is wasted effort. We might add support though if the
demand is for `parachain-template-node`.
* Decided to not infer the block time based on AURA config yet because
there is still the option of setting a specific block time by using
`--dev-block-time`. Also, would want first to align & merge on runtime
metadata checks we added in Omni Node here:
#6450 before starting to
infer AURA config slot duration via the same way.

- [x] update the docs to mention `--dev` now.
- [x] mention about chopsticks in the context of runtime development

---------

Signed-off-by: Iulian Barbu <[email protected]>
Co-authored-by: Michal Kucharczyk <[email protected]>
(cherry picked from commit 48c28d4)
  • Loading branch information
iulianbarbu authored and github-actions[bot] committed Dec 13, 2024
1 parent 51f578a commit b12ca0f
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 28 deletions.
4 changes: 2 additions & 2 deletions cumulus/polkadot-omni-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ chain-spec-builder create --relay-chain <relay_chain_id> --para-id <id> -r <runt

### 3. Run Omni Node

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

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

## Useful links
Expand Down
11 changes: 8 additions & 3 deletions cumulus/polkadot-omni-node/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ pub struct Cli<Config: CliConfig> {

/// Start a dev node that produces a block each `dev_block_time` ms.
///
/// This is a dev option, and it 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.
/// 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>,

Expand Down
15 changes: 13 additions & 2 deletions cumulus/polkadot-omni-node/lib/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ 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;

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 @@ -230,10 +232,19 @@ pub fn run<CliConfig: crate::cli::CliConfig>(cmd_config: RunConfig) -> Result<()
.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)
.map_err(Into::into);
}

// If Statemint (Statemine, Westmint, Rockmine) DB exists and we're using the
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
9 changes: 4 additions & 5 deletions templates/minimal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ Omni Node, nonetheless.

#### Run Omni Node

Start Omni Node with manual seal (3 seconds block times), minimal template runtime based
chain spec. We'll use `--tmp` flag to start the node with its configurations stored in a
temporary directory, which will be deleted at the end of the process.
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-block-time 3000 --tmp
polkadot-omni-node --chain <path/to/chain_spec.json> --dev
```

### Minimal Template Node
Expand Down Expand Up @@ -160,7 +159,7 @@ Then make the changes in the network specification like so:
# ...
chain = "dev"
chain_spec_path = "<TO BE UPDATED WITH A VALID PATH>"
default_args = ["--dev-block-time 3000"]
default_args = ["--dev"]
# ..
```

Expand Down
2 changes: 1 addition & 1 deletion templates/minimal/zombienet-omni-node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
default_command = "polkadot-omni-node"
chain = "dev"
chain_spec_path = "<path/to/chain_spec.json>"
default_args = ["--dev-block-time 3000"]
default_args = ["--dev"]

[[relaychain.nodes]]
name = "alice"
Expand Down
40 changes: 35 additions & 5 deletions templates/parachain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [Connect with the Polkadot-JS Apps Front-End](#connect-with-the-polkadot-js-apps-front-end)
- [Takeaways](#takeaways)

- [Runtime development](#runtime-development)
- [Contributing](#contributing)
- [Getting Help](#getting-help)

Expand Down Expand Up @@ -107,13 +108,11 @@ with the relay chain ID where this instantiation of parachain-template will conn

#### Run Omni Node

Start Omni Node with the generated chain spec. We'll start it development mode (without a relay chain config),
with a temporary directory for configuration (given `--tmp`), and block production set to create a block with
every second.
Start Omni Node with the generated chain spec. We'll start it in development mode (without a relay chain config), producing
and finalizing blocks based on manual seal, configured below to seal a block with each second.

```bash
polkadot-omni-node --chain <path/to/chain_spec.json> --tmp --dev-block-time 1000

polkadot-omni-node --chain <path/to/chain_spec.json> --dev --dev-block-time 1000
```

However, such a setup is not close to what would run in production, and for that we need to setup a local
Expand Down Expand Up @@ -197,6 +196,37 @@ Development parachains:
- 💰 Are preconfigured with a genesis state that includes several prefunded development accounts.
- 🧑‍⚖️ Development accounts are used as validators, collators, and `sudo` accounts.

## Runtime development

We recommend using [`chopsticks`](https://github.com/AcalaNetwork/chopsticks) when the focus is more on the runtime
development and `OmniNode` is enough as is.

### Install chopsticks

To use `chopsticks`, please install the latest version according to the installation [guide](https://github.com/AcalaNetwork/chopsticks?tab=readme-ov-file#install).

### Build a raw chain spec

Build the `parachain-template-runtime` as mentioned before in this guide and use `chain-spec-builder`
again but this time by passing `--raw-storage` flag:

```sh
chain-spec-builder create --raw-storage --relay-chain "rococo-local" --para-id 1000 --runtime \
target/release/wbuild/parachain-template-runtime/parachain_template_runtime.wasm named-preset development
```

### Start `chopsticks` with the chain spec

```sh
npx @acala-network/chopsticks@latest --chain-spec <path/to/chain_spec.json>
```

### Alternatives

`OmniNode` can be still used for runtime development if using the `--dev` flag, while `parachain-template-node` doesn't
support it at this moment. It can still be used to test a runtime in a full setup where it is started alongside a
relay chain network (see [Parachain Template node](#parachain-template-node) setup).

## Contributing

- 🔄 This template is automatically updated after releases in the main [Polkadot SDK monorepo](https://github.com/paritytech/polkadot-sdk).
Expand Down

0 comments on commit b12ca0f

Please sign in to comment.