Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

omni-node: --dev sets manual seal and allows --chain to be set #6646

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9eab6a1
omni-node: --dev starts manual seal and allows --chain to be set
iulianbarbu Nov 25, 2024
e321830
comments fixes
iulianbarbu Nov 26, 2024
922285c
fix comments
iulianbarbu Nov 26, 2024
c5838ce
add prdoc
iulianbarbu Nov 26, 2024
61fda5c
Merge branch 'master' into ib-dev-flag-with-manual-seal
iulianbarbu Nov 26, 2024
8b923a8
fix prdoc
iulianbarbu Nov 26, 2024
3e96f98
add docs and fix clippy
iulianbarbu Nov 26, 2024
dbb1d1e
fix doc test
iulianbarbu Nov 26, 2024
6f9e5e8
prdoc fix
iulianbarbu Nov 26, 2024
ff46e59
Merge branch 'master' into ib-dev-flag-with-manual-seal
iulianbarbu Nov 26, 2024
897ea81
a few more docs
iulianbarbu Nov 27, 2024
f913cec
add choptsticks guide
iulianbarbu Nov 27, 2024
8813409
Merge branch 'master' into ib-dev-flag-with-manual-seal
iulianbarbu Nov 27, 2024
f696909
no need to use allow-unresolved-imports
iulianbarbu Nov 27, 2024
06bbd5e
remake dev-block-time standalone
iulianbarbu Nov 27, 2024
d6faae7
polish public docs
iulianbarbu Nov 28, 2024
7210dc9
Update cumulus/polkadot-omni-node/lib/src/cli.rs
iulianbarbu Nov 28, 2024
1833acd
fix fmt
iulianbarbu Nov 28, 2024
d8395bb
Merge branch 'master' into ib-dev-flag-with-manual-seal
iulianbarbu Nov 29, 2024
405485a
test-stable without cache
iulianbarbu Nov 29, 2024
5d32b16
revert MinimumPeriod
iulianbarbu Nov 30, 2024
4729516
fix clippy
iulianbarbu Dec 1, 2024
81bd3eb
Revert "test-stable without cache"
iulianbarbu Dec 1, 2024
14cbdb4
Merge branch 'master' into ib-dev-flag-with-manual-seal
iulianbarbu Dec 5, 2024
c8c1bd2
Merge branch 'master' into ib-dev-flag-with-manual-seal
iulianbarbu Dec 5, 2024
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
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
3 changes: 2 additions & 1 deletion cumulus/polkadot-omni-node/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ pub struct Cli<Config: CliConfig> {
///
/// 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.
/// a block each `dev_block_time` ms, as if it was part of a parachain. Defaults to 3000ms if
/// not set and `--dev` is used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more explicit here about enabling manual sealing and fact that --dev enables this.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used your phrasing here: d6faae7

#[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
16 changes: 6 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,10 @@ 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`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention manual seal here? (I know it does not enable it for every node, but I think it would be good to have this information in cli).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note here: d6faae7.

#[arg(long)]
pub dev: bool,

/// Specify custom base path.
Expand Down Expand Up @@ -109,12 +109,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
5 changes: 3 additions & 2 deletions templates/parachain/runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ use super::{
MessageQueue, Nonce, PalletInfo, ParachainSystem, Runtime, RuntimeCall, RuntimeEvent,
RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Session, SessionKeys,
System, WeightToFee, XcmpQueue, AVERAGE_ON_INITIALIZE_RATIO, EXISTENTIAL_DEPOSIT, HOURS,
MAXIMUM_BLOCK_WEIGHT, MICRO_UNIT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, VERSION,
MAXIMUM_BLOCK_WEIGHT, MICRO_UNIT, MINIMUM_PERIOD, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
VERSION,
};
use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin};

Expand Down Expand Up @@ -133,7 +134,7 @@ impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
type MinimumPeriod = ConstU64<0>;
type MinimumPeriod = ConstU64<MINIMUM_PERIOD>;
type WeightInfo = ();
}

Expand Down
3 changes: 3 additions & 0 deletions templates/parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ mod block_times {
// NOTE: Currently it is not possible to change the slot duration after the chain has started.
// Attempting to do so will brick block production.
pub const SLOT_DURATION: u64 = MILLI_SECS_PER_BLOCK;

/// Minimum period between blocks set for the `pallet_timestamp`.
pub const MINIMUM_PERIOD: u64 = SLOT_DURATION / 2;
}
pub use block_times::*;

Expand Down
Loading