Multi-group deployment, nodes join or exit groups, and new nodes are added

1. Star topology and parallel multiple groups

As shown in the figure below, star networking topology and parallel multi-group networking topology are two widely used networking methods in blockchain applications.

  • Star topology: The central organization node belongs to multiple groups at the same time and runs multiple organization applications. Each other organization belongs to a different group and runs its own application;

  • Parallel multiple groups: Each node in the blockchain belongs to multiple groups, which can be used for horizontal expansion of multiple parties with different businesses, or vertical expansion of the same business.

 

The following takes the construction of an eight-node star topology and a four-node parallel multi-group blockchain as an example to introduce the multi-group operation method in detail.

(1) Install dependencies

# CentOS
$ sudo yum install -y openssl curl

# Ubuntu
$ sudo apt install -y openssl curl

# Mac OS
# 最新homebrew默认下载的为openssl@3,需要指定版本[email protected]下载
$ brew install [email protected] curl

(2) Star topology

This chapter takes the construction of the star network topology of single machine, four institutions, three groups, and eight nodes as shown in the figure above as an example. , introduces how to use multiple groups.

The star blockchain network is as follows:

  • agencyA: There are 2 nodes on 127.0.0.1, both belonging to group1、group2、group3;

  • agencyB: There are 2 nodes on 127.0.0.1, belonging to group1;

  • agencyC: There are 2 nodes on 127.0.0.1, belonging to group2;

  • agencyD: There are 2 nodes on 127.0.0.1, belonging to group3.

 (3) Build a star blockchain node configuration folder

 Prepare to depend on

 Create operating directory

mkdir -p ~/fisco && cd ~/fisco

Get the build_chain.sh script.

curl -#LO https://gitee.com/FISCO-BCOS/FISCO-BCOS/raw/master-2.0/tools/build_chain.sh && chmod u+x build_chain.sh

Generate star blockchain system configuration file

# 生成区块链配置文件ip_list
$ cat > ipconf << EOF
127.0.0.1:2 agencyA 1,2,3
127.0.0.1:2 agencyB 1
127.0.0.1:2 agencyC 2
127.0.0.1:2 agencyD 3
EOF

# 查看配置文件ip_list内容
$ cat ipconf
# 空格分隔的参数分别表示如下含义:
# ip:num: 物理机IP以及物理机上的节点数目
# agency_name: 机构名称
# group_list: 节点所属的群组列表,不同群组以逗号分隔
127.0.0.1:2 agencyA 1,2,3
127.0.0.1:2 agencyB 1
127.0.0.1:2 agencyC 2
127.0.0.1:2 agencyD 3

Build star blockchain node configuration folder using build_chain script

bash build_chain.sh -f ipconf -p 30300,20200,8545

The successful screenshot is as follows

 The generated node file is as follows

 Start node

# 进入节点目录
$ cd ~/fisco/nodes/127.0.0.1

# 启动节点
$ bash start_all.sh

Screenshot of successful startup is as follows

 View group consensus status

