Skip to content

Commit ba9b9e5

Browse files
[stable2412] Backport #6646 (#6870)
Backport #6646 into `stable2412` from iulianbarbu. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: Iulian Barbu <[email protected]>
1 parent 51f578a commit ba9b9e5

File tree

8 files changed

+90
-28
lines changed

8 files changed

+90
-28
lines changed

cumulus/polkadot-omni-node/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ chain-spec-builder create --relay-chain <relay_chain_id> --para-id <id> -r <runt
4949

5050
### 3. Run Omni Node
5151

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

5454
```bash
55-
polkadot-omni-node --chain <chain_spec.json>
55+
polkadot-omni-node --dev --chain <chain_spec.json>
5656
```
5757

5858
## Useful links

cumulus/polkadot-omni-node/lib/src/cli.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,14 @@ pub struct Cli<Config: CliConfig> {
126126

127127
/// Start a dev node that produces a block each `dev_block_time` ms.
128128
///
129-
/// This is a dev option, and it won't result in starting or connecting to a parachain network.
130-
/// The resulting node will work on its own, running the wasm blob and artificially producing
131-
/// a block each `dev_block_time` ms, as if it was part of a parachain.
129+
/// This is a dev option. It enables a manual sealing, meaning blocks are produced manually
130+
/// rather than being part of an actual network consensus process. Using the option won't
131+
/// result in starting or connecting to a parachain network. The resulting node will work on
132+
/// its own, running the wasm blob and artificially producing a block each `dev_block_time` ms,
133+
/// as if it was part of a parachain.
134+
///
135+
/// The `--dev` flag sets the `dev_block_time` to a default value of 3000ms unless explicitly
136+
/// provided.
132137
#[arg(long)]
133138
pub dev_block_time: Option<u64>,
134139

cumulus/polkadot-omni-node/lib/src/command.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunc
3434
use cumulus_primitives_core::ParaId;
3535
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
3636
use log::info;
37-
use sc_cli::{Result, SubstrateCli};
37+
use sc_cli::{CliConfiguration, Result, SubstrateCli};
3838
use sp_runtime::traits::AccountIdConversion;
3939
#[cfg(feature = "runtime-benchmarks")]
4040
use sp_runtime::traits::HashingFor;
4141

42+
const DEFAULT_DEV_BLOCK_TIME_MS: u64 = 3000;
43+
4244
/// Structure that can be used in order to provide customizers for different functionalities of the
4345
/// node binary that is being built using this library.
4446
pub struct RunConfig {
@@ -230,10 +232,19 @@ pub fn run<CliConfig: crate::cli::CliConfig>(cmd_config: RunConfig) -> Result<()
230232
.ok_or("Could not find parachain extension in chain-spec.")?,
231233
);
232234

235+
if cli.run.base.is_dev()? {
236+
// Set default dev block time to 3000ms if not set.
237+
// TODO: take block time from AURA config if set.
238+
let dev_block_time = cli.dev_block_time.unwrap_or(DEFAULT_DEV_BLOCK_TIME_MS);
239+
return node_spec
240+
.start_manual_seal_node(config, para_id, dev_block_time)
241+
.map_err(Into::into);
242+
}
243+
233244
if let Some(dev_block_time) = cli.dev_block_time {
234245
return node_spec
235246
.start_manual_seal_node(config, para_id, dev_block_time)
236-
.map_err(Into::into)
247+
.map_err(Into::into);
237248
}
238249

239250
// If Statemint (Statemine, Westmint, Rockmine) DB exists and we're using the

prdoc/pr_6646.prdoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: OmniNode --dev flag starts node with manual seal
5+
6+
doc:
7+
- audience: [ Runtime Dev, Node Dev ]
8+
description: |
9+
`polkadot-omni-node` lib supports `--dev` flag now by allowing also to pass over a chain spec,
10+
and starts the node with manual seal. It will seal the node at each `dev_block_time` milliseconds,
11+
which can be set via `--dev-block-time`, and if not set will default to `3000ms`.
12+
13+
crates:
14+
- name: sc-cli
15+
bump: patch
16+
- name: polkadot-omni-node-lib
17+
bump: patch
18+
- name: polkadot-omni-node
19+
bump: patch

substrate/client/cli/src/params/shared_params.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ pub struct SharedParams {
3333

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

4244
/// Specify custom base path.
@@ -109,12 +111,8 @@ impl SharedParams {
109111
pub fn chain_id(&self, is_dev: bool) -> String {
110112
match self.chain {
111113
Some(ref chain) => chain.clone(),
112-
None =>
113-
if is_dev {
114-
"dev".into()
115-
} else {
116-
"".into()
117-
},
114+
None if is_dev => "dev".into(),
115+
_ => "".into(),
118116
}
119117
}
120118

templates/minimal/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ Omni Node, nonetheless.
105105

106106
#### Run Omni Node
107107

108-
Start Omni Node with manual seal (3 seconds block times), minimal template runtime based
109-
chain spec. We'll use `--tmp` flag to start the node with its configurations stored in a
110-
temporary directory, which will be deleted at the end of the process.
108+
Start Omni Node in development mode (sets up block production and finalization based on manual seal,
109+
sealing a new block every 3 seconds), with a minimal template runtime chain spec.
111110

112111
```sh
113-
polkadot-omni-node --chain <path/to/chain_spec.json> --dev-block-time 3000 --tmp
112+
polkadot-omni-node --chain <path/to/chain_spec.json> --dev
114113
```
115114

116115
### Minimal Template Node
@@ -160,7 +159,7 @@ Then make the changes in the network specification like so:
160159
# ...
161160
chain = "dev"
162161
chain_spec_path = "<TO BE UPDATED WITH A VALID PATH>"
163-
default_args = ["--dev-block-time 3000"]
162+
default_args = ["--dev"]
164163
# ..
165164
```
166165

templates/minimal/zombienet-omni-node.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
default_command = "polkadot-omni-node"
33
chain = "dev"
44
chain_spec_path = "<path/to/chain_spec.json>"
5-
default_args = ["--dev-block-time 3000"]
5+
default_args = ["--dev"]
66

77
[[relaychain.nodes]]
88
name = "alice"

templates/parachain/README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [Connect with the Polkadot-JS Apps Front-End](#connect-with-the-polkadot-js-apps-front-end)
2828
- [Takeaways](#takeaways)
2929

30+
- [Runtime development](#runtime-development)
3031
- [Contributing](#contributing)
3132
- [Getting Help](#getting-help)
3233

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

108109
#### Run Omni Node
109110

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

114114
```bash
115-
polkadot-omni-node --chain <path/to/chain_spec.json> --tmp --dev-block-time 1000
116-
115+
polkadot-omni-node --chain <path/to/chain_spec.json> --dev --dev-block-time 1000
117116
```
118117

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

199+
## Runtime development
200+
201+
We recommend using [`chopsticks`](https://github.com/AcalaNetwork/chopsticks) when the focus is more on the runtime
202+
development and `OmniNode` is enough as is.
203+
204+
### Install chopsticks
205+
206+
To use `chopsticks`, please install the latest version according to the installation [guide](https://github.com/AcalaNetwork/chopsticks?tab=readme-ov-file#install).
207+
208+
### Build a raw chain spec
209+
210+
Build the `parachain-template-runtime` as mentioned before in this guide and use `chain-spec-builder`
211+
again but this time by passing `--raw-storage` flag:
212+
213+
```sh
214+
chain-spec-builder create --raw-storage --relay-chain "rococo-local" --para-id 1000 --runtime \
215+
target/release/wbuild/parachain-template-runtime/parachain_template_runtime.wasm named-preset development
216+
```
217+
218+
### Start `chopsticks` with the chain spec
219+
220+
```sh
221+
npx @acala-network/chopsticks@latest --chain-spec <path/to/chain_spec.json>
222+
```
223+
224+
### Alternatives
225+
226+
`OmniNode` can be still used for runtime development if using the `--dev` flag, while `parachain-template-node` doesn't
227+
support it at this moment. It can still be used to test a runtime in a full setup where it is started alongside a
228+
relay chain network (see [Parachain Template node](#parachain-template-node) setup).
229+
200230
## Contributing
201231

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

0 commit comments

Comments
 (0)