📚
Open Polkadot Bootcamp
  • 📚 About the Bootcamp
    • 📖 Additional Resources
    • 👐 Ask For Support
  • 📖 Curriculum
  • 📕Rust Programming Language
    • Basic Rust
      • Introduction to Rust
        • 🧑‍💻 Excercises
      • Common Programming Concepts
        • 🧑‍💻 Excercises
      • Program Life Cycle
        • 🧑‍💻 Excercises
      • Ownership & Borrow Checker
      • Common Data Structures
    • Advanced Rust
      • Generic types, Trait extension and Advanced types
      • Lifetime Notation
      • Smart pointers & Macros
      • Common design patterns in Rust
      • Package management & How to structure your Rust project
      • Overview of the Rust ecosystem
  • 📘Building a blockchain with Polkadot SDK
    • Polkadot
      • Additional Reads
        • Why do you want to build a blockchain on Polkadot?
        • Understanding the sharded network design of Polkadot
      • Development on Polkadot
    • Polkadot SDK
      • Substrate
        • Create a new blockchain
          • 🧑‍💻 Exercise: Clone the minimal template
          • Understanding the architecture
          • Break down the node architecture
          • Introducing to Pop CLI tool
        • Adding a custom logic to runtime
          • 🧑‍💻 Exercise: Rust State Machine
          • Components of a Pallet
          • Hooks
          • Weights & Benchmarking
          • Extensions
            • Signed Extensions
            • Transaction Extensions
        • Common runtime modules
          • 📕Example: System Pallet
          • 📕Example: Contracts Pallet
          • 📕Example: Assets Pallet
          • 📕Example: Utility Pallet
        • Runtime API and RPC
        • Runtime upgrade
        • Bump Polkadot SDK versions
      • Cumulus
        • Introduction to Cumulus
          • Parachain from scratch
          • 🧑‍💻 Exercise: Build a parachain from scratch
        • Running a local relaychain network
          • Register & reserve a parachain
          • Launch the network & run a collator node
          • Launch the network with Pop CLI
        • Agile Coretime
    • Polkadot Hub
  • 📒Smart Contract Development
    • Introduction
      • Introduction to PolkaVM
      • Getting started with Solidity development
      • Solidity File Structure
      • Contract Structure
    • Basic Solidity
      • Value types
      • Reference Types
      • Mapping Types
      • Simple Storage
    • Advanced Solidity
      • Units
      • Global Variables
      • Expression and Control Structures
      • Advanced Storage
      • Contract Tests
      • Contracts
Powered by GitBook
On this page
  • Relay Chain
  • Parachain
  • Session Keys
  • Generating keys
  • Session-pallet
  • Keystore
  • Invulnerables & Candidates
  1. Building a blockchain with Polkadot SDK
  2. Polkadot SDK
  3. Cumulus
  4. Running a local relaychain network

Launch the network & run a collator node

PreviousRegister & reserve a parachainNextAgile Coretime

Last updated 6 months ago

Relay Chain

Either follow the tutorial , use to setup a local environment or connect to Rococo.

Important: we need the same chainspec that is used to start the validators for the collator(s). In case of connecting to Rococo, we need the .

Parachain

Register Parachain

If necessary, register the parachain to the Relay Chain with the parachain-genesis-state and the parachain-wasm files generated above. In addition, you need a parachain manager account and the para-id. Check out the tutorial and look for the step "Register with the local Relay Chain"

Launch Collator

Before we launch a Collator for the Parachain, make sure that its database is purged from any previous attempts, as any leftover state can cause syncing issues. In other words, the genesis state of the collator won't match the genesis state that has been given to the Relay chain.

./target/release/parachain-node-template purge-chain --base-path /tmp/parachain/<collator> --chain parachain-chainspec-raw.json

Launch the collator:

