infrablockchain-docs
en
en
  • InfraBlockchain
    • Learn
      • Architecture
        • Architecture
        • Network Participants
        • Parachain
          • System Parachains
      • Protocol
        • System Token
        • Transaction Fee
        • Proof of Transaction
      • Substrate
        • Learn
          • Basic
            • Cryptography
            • Blockchain Basics
            • Consensus
            • Networks and Nodes
            • Blockchain Transaction
            • Transaction Life Cycle
            • Offchain Operations
            • Light Client
            • Rust for Substrate
            • Introduction to Library
            • Architecture and Rust Libraries
            • File Architecture
            • Accounts, Addresses, and Keys
            • Transaction Format
            • Blockchain Randomness
          • FRAME
            • FRAME Pallets
            • FRAME Macros
            • Custom Pallets
            • Pallet Coupling
            • Origin
            • Events and Erros
            • Runtime Storage
            • State Transitions and Storage
            • SCALE Encoding
            • Weight and Fee
            • Runtime API
            • Runtime Development
          • Account
          • Address Format
          • Glossary
          • CLI
            • Archive
            • Memory Profiler
            • Node Template
            • sidecar
            • srtool
            • Subkey
            • subxt
            • try-runtime
            • tx-wrapper
          • Runtime Development
            • Basics
              • Configure Genesis State
              • Configure Runtime Constants
              • Customize a Chain Spec
              • Import a Pallet
              • Use Helper Function
            • Consensus Model
              • PoW
              • Create a Hybrid Node
            • Offchain Worker
              • Request Offchain HTTP
              • Offchain Indexing
              • Offchain Local Storage
            • Pallet Design
              • Create a Storage Structure
              • Implement Lockable Currency
              • Incorporate Randomness
              • Loose Coupling
              • Tight Coupling
            • Parachain Development
              • Add HRMP Channel
              • Add Paranodes
              • Connect to a Local Relay Chain
              • Convert a Solo Chain
              • Prepare to Launch
              • Select Collator
              • Upgrade a Parachain
            • Storage Migration
              • Basics
              • Trigger Migration
            • Test
              • Basics
              • Test a Transfer Transaction
            • Tools
              • Create a TxWrapper
              • Use Sidecar
              • try-runtime
              • Verify WASM
            • Weigths
              • Benchmark
              • Calculate Fees
              • Use Conditional Weights
              • Use Custom Weights
        • Build
          • Decide What to Build
          • Build Process
          • Determinisitc Runtime
          • Chain Spec
          • Genesis Configuration
          • Application Development
          • RPC
          • Troubleshoot Your Code
        • Tutorials
          • Install
            • Developer Tools
            • Linux
            • macOS
            • Rust Toolchain
            • Issues
            • Windows
          • Quick Start
            • Explore the Code
            • Modify Runtime
            • Start a Node
            • Substrate Basics
          • Build a Blockchain
            • Add Trusted Nodes
            • Authorize Specific Nodes
            • Build a Local Blockchain
            • Simulate Network
            • Upgrade a Running Network
          • Build Application Logic
            • Add a Pallet
            • Add Offchasin Workers
            • Publish Custom Pallets
            • Specify Origin for a Call
            • Use Macros in a Custom Pallet
          • Integrate with Tools
            • Access EVM Accounts
            • EVM Integration
            • Explore Sidecar Endpoints
            • Integrate a Light Client Node
          • Smart Contracts
            • Strategy
            • Build a Token Contract
            • Develop a Smart Contract
            • Prepare Your First Contract
            • Troubleshoot Smart Contracts
            • Use Maps for Storing Values
      • XCM
        • XCM
        • XCM Format
    • Service Chains
      • InfraDID
      • InfraEVM
      • URAuth(Universal Resource Auth)
    • DevOps
      • Build
      • Deploy
      • Monitoring
      • Runtime Upgrade
    • Tutorials
      • Basic
        • How to Interact with System Token
        • How To Pay Transaction Fee
        • How To Vote with TaaV
        • Hot to Get Validator Reward
      • Build
        • Build InfraRelayChain
        • Build Parachain
        • Open Message Passing Channels
        • Transfer Assets with XCM
      • Test
        • Benchmark
        • Check Runtime
        • Debug
        • Simulate Parachains
        • Unit Testing
      • Service Chains
        • Play with InfraDID
          • Build
          • Add Keys
          • Add Service Endpoint
          • Create InfraDID
        • Play with InfraEVM
          • Build
          • Deposit and Withdraw Token
          • Deploy ERC20 Contract
          • Deploy ERC721 Contract
          • Deploy ERC1155 Contract
  • Newnal Data Market
