【PlatONE联盟链使用指南】链交互工具platonecli:节点与系统参数操作

200 阅读7分钟

PlatONE是由万向区块链和矩阵元共同打造的以隐私计算为特色的新一代联盟区块链平台,支持企业级应用,已在2019年9月正式开源并在实际产品中投入使用。目前,PlatONE的单链TPS已超过5万,已获得国家工业及信息化部认可并通过了中国电子技术标准化研究院的功能认证和测试认证。

我们将通过一系列科普文章,带领大家走进PlatONE,从入门到精通。上周我们已经介绍过防火墙相关的服务与操作,今天我们一起来了解如何通过链交互工具platonecil进行节点相关操作。

本文作者:万向区块链通用架构技术部

节点添加 node add

描述: 将节点添加到PlatONE网络中。没有被管理员添加到节点列表的节点无法参与PlatONE网络中节点的区块同步,共识等等。第一次被添加的节点类型都为观察者节点。观察者节点后续可以由管理员修改成为共识节点参与共识。

注解

  • 如果节点列表中已有同名且状态为有效的节点,则注册失败。

  • 如果节点列表中已有同公钥的节点(无论节点状态),则注册失败。

参数:

  • 必选参数:

    : 节点名称: 节点公钥,用于节点间安全通信。节点的公私钥对可由ethkey工具产生。: 节点外网IP: 节点内网IP

  • 可选参数:

    --rpcPort int: 用于rpc远程调用的网络端口,默认端口6791--p2pPort int: 用于p2p通信的网络端口,默认端口16791--desc string: 节点描述--delayNum : 共识节点延迟设置的区块高度,默认实时设置

操作:

./platonecli node add "test" "feffe2938d427088f5fcce94a9245760b92c468d3ca25ab5ef2b1cdccf0ed911963b74ca2dffef20ef135966e34ebcc905d1f12c1df09f05974a617cf8afe8e8" "127.0.0.1" "127.0.0.1" --keyfile ../conf/keyfile.json

输出结果:

{  "status": "Operation Succeeded",  "logs": [      "Event Notify: 0 add node success. node:{\"name\":\"test\",\"owner\":\"\",\"desc\":\"\",\"type\":0,\"status\":1,\"externalIP\":\"127.0.0.1\",\"internalIP\":\"127.0.0.1\",\"publicKey\":\"feffe2938d427088f5fcce94a9245760b92c468d3ca25ab5ef2b1cdccf0ed911963b74ca2dffef20ef135966e34ebcc905d1f12c1df09f05974a617cf8afe8e8\",\"rpcPort\":6791,\"p2pPort\":16791} "  ],  "blockNumber": 234,  "GasUsed": 118776,  "From": "0x8d4d2ed9ca6c6279bab46be1624cf7adbab89e18",  "To": "0x1000000000000000000000000000000000000002",  "TxHash": ""}

节点删除 node delete

描述: 将节点从节点列表中删除。在下一次peers更新后,被删除的节点会被PlatONE网络中的其他节点断开连接。

参数:

  • 必选参数:

    : 节点名称

操作:

./platonecli node delete "test" --keyfile ../conf/keyfile.json

注解

  • 不存在用户直接修改status的情况。确保status只能从1->2。

  • 状态修改后,节点的完整信息依旧可以通过query命令查询到

输出结果:

{  "status": "Operation Succeeded",  "logs": [      "Event Notify: 0 update node success. info:{\"status\":2} "  ],  "blockNumber": 235,  "GasUsed": 102932,  "From": "0x8d4d2ed9ca6c6279bab46be1624cf7adbab89e18",  "To": "0x1000000000000000000000000000000000000002",  "TxHash": ""}

节点信息查询 node query

描述: 通过查询键对节点信息进行查询,返回匹配成功的数据对象。

参数:

  • 可选参数:

    --all 查询键,查询所有节点(包含已被删除的节点)--name string: 查询键,通过节点名称进行查询(返回结果可能不唯一)--status string: 查询键,通过节点状态进行查询。valid(1)为有效状态,invalid(2)为无效(删除)状态--type string: 查询键,通过节点类型进行查询。observer(0)为观察者节点,consensus(1)为共识节点--publicKey string: 查询键,通过节点公钥进行查询(返回结果唯一)

操作:

