8. Block chain expansion

Label: “node management” “expansion group” “free node” “new node” “consensus node” “


FISCO BCOS introduces free nodes, observer nodes and consensus nodesThe three node types can be converted to each other through the console。

  • Consensus node: the node participating in the consensus, which owns all the data of the group (consensus nodes are generated by default when the chain is connected)。

  • Observer nodes: nodes that do not participate in consensus, but can synchronize data on the chain in real time。

  • Free nodes: nodes that have been started and are waiting to join the group。In a temporary node state, can not get the data on the chain。

Convert the specified node into a consensus node, an observer node, and a free node

The following is a detailed description of how the group can expand a new node in combination with a specific operation case。The expansion operation is divided into two phases, namelyGenerate certificates for nodes and launchAdd node to group

This section assumes that the user has already referred to Building the First Blockchain NetworkBuild a 4-node alliance chain, the next operation will generate a new node, and then join the node to group 1。

If you are using the O & M deployment tool, please refer to here to expand the operation

1. Generate a certificate for the node and start it

Each node needs to have a set of certificates to establish connections with other nodes on the chain, and to expand a new node, you first need to issue a certificate for it。

Generate private key certificate for new node

The following operations are performed in the ‘nodes / 127.0.0.1’ directory

  1. Get the certificate generation script

curl -#LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master-2.0/tools/gen_node_cert.sh

Note

-If you cannot download for a long time due to network problems, please try’curl-#LO https://gitee.com/FISCO-BCOS/FISCO-BCOS/raw/master-2.0/tools/gen_node_cert.sh`

  1. Generate a new node private key certificate

# -c specifies the path of the institution certificate and private key
# -o output to the specified folder, where the newly issued certificate and private key of the agency will exist in node4 / conf
# All completed prompt will be output successfully
bash gen_node_cert.sh -c ../cert/agency -o node4

For the national secret version, please execute the following instructions to generate the certificate。

bash gen_node_cert.sh -c ../cert/agency -o node4 -g ../gmcert/agency/

Preparing Node Configuration Files

  1. Copy ‘node0 / config.ini’, ‘node0 / start.sh’ and ‘node0 / stop.sh’ to the node4 directory;

cp node0/config.ini node0/start.sh node0/stop.sh node4/
  1. Modify ‘node4 / config.ini’。For the ‘[rpc]’ module, modify ‘channel _ listen _ port = 20204’ and ‘jsonrpc _ listen _ port = 8549’;For the ‘[p2p]’ module, modify ‘listen _ port = 30304’ and add its own node information to ‘node.’;

$ vim node4/config.ini
[rpc]
    ;rpc listen ip
    listen_ip=127.0.0.1
    ;channelserver listen port
    channel_listen_port=20204
    ;jsonrpc listen port
    jsonrpc_listen_port=8549
[p2p]
    ;p2p listen ip
    listen_ip=0.0.0.0
    ;p2p listen port
    listen_port=30304
    ;nodes to connect
    node.0=127.0.0.1:30300
    node.1=127.0.0.1:30301
    node.2=127.0.0.1:30302
    node.3=127.0.0.1:30303
    node.4=127.0.0.1:30304
  1. Node 3 copies’ node0 / conf / group.1.genesis’ of node 1 (includingInitial list of group nodes) and ‘node0 / conf / group.1.ini’ to the ‘node4 / conf’ directory without modification;

cp node0/conf/group.1.genesis node0/conf/group.1.ini node4/conf/
  1. Run ‘node4 / start.sh’ to start the node;

bash node4/start.sh
  1. Confirm that the connection between node4 and other nodes has been established, and the operation of joining the network is completed。

tail -f node4/log/log*  | grep "connected count"
# The following logs indicate that node node4 has established connections with four other nodes
info|2020-12-22 20:44:36.113611|[P2P][Service] heartBeat,connected count=4
info|2020-12-22 20:44:46.117942|[P2P][Service] heartBeat,connected count=4
info|2020-12-22 20:44:56.120799|[P2P][Service] heartBeat,connected count=4

2. Node joining group

Get the nodeid of node4

cat node4/conf/node.nodeid

The string similar to the following is nodeid, which is the hexadecimal representation of the node public key. For the national password, run ‘cat node4 / conf / gmnode.nodeid’

94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e

Join node4 to group 1 using the console

  1. Use addObserver to add node4 as an observation node to group 1

[group:1]> getObserverList
[]

[group:1]> addObserver 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
{
    "code":1,
    "msg":"Success"
}

[group:1]> getObserverList
[
    94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
]
  1. Use addSealer to add node4 as a consensus node to group 1

[group:1]> getSealerList
[
    6c41f7e138051a13a220cb186e934398e37700295ff355b87f113704996b3e03750100e16653cda18b5f954d3b7b08d068ca4a9d65cec5a40db980b697ffb699,
    7404cdf7f34f038aba90059ff25dc5f05f538010c55e98976aea6bc954910f34f15a255869751c8fe564bdb0fa1eee8e2db47eeca0fdd1359beaac6adcd37ede,
    a7b856e5b59072c809ea963fa45ede72f7d37561affff989fbede6cd61a40137e2146db205434788e61b89a57f08c614cd283e5e915c23714c2fa685237e8bdb,
    e5ea1e18717418a57f115bf1cea5168250f86e5b77f74dd15d0c4bf3758ca37002059ba2e54131296d1646a62be5faf85e243dac8d33d452acd63e20428b72ed
]

[group:1]> addSealer 94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
{
    "code":1,
    "msg":"Success"
}

[group:1]> getSealerList
[
    6c41f7e138051a13a220cb186e934398e37700295ff355b87f113704996b3e03750100e16653cda18b5f954d3b7b08d068ca4a9d65cec5a40db980b697ffb699,
    7404cdf7f34f038aba90059ff25dc5f05f538010c55e98976aea6bc954910f34f15a255869751c8fe564bdb0fa1eee8e2db47eeca0fdd1359beaac6adcd37ede,
    a7b856e5b59072c809ea963fa45ede72f7d37561affff989fbede6cd61a40137e2146db205434788e61b89a57f08c614cd283e5e915c23714c2fa685237e8bdb,
    e5ea1e18717418a57f115bf1cea5168250f86e5b77f74dd15d0c4bf3758ca37002059ba2e54131296d1646a62be5faf85e243dac8d33d452acd63e20428b72ed,
    94ae60f93ef9a25a93666e0149b7b4cb0e044a61b7dcd1b00096f2bdb17d1c6853fc81a24e037c9d07803fcaf78f768de2ba56a4f729ef91baeadaa55a8ccd6e
]

For more operations, please refer to Node Management