Build InfraRelayChain
Before You Begin
Before you start, make sure to:
Review the Rust and Rust Toolchain to set up the Substrate development environment.
Familiarize yourself with Multi-Chain Architecture and Terms.
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
Clone the latest InfraBlockchain SDK:
Build the InfraBlockchain runtime by executing the following three commands:
Verify that the node has been built correctly by running the following command in the same directory:
If the command displays the command-line help, the node is ready for configuration.
Chain Specs
All Substrate-based chains require a chain spec. 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.
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.
In this tutorial, a sample chain spec file for the InfraRelayChain with four Seed Trust Validators is used. For actual network configuration, only alice
and bob
validators are started for simulation purposes.
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
Extract a SCALE-encoded 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 custom chain spec file.
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:
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:
--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.
After starting the node, you should see logs similar to the following:
Record the
peerid
for thealice
node so that other nodes can connect:Open a new terminal and start the second validator node for the
bob
account: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,
Once the
bob
node is started, you can confirm that blocks are being generated.
Next Steps
Last updated