参考:https://docs.substrate.io/tutorials/v3/private-network/
实现目标
这里我们学习:
- 如何基于Substrate来构成一个两节点的链网络。
- 如何配置使用Aura的共识机制。
- 如何定制账户,并设置其为Aura的Validator。
启动两个节点的链网络
确认环境准备好了
- Rust及相关Rust的工具链已安装。
- Substrate node template源码已下载好,且编译通过。
- Subkey已安装好(它的安装步骤将在“自主生成key”部分详细讲)。
基于Substrate节点模板启动两节点的链网络
这里,我们将基于节点模板里缺省有的两个账户Alice和Bob,来启动两个Substrate节点,并让这个两个节点相互连接,形成一个链网络。因此,经过这部分学习后,我们应掌握基于Substrate构建多节点链网络的基本步骤。
基于Alice启动Substrate节点
- 执行以下的命令,清除之前节点启动可能残留的数据
./target/release/node-template purge-chain --base-path /tmp/alice --chain local
该命令会提示,敲入y
Are you sure to remove "/tmp/alice/chains/local_testnet/db/full"? [y/N]
注:如果希望新建的链是纯净的,就应清除之前启动过的链的数据。
- 执行以下的命令,用alice这个账户来启动一个substrate节点。
./target/release/node-template \
--base-path /tmp/alice \
--chain local \
--alice \
--port 30333 \
--ws-port 9945 \
--rpc-port 9933 \
--node-key 0000000000000000000000000000000000000000000000000000000000000001 \
--telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \
--validator
下面是该命令用到的选项的含义:
:Option | :Description |
---|---|
--base-path |
Specifies the directory for storing all of the data related to this chain. |
--chain local |
Specifies the chain specification to use. Valid predefined chain specifications include local , development , and staging . |
--alice |
Adds the predefined keys for the alice account to the node’s keystore. With this setting, the alice account is used for block production and finalization. |
--port 30333 |
Specifies the port to listen on for peer-to-peer (p2p ) traffic. Because this tutorial uses two nodes running on the same physical computer to simulate a network, you must explicitly specify a different port for at least one account. |
--ws-port 9945 |
Specifies the port to listen on for incoming WebSocket traffic. The default port is 9944 . This tutorial uses a custom web socket port number (9945 ). |
--rpc-port 9933 |
Specifies the port to listen on for incoming RPC traffic. The default port is 9933 . |
--node-key <key> |
Specifies the Ed25519 secret key to use for libp2p networking. You should only use this option for development and testing. |
--telemetry-url |
Specifies where to send telemetry data. For this tutorial, you can send telemetry data to a server hosted by Parity that is available for anyone to use. |
--validator |
Specifies th |