## 返回网络中所有节点./platonecli node query --all --keyfile ../conf/keyfile.json## 根据查询键进行搜索./platonecli node query --name "test" --keyfile ../conf/keyfile.json​./platonecli node query --status "valid" --keyfile ../conf/keyfile.json​./platonecli node query --type "consensus" --keyfile ../conf/keyfile.json​./platonecli node query -publicKey feffe2938d427088f5fcce94a9245760b92c468d3ca25ab5ef2b1cdccf0ed911963b74ca2dffef20ef135966e34ebcc905d1f12c1df09f05974a617cf8afe8e8 --keyfile ../conf/keyfile.json## 组合查询./platonecli node query --status "valid" --name "root" --keyfile ../conf/keyfile.json

输出结果:

读操作

result: %s

示例

{  "code":0,  "msg":"success",  "data":[{    "name": ...,    "owner": ...,    "desc": ...,    "type": ...,    "publickey": ...,    "externalIP": ...,    "internalIP": ...,    "rpcPort": ...,    "p2pPort": ...,    "status": ...,    "delynum": `omitempty`    }  ]}

注解

无”approver”字段

节点统计 node stat

描述: 通过查询键对节点信息进行查询,对匹配成功的数据对象进行统计,返回统计值。

参数:

  • 可选参数:

    --status string: 查询键,通过节点状态进行统计。"valid"为有效状态(1),"invalid"为无效(删除)状态(2)--type string: 查询键,通过节点类型进行统计。"observer"为观察者节点(0),"consensus"为共识节点(1)

操作:

# 指定公钥对应的节点数目./platonecli  node stat --status "valid" --keyfile ../conf/keyfile.json

输出结果:

# 读操作* result: <num>

节点更新 node update

描述:

  • 更新节点的descdelayNumtype字段中的信息。无法更新权限同级及其以上角色节的信息。

  • 状态无效的节点依旧可以更新相应信息(bug?)

参数:

  • 必选参数:

    : 节点名称

  • 可选参数:

    --desc string: 节点描述--type string: 节点类型,"observer"(0)为观察者节点,"consensus"(1)为共识节点。--delay : 共识节点延迟设置的区块高度,默认实时设置

操作:

# 更新节点type信息./platonecli  node update "test" --type "consensus" --keyfile ../conf/keyfile.json# 更新节点desc信息./platonecli  node update "test" --desc "this is a description" --keyfile ../conf/keyfile.json  # 更新节点delayNum信息./platonecli  node update "test" --delay 10 --keyfile ../conf/keyfile.json

输出结果:

# 同步查询result: NodeManager update key: type

系统参数设置 sysconfig set

描述: 系统参数设置。

参数:

  • 可选参数:

    --block-gaslimit : the gas limit of the block--tx-gaslimit : the gas limit of transactions--tx-use-gas : if transactions use gas, 'use-gas' for transactions use gas, 'not-use' for not--audit-con : approve the deployed contracts, 'audit' for allowing contracts audit, 'not-audit' for not--check-perm : check the sender permission when deploying contracts, 'with-perm' for checking permission, 'without-perm' for not--empty-block : consensus produces empty block, 'allow-empty' for allowing to produce empty block, 'notallow-empty' for not--gas-contract : register the gas contract by contract name--vrf-params : modify vrf parameters

操作:

#注意一次只能操作一个系统参数./platonecli sysconfig set  --audit-con audit  --keyfile ../conf/keyfile.json

输出结果:

以audit-con为例

{  "status": "Operation Succeeded",  "logs": [      "Event IsApproveDeployedContract: 0 param set successful. "  ],  "blockNumber": 200,  "GasUsed": 103352,  "From": "0x8d4d2ed9ca6c6279bab46be1624cf7adbab89e18",  "To": "0x1000000000000000000000000000000000000004",  "TxHash": ""}

操作

./platonecli sysconfig set --vrf-params '{"electionEpoch":7,"nextElectionBlock":0,"validatorCount":3}' --keyfile ../conf/keyfile.json

系统参数获取 sysconfig get

描述: 系统参数获取。

参数:

  • 可选参数:

    --block-gaslimit : the gas limit of the block--tx-gaslimit : the gas limit of transactions--tx-use-gas : if transactions use gas, 'use-gas' for transactions use gas, 'not-use' for not--audit-con : approve the deployed contracts, 'audit' for allowing contracts audit, 'not-audit' for not--check-perm : check the sender permission when deploying contracts, 'with-perm' for checking permission, 'without-perm' for not--empty-block : consensus produces empty block, 'allow-empty' for allowing to produce empty block, 'notallow-empty' for not--gas-contract : register the gas contract by contract name--vrf-param : get vrf parameters

操作:

#注意一次只能获取一个系统参数./platonecli sysconfig get  --audit-con  --keyfile ../conf/keyfile.json

输出结果:

# 以audit-con为例result:IsApproveDeployedContract: audit

操作

./platonecli sysconfig get --vrf-params  --keyfile ../conf/keyfile.json