At the time of non-commercial trade, the common knowledge is normal. At the same time,;belong;, become;,可通过查view Each point is normal. +++node0node1group1group2group3node2node3group1node4node5group2node6node7group3tail -f node*/log/* | grep "++"

Node normal consensus prints +++ log, +++ Log field meaning:

  • g::Group ID

  • blkNum: The height of the new block generated by the Leader node;

  • tx: The number of transactions included in the new block;

  • nodeIdx: index of this node;

  • hash: The latest block hash generated by the consensus node.

# 查看node0 group1是否正常共识(Ctrl+c退回命令行)
$ tail -f node0/log/* | grep "g:1.*++"
info|2019-02-11 15:33:09.914042| [g:1][p:264][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=2,hash=72254a42....

# 查看node0 group2是否正常共识
$ tail -f node0/log/* | grep "g:2.*++"
info|2019-02-11 15:33:31.021697| [g:2][p:520][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=ef59cf17...

# ... 查看node1, node2节点每个群组是否正常可参考以上操作方法...

# 查看node3 group1是否正常共识
$ tail -f node3/log/*| grep "g:1.*++"
info|2019-02-11 15:39:43.927167| [g:1][p:264][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=5e94bf63...

# 查看node5 group2是否正常共识
$ tail -f node5/log/* | grep "g:2.*++"
info|2019-02-11 15:39:42.922510| [g:2][p:520][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=2,hash=b80a724d...

 2.Configure the console

#回到fisco目录
$ cd ~/fisco

# 获取控制台
$ curl -#LO https://github.com/FISCO-BCOS/console/releases/download/v2.9.2/download_console.sh && bash download_console.sh

# 若因为网络问题导致长时间无法执行上面的命令,请尝试以下命令:
$ https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/console/releases/v2.9.2/download_console.sh && bash download_console.sh

# 进入控制台操作目录
$ cd console

# 拷贝group2节点证书到控制台配置目录
$ cp ~/fisco/nodes/127.0.0.1/sdk/* conf/

# 获取node0的channel_listen_port
$ grep "channel_listen_port" ~/fisco/nodes/127.0.0.1/node*/config.ini
/home/ubuntu16/fisco/nodes/127.0.0.1/node0/config.ini:    channel_listen_port=20200
/home/ubuntu16/fisco/nodes/127.0.0.1/node1/config.ini:    channel_listen_port=20201
/home/ubuntu16/fisco/nodes/127.0.0.1/node2/config.ini:    channel_listen_port=20202
/home/ubuntu16/fisco/nodes/127.0.0.1/node3/config.ini:    channel_listen_port=20203
/home/ubuntu16/fisco/nodes/127.0.0.1/node4/config.ini:    channel_listen_port=20204
/home/ubuntu16/fisco/nodes/127.0.0.1/node5/config.ini:    channel_listen_port=20205
/home/ubuntu16/fisco/nodes/127.0.0.1/node6/config.ini:    channel_listen_port=20206
/home/ubuntu16/fisco/nodes/127.0.0.1/node7/config.ini:    channel_listen_port=20207

# 拷贝控制台配置
$ cp ~/fisco/console/conf/config-example.toml ~/fisco/console/conf/config.toml

(1) Start the console

bash console/conf/start.sh

Screenshot of successful startup is as follows

 (2) Send transactions to the group

Transaction issued by console

# ... 向group1发交易...
$ [group:1]> deploy HelloWorld
contract address:0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744
# 查看group1当前块高,块高增加为1表明出块正常,否则请检查group1是否共识正常
$ [group:1]> getBlockNumber
1

# ... 向group2发交易...
# 切换到group2
$ [group:1]> switch 2
Switched to group 2.
# 向group2发交易,返回交易哈希表明交易部署成功,否则请检查group2是否共识正常
$ [group:2]> deploy HelloWorld
transaction hash: 0xd0305411e36d2ca9c1a4df93e761c820f0a464367b8feb9e3fa40b0f68eb23fa
contract address:0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744
# 查看group2当前块高,块高增加为1表明出块正常,否则请检查group2是否共识正常
$ [group:2]> getBlockNumber
1

# ... 向group3发交易...
# 切换到group3
$ [group:2]> switch 3
Switched to group 3.
# 向group3发交易,返回交易哈希表明交易部署成功
$ [group:3]> deploy HelloWorld
transaction hash: 0xd0305411e36d2ca9c1a4df93e761c820f0a464367b8feb9e3fa40b0f68eb23fa
contract address:0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744
# 查看group3当前块高,块高为1表明出块正常,否则请检查group3是否共识正常
$ [group:3]> getBlockNumber
1

# ... 切换到不存在的组4,控制台提示group4不存在,并输出当前的group列表 ...
$ [group:3]> switch 4
Group 4 does not exist. The group list is [1, 2, 3].

# 退出控制台
$ [group:3]> exit

View log

After the node generates a block, it will output Report logs. The meanings of each field in the log are as follows:

Every time a node produces a new block, a Report log will be printed. The meanings of each field in the Report log are as follows:

  • g::Group ID

  • num: Block height;

  • sealerIdx: Consensus node index;

  • hash: block hash;

  • next:Next block height;

  • tx:The number of transactions included in the block;

  • nodeIdx: Current node index.

# 进入节点目录
$ cd ~/fisco/nodes/127.0.0.1