Powered by GitBook
On this page
  • Before You Begin
  • Tutorial Objectives
  • Build the Relay Chain Node
  • Chain Specs
  • Start the Relay Chain Node
  • Next Steps
  1. InfraBlockchain
  2. Tutorials
  3. Build

Build InfraRelayChain

PreviousBuildNextBuild Parachain

Last updated 1 year ago

Before You Begin

Before you start, make sure to:

  • Review the to set up the Substrate development environment.

  • Familiarize yourself with Multi-Chain Architecture and .

Tutorial Objectives

By completing this tutorial, you will achieve the following objectives:

  • Learn how to build the InfraRelayChain runtime as a binary.

  • Extract the plain chain spec and the SCALE-encoded raw chain spec from the binary.

  • Start nodes from the chain spec.

Build the Relay Chain Node

  1. Clone the latest InfraBlockchain SDK:

    git clone --branch master https://github.com/InfraBlockchain/infrablockchain-substrate.git
  2. Build the InfraBlockchain runtime by executing the following three commands:

    1. cargo build --release --bin infra-relaychain
    
    2. cargo build --release --bin infra-relaychain-execute-worker
    
    3. cargo build --release --bin infra-relaychain-prepare-worker
  3. Verify that the node has been built correctly by running the following command in the same directory:

    ./target/release/infra-relaychain --help

    If the command displays the command-line help, the node is ready for configuration.

Chain Specs

Extracting the Plain Chain Spec

Use the following command in the same directory to extract the plain chain spec. After running the command, the plain-infra-relay-chainspec.json file is created in the same path.

./target/release/infra-relaychain build-spec --chain infra-relay-local --disable-default-bootnode > plain-infra-relay-chainspec.json

Relay Chain must have at least one validator node running for each connected parachain collator. Therefore, to connect two parachains with one collator each, you need to run at least three Relay Chain validator nodes.

Extracting the Raw Chain Spec File

./target/release/infra-relaychain build-spec --chain plain-infra-relay-chainspec.json --disable-default-bootnode --raw > raw-infra-relay-chainspec.json

If someone else is completing this tutorial concurrently on the same local network, modify the plain chain spec to avoid connecting nodes. In the plain chain spec JSON file, find the protocolId key and change it to a unique value:

   "protocolId": "infrablockchain"

Start the Relay Chain Node

To build the InfraBlockchain, you need to start the InfraRelayChain, which can connect parachains.

Start a validator node for alice account:

