## Module your_first_node

Source
Expand description

Running the given runtime with a node. No specific consensus mechanism is used at this stage.

## §Your first Node

In this guide, you will learn how to run a runtime, such as the one created in `your_first_runtime`, in a node. Within the context of this guide, we will focus on running the runtime with an `omni-node`. Please first read this page to learn about the OmniNode, and other options when it comes to running a node.

`your_first_runtime` is a runtime with no consensus related code, and therefore can only be executed with a node that also expects no consensus ([`sc_consensus_manual_seal`]). `pezkuwi-omni-node`’s `--dev-block-time` precisely does this.

> All of the following steps are coded as unit tests of this module. Please see `Source` of the page for more information.

### §Running The Omni Node

#### §Installs

The `pezkuwi-omni-node` can either be downloaded from the latest Release of `pezkuwi-sdk`, or installed using `cargo`:

    cargo install pezkuwi-omni-node

Next, we need to install the `chain-spec-builder`. This is the tool that allows us to build chain-specifications, through interacting with the genesis related APIs of the runtime, as described in `crate::guides::your_first_runtime`.

    cargo install staging-chain-spec-builder

> The name of the crate is prefixed with `staging` as the crate name `chain-spec-builder` on crates.io is already taken and is not controlled by `pezkuwi-sdk` developers.

#### §Building Runtime

Next, we need to build the corresponding runtime that we wish to interact with.

    cargo build --release -p path-to-runtime

Equivalent code in tests:

ⓘ

    run_cmd!(
    	cargo build --release -p $FIRST_RUNTIME
    )
    .expect("Failed to run command");

This creates the wasm file under `./target/{release}/wbuild/release` directory.

#### §Building Chain Spec

Next, we can generate the corresponding chain-spec file. For this example, we will use the `development` (`sp_genesis_config::DEVELOPMENT`) preset.

Note that we intend to run this chain-spec with `pezkuwi-omni-node`, which is tailored for running teyrchains. This requires the chain-spec to always contain the `para_id` and a `relay_chain` fields, which are provided below as CLI arguments.

    chain-spec-builder \
    	-c <path-to-output> \
    	create \
    	--relay-chain dontcare \
    	--runtime pezkuwi_sdk_docs_first_runtime.wasm \
    	named-preset development

Equivalent code in tests:

ⓘ

    let chain_spec_builder = find_release_binary(&CHAIN_SPEC_BUILDER).unwrap();
    let runtime_path = find_wasm(PARA_RUNTIME).unwrap();
    let output = "/tmp/demo-chain-spec.json";
    let runtime_str = runtime_path.to_str().unwrap();
    run_cmd!(
    	$chain_spec_builder -c $output create --relay-chain dontcare -r $runtime_str named-preset development
    ).expect("Failed to run command");
    std::fs::remove_file(output).unwrap();

#### §Running `pezkuwi-omni-node`

Finally, we can run the node with the generated chain-spec file. We can also specify the block time using the `--dev-block-time` flag.

    pezkuwi-omni-node \
    	--tmp \
    	--dev-block-time 1000 \
    	--chain <chain_spec_file>.json

> Note that we always prefer to use `--tmp` for testing, as it will save the chain state to a temporary folder, allowing the chain-to be easily restarted without `purge-chain`. See [`sc_cli::commands::PurgeChainCmd`] and [`sc_cli::commands::RunCmd::tmp`] for more info.

This will start the node and import the blocks. Note while using `--dev-block-time`, the node will use the testing-specific manual-seal consensus. This is an efficient way to test the application logic of your runtime, without needing to yet care about consensus, block production, relay-chain and so on.

#### §Next Steps

- See the rest of the steps in `crate::reference_docs::omni_node`.