编译和运行substrate
rust环境搭建、 安装必要插件、 安装WASM、 升级cmake
这里以ubuntu18.04为例
参见安装rust、配置git、配置rust国内源
clone substrate
安装git :
sudo apt install git
clone substrate
克隆慢?请参见配置git
clone https://github.com/paritytech/substrate.git
编译substrate
cd substrate
cargo build --release
运行substrate单节点
./target/release/substrate
出现如下所示,说明单节点跑起来了,如果不是环境问题,不用15分钟吧
运行多节点
开启两个终端,进入到substrate目录下:
启动Alice节点
./target/release/substrate --alice --chain local --base-path /tmp/alice
这时候是不会出块的
启动bob节点
./target/release/node-template --bob --chain local --base-path /tmp/bob
至少两个节点一起启动,才会出块
local 网络只有alice和bob是验证人
substrate 命令
xxx@xxx:~/workspace/substracte/substrate-node-template$ ./target/release/node-template -h
node-template 2.0.0-rc2-93862bd-x86_64-linux-gnu
Substrate DevHub <https://github.com/substrate-developer-hub>
All core commands that are provided by default.
The core commands are split into multiple subcommands and `Run` is the default subcommand. From the CLI user
perspective, it is not visible that `Run` is a subcommand. So, all parameters of `Run` are exported as main executable
parameters.
(核心命令分为多个子命令,“run”是默认的子命令。在终端运行时,“run”是默认执行的。因此,“run”的所有参数都被导出为主要可执行文件的参数)
USAGE:
node-template [FLAGS] [OPTIONS]
node-template <SUBCOMMAND>
FLAGS:
--alice Shortcut for `--name Alice --validator` with session keys for `Alice` added to keystore
(local默认验证人)
--bob Shortcut for `--name Bob --validator` with session keys for `Bob` added to keystore
(local默认验证人)
--charlie Shortcut for `--name Charlie --validator` with session keys for `Charlie` added to keystore
(local用不上)
--dave Shortcut for `--name Dave --validator` with session keys for `Dave` added to keystore
(local用不上)
--dev Specify the development chain
--discover-local Enable peer discovery on local networks
--eve Shortcut for `--name Eve --validator` with session keys for `Eve` added to keystore
--ferdie Shortcut for `--name Ferdie --validator` with session keys for `Ferdie` added to keystore
--force-authoring Enable authoring even when offline
-h, --help Prints help information
--legacy-network-protocol Use the legacy "pre-mainnet-launch" networking protocol. Enable if things seem
broken. This option will be removed in the future
--light Experimental: Run in light client mode
--no-grandpa Disable GRANDPA voter when running in validator mode, otherwise disable the GRANDPA
observer
--no-mdns Disable mDNS discovery
--no-private-ipv4 Forbid connecting to private IPv4 addresses (as specified in
[RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with
`--reserved-nodes` or `--bootnodes`
--no-prometheus Do not expose a Prometheus metric endpoint
--no-telemetry Disable connecting to the Substrate telemetry server
--no-yamux-flow-control Disable the yamux flow control. This option will be removed in the future once
there is enough confidence that this feature is properly working
--one Shortcut for `--name One --validator` with session keys for `One` added to keystore
--password-interactive Use interactive shell for entering the password used by the keystore
--prometheus-external Listen to all Prometheus data source interfaces
--reserved-only Whether to only allow connections to/from reserved nodes
--rpc-external Listen to all RPC interfaces
--two Shortcut for `--name Two --validator` with session keys for `Two` added to keystore
--unsafe-pruning Force start with unsafe pruning settings
--unsafe-rpc-external Listen to all RPC interfaces
--unsafe-ws-external Listen to all Websocket interfaces
--validator Enable validator mode
-V, --version Prints version information
--ws-external Listen to all Websocket interfaces
OPTIONS:
-d, --base-path <PATH> Specify custom base path
--bootnodes <ADDR>... Specify a list of bootnodes
--chain <CHAIN_SPEC>
Specify the chain specification (one of dev, local, or staging)
--database <DB> Select database backend to use
--db-cache <MiB> Limit the memory the database cache can use
--offchain-worker <ENABLED>
Should execute offchain workers on every block [default: WhenValidating] [possible values: Always, Never,
WhenValidating]
--execution <STRATEGY>
The execution strategy that should be used by all execution contexts [possible values: Native, Wasm, Both,
NativeElseWasm]
--execution-block-construction <STRATEGY>
The means of execution used when calling into the runtime while constructing blocks [default: Wasm]
[possible values: Native, Wasm, Both, NativeElseWasm]
--execution-import-block <STRATEGY>
The means of execution used when calling into the runtime while importing blocks [default: NativeElseWasm]
[possible values: Native, Wasm, Both, NativeElseWasm]
--execution-offchain-worker <STRATEGY>
The means of execution used when calling into the runtime while using an off-chain worker [default: Native]
[possible values: Native, Wasm, Both, NativeElseWasm]
--execution-other <STRATEGY>
The means of execution used when calling into the runtime while not syncing, importing or constructing
blocks [default: Native] [possible values: Native, Wasm, Both, NativeElseWasm]
--execution-syncing <STRATEGY>
The means of execution used when calling into the runtime while syncing blocks [default: NativeElseWasm]
[possible values: Native, Wasm, Both, NativeElseWasm]
--in-peers <COUNT>
Specify the maximum number of incoming connections we're accepting [default: 25]
--enable-offchain-indexing <ENABLE_OFFCHAIN_INDEXING>
Enable Offchain Indexing API, which allows block import to write to Offchain DB
--keystore-path <PATH> Specify custom keystore path
--listen-addr <LISTEN_ADDR>... Listen on this multiaddress
-l, --log <LOG_PATTERN>...
Sets a custom logging filter. Syntax is <target>=<level>, e.g. -lsync=debug
--max-parallel-downloads <COUNT>
Maximum number of peers from which to ask for the same blocks in parallel [default: 5]
--max-runtime-instances <max-runtime-instances> The size of the instances cache for each runtime
--name <NAME> The human-readable name for this node
--node-key <KEY> The secret key to use for libp2p networking
--node-key-file <FILE>
The file from which to read the node's secret key to use for libp2p networking
--node-key-type <TYPE>
The type of secret key to use for libp2p networking [default: Ed25519] [possible values: Ed25519]
--out-peers <COUNT>
Specify the number of outgoing connections we're trying to maintain [default: 25]
--password <password> Password used by the keystore
--password-filename <PATH> File that contains the password used by the keystore
--pool-kbytes <COUNT>
Maximum number of kilobytes of all transactions stored in the pool [default: 20480]
--pool-limit <COUNT>
Maximum number of transactions in the transaction pool [default: 8192]
--port <PORT> Specify p2p protocol TCP port
--prometheus-port <PORT> Specify Prometheus data source server TCP Port
--pruning <PRUNING_MODE>
Specify the state pruning mode, a number of blocks to keep or 'archive'
--public-addr <PUBLIC_ADDR>...
The public address that other nodes will use to connect to it. This can be used if there's a proxy in front
of this node
--reserved-nodes <ADDR>... Specify a list of reserved node addresses
--rpc-cors <ORIGINS>
Specify browser Origins allowed to access the HTTP & WS RPC servers
--rpc-methods <METHOD SET>
RPC methods to expose. [default: Auto] [possible values: Auto, Safe, Unsafe]
--rpc-port <PORT> Specify HTTP RPC server TCP port
--sentry <sentry>... Enable sentry mode
--sentry-nodes <ADDR>... Specify a list of sentry node public addresses
--state-cache-size <Bytes> Specify the state cache size [default: 67108864]
--telemetry-url <URL VERBOSITY>... The URL of the telemetry server to connect to
--tracing-receiver <RECEIVER>
Receiver to process tracing messages [default: Log] [possible values: Log, Telemetry]
--tracing-targets <TARGETS> Comma separated list of targets for tracing
--wasm-execution <METHOD>
Method for executing Wasm runtime code [default: Interpreted] [possible values: Interpreted]
--ws-max-connections <COUNT> Maximum number of WS RPC server connections
--ws-port <PORT> Specify WebSockets RPC server TCP port
SUBCOMMANDS:
build-spec Build a spec.json file, outputs to stdout
check-block Validate a single block
export-blocks Export blocks to a file
export-state Export state as raw chain spec
help Prints this message or the help of the given subcommand(s)
import-blocks Import blocks from file
purge-chain Remove the whole chain data
revert Revert chain to the previous state
异常处理
删除缓存:
./target/release/substrate purge-chain --dev
删除指定数据库:
rm -rf /tmp/bob
rm -rf /tmp/alise
检查9944端口是否被占用
lsof -i:9944