此文针对xchain的区块链网络部署
独立启动模式
环境准备
1. cp ./bin/* /usr/bin
2. cp ./so/libwasmvm.x86_64.so /lib & /sbin/ldconfig -v
启动创世节点
默认客户端数据目录为 $HOME/.xccli
默认节点数据目录为 $HOME/.xcd
1. sh ./sh/init_genesis.sh
2. xcd start --rpc.laddr="tcp://0.0.0.0:26657"
启动节点加入已有区块链网络
注: 如果节点与创世节点在同一机器需要修改节点和客户端数据目录,修改脚本中的前两行xcclihome、xcdhome。
1. sh ./sh/init_follow.sh
将创世节点的创世配置拷贝到该节点目录
2. copy
$Genesis_HOME/.xcd/config/genesis.json ->$HOME/.xcd/config
- 将该节点地址加入区块链网络
3.1 获取节点地址
xcd tendermint show-node-address
3.2 创世节点添加账户并赋予peer角色
xccli tx member addAccount ${node-address} org1 peer --from org1Admin -y
4.获取创世节点的nodeid
xcd tendermint show-node-id
5.启动节点
xcd start --rpc.laddr="tcp://0.0.0.0:26647" --p2p.laddr="tcp://0.0.0.0:26646" --p2p.persistent_peers=
${创世节点node-id}@127.0.0.1:26656
docker启动模式
加载xchain镜像:
docker load < xchain.tar
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xchain latest 22ebd18c8fbe 9 minutes ago 165MB
启动创世节点xchain1:
> docker run -d --name xchain1 \
-v /data/node1/.xcd:/root/.xcd \
-v /data/node1/.xccli:/root/.xccli \
-p 26656:26656 \
-p 26657:26657 \
xchain:latest
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eface923382c xchain:latest "/bin/sh /root/start…" 3 seconds ago Up 2 seconds 0.0.0.0:26656-26657->26656-26657/tcp, :::26656-26657->26656-26657/tcp xchain1
查看节点日志
> docker logs -f xchain1
xcd start --rpc.laddr=tcp://0.0.0.0:26657
I[2022-07-04|07:32:58.450] starting ABCI with Tendermint module=main
!!!!!!!!NewNode enter, consensusPlugin: pbft
!!!!!!!!!!createBlockchainReactor, fastsync version: v0
I[2022-07-04|07:33:03.577] Executed block module=state height=1 validTxs=0 invalidTxs=0
I[2022-07-04|07:33:03.583] Committed state module=state height=1 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
I[2022-07-04|07:33:08.594] Executed block module=state height=2 validTxs=0 invalidTxs=0
I[2022-07-04|07:33:08.596] Committed state module=state height=2 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
I[2022-07-04|07:33:13.607] Executed block module=state height=3 validTxs=0 invalidTxs=0
I[2022-07-04|07:33:13.609] Committed state module=state height=3 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
I[2022-07-04|07:33:18.630] Executed block module=state height=4 validTxs=0 invalidTxs=0
I[2022-07-04|07:33:18.632] Committed state module=state height=4 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
查看节点状态:
> docker exec xchain1 xccli status
{
"node_info": {
"protocol_version": {
"p2p": "7",
"block": "10",
"app": "0"
},
"id": "ce86356fcb03a6f1f9b0296d774dca8daa5f39af",
"listen_addr": "tcp://0.0.0.0:26656",
"network": "xachain",
"version": "1.3.0",
"channels": "4030382021222300",
"moniker": "test",
"other": {
"tx_index": "on",
"rpc_address": "tcp://0.0.0.0:26657"
},
"validator_addr": "F87AD64DD24129C257FFDE8B76D1F09716A90BF0"
},
"sync_info": {
"latest_block_hash": "8D892C7B37744D89018CAEF3FC401380EF7D2D3A18B5D47A0CDDBA102C1F57B9",
"latest_app_hash": "3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2",
"latest_block_height": "82",
"latest_block_time": "2022-07-04T07:39:45.02626088Z",
"earliest_block_hash": "20BE1477D82EAD9B66C810DA7307C5274ECD119D9F0A52526638DE4EDA531325",
"earliest_app_hash": "",
"earliest_block_height": "1",
"earliest_block_time": "2022-07-04T07:32:56.417565882Z",
"catching_up": false
},
"validator_info": {
"address": "F87AD64DD24129C257FFDE8B76D1F09716A90BF0",
"pub_key": {
"type": "tendermint/PubKeySm2",
"value": "AwBTnQxuy2rKjpUpZAmLQbvHEgz9AiPqynHUiXENxOwG"
},
"voting_power": "100"
}
}
新建节点并加入xchain1所在区块链网络
准备新节点的工作目录
> mkdir -p /data/node2/.xcd/config/
将创世配置文件拷贝到新节点的工作目录
> docker cp xchain1:/root/.xcd/config/genesis.json /data/node2/.xcd/config/
查看xchain1的nodeid
> docker exec xchain1 xcd tendermint show-node-id
ce86356fcb03a6f1f9b0296d774dca8daa5f39af
启动新节点xchain2
> docker run -d --name xchain2 \
-v /data/node2/.xcd:/root/.xcd \
-v /data/node2/.xccli:/root/.xccli \
-p 26666:26656 \
-p 26667:26657 \
-e NODEORDER=follow \
--link xchain1:xchain1 \
xchain:latest --p2p.persistent_peers=ce86356fcb03a6f1f9b0296d774dca8daa5f39af@xchain1:26656
将xchain2的节点地址通过xchain1加入区块链组织并赋予peer角色
查看xchain2的节点地址
> docker exec xchain2 xcd tendermint show-node-address
xchain1ma3sxsnutd9mns4phxj3qkmxtq6ny9jw2xlkvs
发起添加账户交易
> docker exec xchain1 xccli tx member addAccount xchain1ma3sxsnutd9mns4phxj3qkmxtq6ny9jw2xlkvs org1 peer --from org1Admin -y
{
"height": "0",
"txhash": "BF4381F5F30A9A17151A8211DA3FD2714BCCC8B686E5BD2C1E6119DA398474C4"
}
查看节点日志
> docker logs -f xchain2
I[2022-07-04|08:08:37.851] starting ABCI with Tendermint module=main
!!!!!!!!NewNode enter, consensusPlugin: pbft
!!!!!!!!!!createBlockchainReactor, fastsync version: v0
E[2022-07-04|08:08:37.894] Can't add peer's address to addrbook module=p2p err="Cannot add non-routable address ce86356fcb03a6f1f9b0296d774dca8daa5f39af@172.17.0.2:26656"
E[2022-07-04|08:08:40.401] Stopping peer for error module=p2p peer="Peer{MConn{172.17.0.2:26656} ce86356fcb03a6f1f9b0296d774dca8daa5f39af out}" err=EOF
E[2022-07-04|08:08:45.422] Stopping peer for error module=p2p peer="Peer{MConn{172.17.0.2:26656} ce86356fcb03a6f1f9b0296d774dca8daa5f39af out}" err=EOF
E[2022-07-04|08:08:50.444] Stopping peer for error module=p2p peer="Peer{MConn{172.17.0.2:26656} ce86356fcb03a6f1f9b0296d774dca8daa5f39af out}" err=EOF
E[2022-07-04|08:08:55.457] Stopping peer for error module=p2p peer="Peer{MConn{172.17.0.2:26656} ce86356fcb03a6f1f9b0296d774dca8daa5f39af out}" err=EOF
E[2022-07-04|08:09:00.469] Stopping peer for error module=p2p peer="Peer{MConn{172.17.0.2:26656} ce86356fcb03a6f1f9b0296d774dca8daa5f39af out}" err=EOF
I[2022-07-04|08:09:05.698] Executed block module=state height=1 validTxs=0 invalidTxs=0
I[2022-07-04|08:09:05.700] Committed state module=state height=1 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
I[2022-07-04|08:09:05.704] Executed block module=state height=2 validTxs=0 invalidTxs=0
I[2022-07-04|08:09:05.705] Committed state module=state height=2 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
I[2022-07-04|08:09:07.118] Executed block module=state height=3 validTxs=0 invalidTxs=0
I[2022-07-04|08:09:07.119] Committed state module=state height=3 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
I[2022-07-04|08:09:07.123] Executed block module=state height=4 validTxs=0 invalidTxs=0
I[2022-07-04|08:09:07.124] Committed state module=state height=4 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
I[2022-07-04|08:09:07.127] Executed block module=state height=5 validTxs=0 invalidTxs=0
I[2022-07-04|08:09:07.128] Committed state module=state height=5 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
I[2022-07-04|08:09:07.133] Executed block module=state height=6 validTxs=0 invalidTxs=0
I[2022-07-04|08:09:07.135] Committed state module=state height=6 txs=0 appHash=3D707D36DF8A8E0E104FBF168F92380DEB8985406D992D4AF50964A04D9E4DE2
拥有两个节点的区块链网络建设完成,后续节点加入方式雷同。