# 查看group1出块情况:有新区块产生
$ cat node0/log/* |grep "g:1.*Report"
info|2019-02-11 16:08:45.077484| [g:1][p:264][CONSENSUS][PBFT]^^^^^^^^Report,num=1,sealerIdx=1,hash=9b5487a6...,next=2,tx=1,nodeIdx=2

# 查看group2出块情况:有新区块产生
$ cat node0/log/* |grep "g:2.*Report"
info|2019-02-11 16:11:55.354881| [g:2][p:520][CONSENSUS][PBFT]^^^^^^^^Report,num=1,sealerIdx=0,hash=434b6e07...,next=2,tx=1,nodeIdx=0

# 查看group3出块情况:有新区块产生
$ cat node0/log/* |grep "g:3.*Report"
info|2019-02-11 16:14:33.930978| [g:3][p:776][CONSENSUS][PBFT]^^^^^^^^Report,num=1,sealerIdx=1,hash=3a42fcd1...,next=2,tx=1,nodeIdx=2

(3) Node joins the group

This chapter takes adding node2 to group2 as an example to introduce how to add a new node to an existing group.

Copy group2 group configuration to node2

# 进入节点目录
$ cd ~/fisco/nodes/127.0.0.1

# ... 从node0拷贝group2的配置到node2...
$ cp node0/conf/group.2.* node2/conf

# ...重启node2(重启后请确定节点正常共识)...
$ cd node2 && bash stop.sh && bash start.sh

Get the node ID of node2

# 请记住node2的node ID,将node2加入到group2需用到该node ID
cat conf/node.nodeid

 Send a command to group2 through the console to add node2 to group2

# ...回到控制台目录,并启动控制台(直接启动到group2)...
cd ~/fisco/console && bash start.sh 2

 Check the block production status of newly added nodes through logs

# 进入节点所在目录
cd ~/fisco/nodes/127.0.0.1
# 查看节点共识情况(Ctrl+c退回命令行)
$ tail -f node2/log/* | grep "g:2.*++"
info|2019-02-11 18:41:31.625599| [g:2][p:520][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=4,tx=0,nodeIdx=1,hash=c8a1ed9c...
......此处省略其他输出......

# 查看node2 group2出块情况:有新区块产生
$ cat node2/log/* | grep "g:2.*Report"
info|2019-02-11 18:53:20.708366| [g:2][p:520][CONSENSUS][PBFT]^^^^^Report:,num=3,idx=3,hash=80c98d31...,next=10,tx=1,nodeIdx=1
# node2也Report了块高为3的区块,说明node2已经加入group2
Stop node
# 回到节点目录 && 停止节点
cd ~/fisco/nodes/127.0.0.1 && bash stop_all.sh

3. Multiple groups in parallel

The method of building parallel multi-group blockchains is similar to the method of building star-topology blockchains. Taking the construction of a four-node two-group parallel multi-chain system as an example:

  • Group 1: includes four nodes, the node IPs are all127.0.0.1;

  • Group 2: includes four nodes, and the node IPs are all127.0.0.1.

(1) Construct a single group four-node blockchain 1

Use the build_chain.sh script to generate a single group four-node blockchain node configuration folder

mkdir -p ~/fisco && cd ~/fisco
# 获取build_chain.sh脚本
curl -#LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.9.1/build_chain.sh && chmod u+x build_chain.sh

# 若因为网络问题导致长时间无法执行上面的命令,请尝试以下命令:
curl -#LO https://gitee.com/FISCO-BCOS/FISCO-BCOS/raw/master-2.0/tools/build_chain.sh && chmod u+x build_chain.sh

# 构建本机单群组四节点区块链(生产环境中,建议每个节点部署在不同物理机上)
bash build_chain.sh -l 127.0.0.1:4 -o multi_nodes -p 20000,20100,7545

The successful screenshot is as follows

 Start all nodes

# 进入节点目录
$ cd ~/fisco/multi_nodes/127.0.0.1
$ bash start_all.sh
# 查看进程情况
$ ps aux | grep fisco-bcos

 View node consensus status

# 查看node0共识情况(Ctrl+c退回命令行)
$ tail -f node0/log/* | grep "g:1.*++"
info|2019-02-11 20:59:52.065958| [g:1][p:264][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=2,hash=da72649e...

# 查看node1共识情况
$ tail -f node1/log/* | grep "g:1.*++"
info|2019-02-11 20:59:54.070297| [g:1][p:264][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=0,hash=11c9354d...

# 查看node2共识情况
$ tail -f node2/log/* | grep "g:1.*++"
info|2019-02-11 20:59:55.073124| [g:1][p:264][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=b65cbac8...

# 查看node3共识情况
$ tail -f node3/log/* | grep "g:1.*++"
info|2019-02-11 20:59:53.067702| [g:1][p:264][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=0467e5c4...

(2) Add group2 to the blockchain

 The configuration files of each group of the parallel multi-group blockchaingenesis are almost the same, but the [group].id is different, which is the group number.

# 进入节点目录
$ cd ~/fisco/multi_nodes/127.0.0.1

# 拷贝group1的配置
$ cp node0/conf/group.1.genesis node0/conf/group.2.genesis
$ cp node0/conf/group.1.ini node0/conf/group.2.ini

# 修改群组ID
$ sed -i "s/id=1/id=2/g"  node0/conf/group.2.genesis
$ cat node0/conf/group.2.genesis | grep "id"
# 已修改到    id=2

# 更新group.2.genesis文件中的共识节点列表,剔除已废弃的共识节点。

# 将配置拷贝到各个节点
$ cp node0/conf/group.2.genesis node1/conf/group.2.genesis
$ cp node0/conf/group.2.genesis node2/conf/group.2.genesis
$ cp node0/conf/group.2.genesis node3/conf/group.2.genesis
$ cp node0/conf/group.2.ini node1/conf/group.2.ini
$ cp node0/conf/group.2.ini node2/conf/group.2.ini
$ cp node0/conf/group.2.ini node3/conf/group.2.ini

# 重启各个节点
$ bash stop_all.sh
$ bash start_all.sh

Check the group consensus

# 查看node0 group2共识情况(Ctrl+c退回命令行)
$ tail -f node0/log/* | grep "g:2.*++"
info|2019-02-11 21:13:28.541596| [g:2][p:520][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=2,hash=f3562664...

# 查看node1 group2共识情况
$ tail -f node1/log/* | grep "g:2.*++"
info|2019-02-11 21:13:30.546011| [g:2][p:520][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=0,hash=4b17e74f...

# 查看node2 group2共识情况
$ tail -f node2/log/* | grep "g:2.*++"
info|2019-02-11 21:13:59.653615| [g:2][p:520][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=90cbd225...

# 查看node3 group2共识情况
$ tail -f node3/log/* | grep "g:2.*++"
info|2019-02-11 21:14:01.657428| [g:2][p:520][CONSENSUS][SEALER]++++++++Generating seal on,blkNum=1,tx=0,nodeIdx=3,hash=d7dcb462...

(3) Send transactions to the group

Get the console (if the above is not deleted, you can continue to use it)

# 若从未下载控制台,请进行下面操作下载控制台,否则将控制台拷贝到~/fisco目录:
$ cd ~/fisco
# 获取控制台
$ curl -#LO https://github.com/FISCO-BCOS/console/releases/download/v2.9.2/download_console.sh && bash download_console.sh

# 若因为网络问题导致长时间无法执行上面的命令,请尝试以下命令:
$ https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/console/releases/v2.9.2/download_console.sh && bash download_console.sh

Configure the console (to use the original console, you need to delete the original certificate, copy the certificate of the parallel node, and modify the config.toml file)

# 获取channel_port
$ grep "channel_listen_port" multi_nodes/127.0.0.1/node0/config.ini
multi_nodes/127.0.0.1/node0/config.ini:    channel_listen_port=20100

# 进入控制台目录
$ cd console
# 拷贝节点证书
$ cp ~/fisco/multi_nodes/127.0.0.1/sdk/* conf

# 拷贝控制台配置
$ cp ~/fisco/console/conf/config-example.toml ~/fisco/console/conf/config.toml

# 修改控制台连接节点的端口为20100和20101
# linux系统使用如下命令:
$ sed -i 's/127.0.0.1:20200/127.0.0.1:20100/g' ~/fisco/console/conf/config.toml
$ sed -i 's/127.0.0.1:20201/127.0.0.1:20101/g' ~/fisco/console/conf/config.toml  

# mac系统使用如下命令:
$ sed -i .bkp 's/127.0.0.1:20200/127.0.0.1:20100/g' ~/fisco/console/conf/config.toml
$ sed -i .bkp 's/127.0.0.1:20201/127.0.0.1:20101/g' ~/fisco/console/conf/config.toml 

Send transactions to groups through the console

# ... 启动控制台 ...
$ bash start.sh
# 输出如下信息表明控制台启动成功,若启动失败,请检查是否配置证书、channel listen port配置是否正确
=====================================================================================
Welcome to FISCO BCOS console(2.6.0)!
Type 'help' or 'h' for help. Type 'quit' or 'q' to quit console.
 ________ ______  ______   ______   ______       _______   ______   ______   ______
|        |      \/      \ /      \ /      \     |       \ /      \ /      \ /      \
| $$$$$$$$\$$$$$|  $$$$$$|  $$$$$$|  $$$$$$\    | $$$$$$$|  $$$$$$|  $$$$$$|  $$$$$$\
| $$__     | $$ | $$___\$| $$   \$| $$  | $$    | $$__/ $| $$   \$| $$  | $| $$___\$$
| $$  \    | $$  \$$    \| $$     | $$  | $$    | $$    $| $$     | $$  | $$\$$    \
| $$$$$    | $$  _\$$$$$$| $$   __| $$  | $$    | $$$$$$$| $$   __| $$  | $$_\$$$$$$\
| $$      _| $$_|  \__| $| $$__/  | $$__/ $$    | $$__/ $| $$__/  | $$__/ $|  \__| $$
| $$     |   $$ \\$$    $$\$$    $$\$$    $$    | $$    $$\$$    $$\$$    $$\$$    $$
 \$$      \$$$$$$ \$$$$$$  \$$$$$$  \$$$$$$      \$$$$$$$  \$$$$$$  \$$$$$$  \$$$$$$

=====================================================================================
# ... 向group1发交易...
# 获取当前块高
$ [group:1]> getBlockNumber
0
# 向group1部署HelloWorld合约,若部署失败,请检查group1共识是否正常
$ [group:1]> deploy HelloWorld
transaction hash: 0xd0305411e36d2ca9c1a4df93e761c820f0a464367b8feb9e3fa40b0f68eb23fa
contract address:0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744
# 获取当前块高,若块高没有增加,请检查group1共识是否正常
$ [group:1]> getBlockNumber
1

# ... 向group2发交易...
# 切换到group2
$ [group:1]> switch 2
Switched to group 2.
# 获取当前块高
$ [group:2]> getBlockNumber
0
# 向group2部署HelloWorld合约
$ [group:2]> deploy HelloWorld
transaction hash: 0xd0305411e36d2ca9c1a4df93e761c820f0a464367b8feb9e3fa40b0f68eb23fa
contract address:0x8c17cf316c1063ab6c89df875e96c9f0f5b2f744
# 获取当前块高,若块高没有增加,请检查group2共识是否正常
$ [group:2]> getBlockNumber
1
# 退出控制台
$[group:2]> exit

View node block production status through logs

# 切换到节点目录
$ cd ~/fisco/multi_nodes/127.0.0.1/

# 查看group1出块情况,看到Report了属于group1的块高为1的块
$ cat node0/log/* | grep "g:1.*Report"
info|2019-02-11 21:14:57.216548| [g:1][p:264][CONSENSUS][PBFT]^^^^^Report:,num=1,sealerIdx=3,hash=be961c98...,next=2,tx=1,nodeIdx=2

# 查看group2出块情况,看到Report了属于group2的块高为1的块
$ cat node0/log/* | grep "g:2.*Report"
info|2019-02-11 21:15:25.310565| [g:2][p:520][CONSENSUS][PBFT]^^^^^Report:,num=1,sealerIdx=3,hash=5d006230...,next=2,tx=1,nodeIdx=2
Stop node
# 回到节点目录 && 停止节点
$ cd ~/fisco/multi_nodes/127.0.0.1 && bash stop_all.sh

Guess you like

Origin blog.csdn.net/m0_72435337/article/details/131742135