./target/release/parachain-node-template --collator \
--name C1 \
--base-path /tmp/parachain/collator1 \
--chain parachain-chainspec-raw.json \
--force-authoring \
--rpc-port 10001 \
--ws-port 10002 \
--listen-addr /ip4/0.0.0.0/tcp/10003/ws \
-- \
--execution wasm \
--chain /{PATH_TO_RELAYCHAIN_CHAINSPEC} \
--port 10004 \
--ws-port 10005
  1. Ensure the collator is peering with the relay chain (and the other collator(s) if present) by checking the collator output logs.

    • No peers with the Parachain: see Important.

Important:

  • the force-authoring flag is only necessary when you have one collator (e.g. for testing).

  • the listen-addr flag is necessary if you want other nodes to be able to connect to you to join the network. An additional bootnodes flag is necessary for this other collator (when the chainspec doesn't provide bootnodes). In addition, you need the [parachain] local identity of the collator you want to connect to (you can find this in the logs when you start your node).

An example of launching a second collator that you want to connect to the first collator shown above:

./target/release/parachain-node-template --collator \
--name C2 \
--base-path /tmp/parachain/collator2 \
--chain parachain-chainspec-raw.json \
--force-authoring \
--rpc-port 10006 \
--ws-port 10007 \
--listen-addr /ip4/0.0.0.0/tcp/10008/ws \
--bootnodes /ip4/127.0.0.1/tcp/10003/ws/p2p/{INSERT_COLLATOR_1_PARACHAIN_NODE_IDENTITY} \
-- \
--execution wasm \
--chain /{PATH_TO_RELAYCHAIN_CHAINSPEC} \
--port 10009 \
--ws-port 10010

*The force-authoring can still be provided for the case where you want it to build blocks if it is the only collator in the network.

Session Keys

The session key needs to be set for a collator to start producing blocks. It is advised to use a different keypair than the collator keypair. This is to minimize exposure of the collator keypair.

Generating keys

There are multiple ways to generate keys, such as:

  • Polkadot JS extension or any other custodial

Session-pallet

In order to change your session keys you'd have to call set_keys with the new public key.

Keystore

In order for a collator to be able to sign e.g. its produced block, the session keypair needs to be added to the keystore. The keystore is a file that provides a secure and encrypted storage solution for your private keys. It ensures that only authorized processes can access and use the private keys when needed.

  1. Go to Developer and RPC calls and click author, insertKey.

  2. Enter "aura" as the keyType

  3. Enter the seed/mnemonic of the collator's session key as suri.

  4. Enter he hex value of the public key of the collator's session key for publicKey.

The Collator's session keys are added to the keystore and should now be building blocks.

Invulnerables & Candidates

No peers with the Relay Chain: if you made changes to the relay chainspec, make sure bootnodes are provided. In addition, can also be a problem.

No blocks being produced should be expected until the session key is added to the keystore - This is specific to a custom chain spec and would probably work if using the parachain-node-template default spec as it would probably just use alice/bob as collators. ./target/release/parachain-node-template --help:

Last, depending on the chain and the syncing method, the time it takes to be completely synchronized and build your first block can vary. The flag --sync=warp enables the node to make use of the . This decreases the synchronization time significantly by only validating / applying full blocks at the end of the initial synchronization process.

Session keys are set in . Session keys can be added to , otherwise needs to be called by the collator.

Connect to your collator via Polkadot JS: (ws-port flag set to 10002)

As for cumulus' out-of-the-box implementation, the set of collators that are allowed to build blocks are coming from the pallet , more specifically the invulnerables and candidates.

If we want to add a new collator we either through root or we can .

Important: invulnerables will always be chosen to build blocks. As for candidates, there is a that caps the amount of candidates that can be registered. In other words, if a collator wants to register as candidate but the desired_amount is met, the collator has to wait until a collator or the desired_amount .

📘
"Prepare a local Relay Chain"
Zombienet
Rococo chainspec
"Connect a local Parachain"
NAT
warp sync protocol
PolkaVault
Subkey
session-pallet
genesis state
set_keys
https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A10002
collator-selection
add it to invulnerables
register as a candidate
desired_amount
leave_intent
is increased