借助BFT-SMaRt
共识提供的Reconfig操作元语,JD Chain
实现了在不停机的情况下快速更新共识网络拓扑,实现添加共识节点,移除共识节点,更新共识信息 等功能。
:bin$ ./jdchain-cli.sh participant -h
Usage: jdchain-cli participant [-hV] [--pretty] [--home=<path>] [COMMAND]
Add, update or delete participant.
-h, --help Show this help message and exit.
--home=<path> Set the home directory.
Default: ../
--pretty Pretty json print
-V, --version Print version information and exit.
Commands:
register Register new participant.
active Active participant.
update Update participant.
inactive Inactive participant.
help Displays help information about the specified command
:bin$ ./jdchain-cli.sh participant register -h
Register new participant.
Usage: jdchain-cli participant register [-hV] [--ca-mode] [--pretty]
[--crt=<caPath>] [--gw-host=<gwHost>]
[--gw-port=<gwPort>] [--home=<path>]
[-n=<name>]
--participant-name=<participantName>
[--pubkey=<pubkey>]
--ca-mode Register with CA
--crt=<caPath> File of the X509 certificate
--gw-host=<gwHost> Set the gateway host. Default: 127.0.0.1
--gw-port=<gwPort> Set the gateway port. Default: 8080
-h, --help Show this help message and exit.
--home=<path> Set the home directory.
-n, --name=<name> Name of the key
--participant-name=<participantName>
Name of the participant
--pretty Pretty json print
--pubkey=<pubkey> Pubkey of the user
-V, --version Print version information and exit.
participant-name
,新节点名称ca-mode
,身份认证模式是否为证书(CA
)模式,默认false
name
,当ca-mode
为true
时会读取本地${home}/config/keys/${name}.crt
文件,反之读取${home}/config/keys/${name}.pub
crt
,证书文件路径pubkey
,Base58
编码公钥信息,仅在非ca-mode
情况下使用注册新节点:
:bin$ ./jdchain-cli.sh participant register --participant-name node4 --name node4
select ledger, input the index:
INDEX LEDGER
0 j5sB3sVTFgTqTYzo7KtQjBLSy8YQGPpJpvQZaW9Eqk46dg
// 选择账本
> 0
// 选择此交易签名用户(必须是链上存在的用户,且有相应操作权限)
select keypair to sign tx, input the index:
0 k1 LdeNq3862vtUCeptww1T5mVvLbAeppYqVNdqD
1 1627618939 LdeNyibeafrAQXgHjBxgQxoLbna6hL4BcXZiw
2 node4 LdeNwG6ECEGz57o2ufhwSbnW4C35TvPqANK7T
1
input password of the key:
> 1
register participant: [LdeNwG6ECEGz57o2ufhwSbnW4C35TvPqANK7T]
成功在账本j5sB3sVTFgTqTYzo7KtQjBLSy8YQGPpJpvQZaW9Eqk46dg
中注册了新的节点LdeNwG6ECEGz57o2ufhwSbnW4C35TvPqANK7T
可通过共识节点列表查看新的账本列表:
:bin$ ./jdchain-cli.sh query participants
select ledger, input the index:
INDEX LEDGER
0 j5sB3sVTFgTqTYzo7KtQjBLSy8YQGPpJpvQZaW9Eqk46dg
> 0
[{"address":"LdeNwsiuo7n6HULWhNKc87PBXJXAfGKFon9RE","id":2,"name":"2","participantNodeState":"CONSENSUS","pubKey":"7VeRFF1ednwhrFoe5cngKwPUJ2N4iFKD9Jt53GxSCc1MmPQ6"},{"address":"LdeNiXZbsBCsTc2ZGp1PGBX81aUxPekhwEwmY","id":1,"name":"1","participantNodeState":"CONSENSUS","pubKey":"7VeREmuT4fF9yRPEMbSSaNLKbLa3qoTpfGHRgwpnSWUn5tqW"},{"address":"LdeNwG6ECEGz57o2ufhwSbnW4C35TvPqANK7T","id":4,"name":"node4","participantNodeState":"READY","pubKey":"7VeRKiWHcHjNoYH9kJk2fxoJxgBrstVJ7bHRecKewJAKcvUD"},{"address":"LdeNyibeafrAQXgHjBxgQxoLbna6hL4BcXZiw","id":0,"name":"0","participantNodeState":"CONSENSUS","pubKey":"7VeRJpb2XX8XKAaC7G5zQg9DbgKM8gmLhUBtGFmerFbhJTZn"},{"address":"LdeP2ji8PR1DPsLt5NoFeiBnhpckrLHgCJge6","id":3,"name":"3","participantNodeState":"CONSENSUS","pubKey":"7VeRGE4V9MR7HgAqTrkxGvJvaaKRZ3fAjHUjYzpNBGcjfAvr"}]
register participant: [LdeNwG6ECEGz57o2ufhwSbnW4C35TvPqANK7T]
可以看出node4
注册成功,地址为LdeNwG6ECEGz57o2ufhwSbnW4C35TvPqANK7T
激活节点前请正确配置并启动新节点,以下以刚注册成功的node4
为例
node4
解压peer
压缩包,复制待加入账本其他节点中数据最新的节点数据库数据,然后修改config/ledger-binding.conf
:
# Base58编码的账本哈希
ledger.bindings=<账本hash>
# 账本名字,与账本相关的其他其他peer保持一致
binding.<账本HASH>.name=<节点名称>
# peer4的名名称,与[向现有共识网络注册新的参与方]操作中保持一致
binding.<账本hash>.parti.name=<节点名称>
# peer4的用户地址
binding.<账本hash>.parti.address=<peer4的用户地址>
# 新参与方base58编码的私钥,与[向现有共识网络注册新的参与方]操作中保持一致
binding.<账本hash>.parti.pk=<新参与方base58编码的私钥>
# 新参与方base58编码的私钥读取密码,与[向现有共识网络注册新的参与方]操作中保持一致
binding.<账本hash>.parti.pwd=<新参与方base58编码的私钥读取密码>
# 新参与方对应的账本数据库连接uri,即peer4的账本数据库存放位置,参照其他peer修改,不可与其他peer混用
binding.<账本hash>.db.uri=<账本数据库连接>
node4
执行peer4
中bin
目录下peer-startup.sh
脚本启动启动新参与方peer4
节点进程:
./peer-startup.sh
:bin$ ./jdchain-cli.sh participant active -h
Active participant.
Usage: jdchain-cli participant active [-hV] [--pretty] [--shutdown]
--consensus-port=<consensusPort>
[--home=<path>] --host=<host>
--ledger=<ledger> --port=<port>
--syn-host=<synHost> --syn-port=<synPort>
--consensus-port=<consensusPort>
Set the participant consensus port.
-h, --help Show this help message and exit.
--home=<path> Set the home directory.
--host=<host> Set the participant host.
--ledger=<ledger> Set the ledger.
--port=<port> Set the participant service port.
--pretty Pretty json print
--shutdown Restart the node server.
--syn-host=<synHost> Set synchronization participant host.
--syn-port=<synPort> Set synchronization participant port.
-V, --version Print version information and exit.
ledger
,账本哈希host
,新节点地址port
,新节点服务端口consensus-port
,新节点共识端口syn-host
,数据同步节点地址syn-port
,数据同步节点服务端口在账本j5sB3sVTFgTqTYzo7KtQjBLSy8YQGPpJpvQZaW9Eqk46dg
中激活node4
(以步骤2中启动的服务地址和端口为127.0.0.1
和7084
例),共识端口设置为10088
,同步节点地址和端口为127.0.0.1
和7080
为例:
:bin$./jdchain-cli.sh participant active --ledger j5sB3sVTFgTqTYzo7KtQjBLSy8YQGPpJpvQZaW9Eqk46dg --host 127.0.0.1 --port 7084 --consensus-port 10088 --syn-host 127.0.0.1 --syn-port 7080
participant activated
成功后可通过共识节点列表查询最新共识节点列表状态,node4
为CONSENSUS
通过激活节点操作除了激活新增的节点外,还可以动态修改已经处于激活状态的共识节点的IP
和共识端口
信息,从而实现本机的共识端口变更,不同机器之间进行账本迁移
。
| 在进行节点信息变更时,要求暂停向共识网络中发起新的业务数据上链请求
| 操作前请确保变更到的端口未被占用
如将node4
共识端口由10088
修改为10188
,操作指令如下:
:bin$./jdchain-cli.sh participant update --ledger j5sB3sVTFgTqTYzo7KtQjBLSy8YQGPpJpvQZaW9Eqk46dg --host 127.0.0.1 --port 7084 --consensus-port 10188 --syn-host 127.0.0.1 --syn-port 7080
participant updated
指令成功执行后,peer1
的共识端口将自动变更为10188
账本迁移指将一台机器(IP
)上的共识节点迁移到另一台机器(IP
)上,主要操作流程如下:
| 操作前请确保变更到的端口未被占用
如将node4
共识IP
由127.0.0.1
修改为192.168.1.100
(另一台机器),操作指令如下:
:bin$./jdchain-cli.sh participant update --ledger j5sB3sVTFgTqTYzo7KtQjBLSy8YQGPpJpvQZaW9Eqk46dg --host 192.168.1.100 --port 7084 --consensus-port 10188 --syn-host 127.0.0.1 --syn-port 7080 -shutdown
participant updated
特别注意:-shutdown
会停止当前运行的当前账本共识服务,为必填选项,否则可能将导致整个网络需要重启。
:bin$ ./jdchain-cli.sh participant inactive -h
Inactive participant.
Usage: jdchain-cli participant inactive [-hV] [--pretty] --address=<address>
[--home=<path>] --host=<host>
--ledger=<ledger> --port=<port>
--syn-host=<synHost>
--syn-port=<synPort>
--address=<address> Set the participant address.
-h, --help Show this help message and exit.
--home=<path> Set the home directory.
--host=<host> Set the participant host.
--ledger=<ledger> Set the ledger.
--port=<port> Set the participant service port.
--pretty Pretty json print
-V, --version Print version information and exit.
ledger
,账本哈希address
,待移除节点共识端口host
,待移除节点服务地址port
,待移除节点服务端口如移除node4
:
:bin$ ./jdchain-cli.sh participant inactive --ledger j5sB3sVTFgTqTYzo7KtQjBLSy8YQGPpJpvQZaW9Eqk46dg --address LdeNwG6ECEGz57o2ufhwSbnW4C35TvPqANK7T --host 127.0.0.1 --port 7084
participant inactivated
成功后可通过共识节点列表查询最新共识节点列表状态,node4
为DEACTIVATED