./target/release/infra-relaychain \
--alice \
--validator \
--base-path /tmp/relay/alice \
--chain ./raw-infra-relay-chainspec.json \
--port 30333 \
--rpc-port 9944
  • --validator: Option to start a validator node.

  • --base_path: Specifies the location where chain data is stored.

  • --chain: Path to the raw chain spec file.

  • --port, --rpc-port: Specifies the ports for communication with the chain.

    Ensure that the same ports are not used by other nodes on the local computer.

  1. After starting the node, you should see logs similar to the following:

    2023-11-16 18:05:43 bclabs InfraBlockchain
    2023-11-16 18:05:43 ✌️  version 1.1.0-e146a06602e
    2023-11-16 18:05:43 ❤️  by blockchain labs, 2017-2023
    2023-11-16 18:05:43 📋 Chain specification: Infra Relay Devnet
    2023-11-16 18:05:43 🏷  Node name: Alice
    2023-11-16 18:05:43 👤 Role: AUTHORITY
    2023-11-16 18:05:43 💾 Database: RocksDb at /tmp/relay/alice/chains/infra_relay_devnet/db/full
    2023-11-16 18:05:44 BEEFY is still experimental, usage on Polkadot network is discouraged.
    2023-11-16 18:05:45 👶 Creating empty BABE epoch changes on what appears to be first startup. 
    2023-11-16 18:05:45 🏷  Local node identity is: 12D3KooWBJyq6nyn6JJSmdy5QmemYBCofKvWh6w5Am6p33tYzxu1
    
    ...
  2. Record the peerid for the alice node so that other nodes can connect:

    🏷 Local node identity is: 12D3KooWBJyq6nyn6JJSmdy5QmemYBCofKvWh6w5Am6p33tYzxu1
  3. Open a new terminal and start the second validator node for the bob account:

    ./target/release/infra-relaychain \
    --bob \
    --validator \
    --base-path /tmp/relay/bob \
    --chain ./raw-infra-relay-chainspec.json \
    --port 30334 \
    --rpc-port 9945 

    The command used to start the first node is similar to the one used for starting the second node, but there are some important differences..

  • Use a command similar to the one used for the first node, but with a different base path (/tmp/relay/bob), validator key (--bob), and ports (30334 and 9945).

  • Since both validators are running on the same local computer, there is no need to specify the IP address and peer identifier of the first node as specified in the chain spec file. The bootnodes option is necessary when connecting to nodes running outside the local network or nodes not identified in the chain spec file.

  • If the relay chain is not producing blocks, try disabling the firewall or start the node with the address of the alice node in the --bootnodes option:

    Example,

    ./target/release/infra-relaychain \
    --bob \
    --validator \
    --base-path /tmp/relay/bob \
    --chain ./raw-infra-relay-chainspec.json \
    --port 30334 \
    --rpc-port 9945 
    --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWGjsmVmZCM1jPtVNp6hRbbkGBK3LADYNniJAKJ19NUYiq
  • Once the bob node is started, you can confirm that blocks are being generated.

    2023-11-16 18:08:57 discovered: 12D3KooWP2vgMARpeD9H5innUPaBR7LFQqJSP6dX4TRS9DtkqsBQ /ip4/172.16.72.194/tcp/30334
    2023-11-16 18:09:00 💤 Idle (1 peers), best: #0 (0xe521…3cca), finalized #0 (0xe521…3cca), ⬇ 1.5kiB/s ⬆ 1.5kiB/s
    2023-11-16 18:09:05 💤 Idle (1 peers), best: #0 (0xe521…3cca), finalized #0 (0xe521…3cca), ⬇ 0.2kiB/s ⬆ 0.2kiB/s
    2023-11-16 18:09:10 💤 Idle (1 peers), best: #0 (0xe521…3cca), finalized #0 (0xe521…3cca), ⬇ 0 ⬆ 0
    2023-11-16 18:09:12 🙌 Starting consensus session on top of parent 0xe5212b368879d4a38e84693a0f1582402ac100948a895217823de534cf753cca
    🎁 Prepared block for proposing at 1 (2 ms) [hash: 0x2a02735687bb7ec53f34e17424a313b8b05ecce8ac855216dfae3c254980efdc; parent_hash: 0xe521…3cca; extrinsics (2): [0x62c3…6593, 0xf265…0515]

Next Steps

All Substrate-based chains require a . The chain spec specifies the initial state of the network (genesis state) and various network settings. For deterministic network configuration, all nodes participating in the network have the same chain spec.

In this tutorial, a sample chain spec file for the InfraRelayChain with four is used. For actual network configuration, only alice and bob validators are started for simulation purposes.

Extract a raw JSON file. After running the command, the raw-infra-relay-chainspec.json file is created in the same path.

You can read and edit the plain text version of the chain spec file. However, to use the chain spec file to start a node, it needs to be converted to the SCALE-encoded raw format. The sample chain spec represents a network with four validators. If you want to add different validators, multiple relay chains, or use custom account keys instead of predefined accounts, you will need to create a .

Rust and Rust Toolchain
Terms
chain spec
SCALE-encoded
Build a parachain
custom chain spec file
Seed Trust Validators