3. 长安链CMC工具(Cert)
3.1. 简介
cmc(ChainMaker Client)是ChainMaker提供的命令行工具,用于和ChainMaker链进行交互以及生成证书或者密钥等功能。cmc基于go语言编写,通过使用ChainMaker的go语言sdk(使用grpc协议)达到和ChainMaker链进行交互的目的。
cmc的详细日志请查看./sdk.log
长安链在2.1版本以后支持不同身份模式,详情见身份权限管理的身份模式部分。本篇文章中主要是介绍PermissionedWithCert模式,更多模式的cmc使用文档如下:
- PermissionedWithCert 
3.2. 编译&配置
cmc工具的编译&运行方式如下:
创建工作目录 $WORKDIR 比如 ~/chainmaker
启动测试链 在工作目录下 使用脚本搭建
# 编译cmc
$ cd $WORKDIR/chainmaker-go/tools/cmc
$ go build
# 配置测试数据
$ cp -rf $WORKDIR/chainmaker-go/build/crypto-config $WORKDIR/chainmaker-go/tools/cmc/testdata/ # 使用chainmaker-cryptogen生成的测试链的证书
# 查看help
$ cd $WORKDIR/chainmaker-go/tools/cmc
$ ./cmc --help
3.3. 自定义配置
cmc 依赖 sdk-go 配置文件。
编译&配置 步骤使用的是 SDK配置模版 
可通过修改 ~/chainmaker/chainmaker-go/tools/cmc/testdata/sdk_config.yml 实现自定义配置。
比如 user_key_file_path,user_crt_file_path,user_sign_key_file_path,user_sign_crt_file_path
这四个参数可设置为普通用户或admin用户的证书/私钥路径。设置后cmc将会以对应用户身份与链建立连接。
其他详细配置项请参看 ~/chainmaker/chainmaker-go/tools/cmc/testdata/sdk_config.yml 中的注解。
3.4. 功能
cmc提供功能如下:
- 私钥管理:私钥生成功能 
- 证书管理:包括生成ca证书、生成crl列表、生成csr、颁发证书、根据证书获取节点Id等功能 
- 交易功能:主要包括链管理、用户合约发布、升级、吊销、冻结、调用、查询等功能 
- 查询链上数据:查询链上block和transaction 
- 链配置:查询及更新链配置 
- 归档&恢复功能:将链上数据转移到独立存储上,归档后的数据具备可查询、可恢复到链上的特性 
- 线上多签:通过系统合约实现线上多签的请求发起、投票和查询等功能 
- 系统合约开放管理:管理系统合约的开放权限、查询弃用系统合约列表 
- 证书别名:证书别名管理。 
- 地址转换:根据证书或公钥生成地址 
- 交易池:交易池相关查询命令 
- gas管理:gas管理类命令,包括设置 gas admin、充值 gas 等功能 
- 交易ID黑名单管理:开启、关闭、添加、删除查询等功能 
- 链上权限管理:链上权限策略的新增、修改等功能 
- 共识扩展数据管理:链上共识扩展数据的新增、修改等功能 
3.4.1. 示例
3.4.1.1. 私钥管理
生成私钥, 目前支持的算法有 SM2 ECC_P256 未来将支持更多算法。
参数说明:
./cmc key gen -h 
# 返回
Private key generate
Usage:
  cmc key gen [flags]
Flags:
  -a, --algo string   specify key generate algorithm
  -h, --help          help for gen
  -n, --name string   specify storage name
  -p, --path string   specify storage path
示例:
./cmc key gen -a ECC_P256 -n ca.key -p ./
3.4.1.2. 证书管理
- 生成crl(Certificate Revocation List)列表 - crl列表用于撤消证书请求,首先将要撤消的证书生成一个crl列表,然后再发送请求到链上 - 参数说明 - ./cmc cert crl -h - # 返回 create cert crl Usage: cmc cert crl [flags] Flags: -C, --ca-cert-path string specify certificate authority certificate path -K, --ca-key-path string specify certificate authority key path --crl-path string specify crl file path --crt-path string specify crt file path -h, --help help for crl - 示例 - ./cmc cert crl -C ./testdata/crypto-config/wx-org2.chainmaker.org/ca/ca.crt -K ./testdata/crypto-config/wx-org2.chainmaker.org/ca/ca.key --crl-path=./client1.crl --crt-path=./testdata/crypto-config/wx-org2.chainmaker.org/user/client1/client1.sign.crt 
- 吊销证书 - 将crl发送到链上,吊销证书 - 参数说明 - ./cmc client certmanage revoke -h - 示例 - ./cmc client certmanage revoke \ --sdk-conf-path=./testdata/sdk_config.yml \ --cert-crl-path=./client1.crl \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key 
- 冻结链上证书 - ./cmc client certmanage freeze \ --sdk-conf-path=./testdata/sdk_config.yml \ --cert-file-paths=./mycert.cert \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key 
- 解冻链上证书 - ./cmc client certmanage unfreeze \ --sdk-conf-path=./testdata/sdk_config.yml \ --cert-file-paths=./mycert.cert \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key 
3.4.1.3. 交易功能
3.4.1.3.1. 用户合约
cmc的交易功能用来发送交易和链进行交互,主要参数说明如下:
  sdk配置文件flag
  --sdk-conf-path: 指定cmc使用sdk的配置文件路径
  admin签名者flags,此类flag的顺序及个数必须保持一致,且至少传入一个admin
  --admin-crt-file-paths: admin签名者的crt文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
      比如 ./wx-org1.chainmaker.org/admin1.sign.crt,./wx-org2.chainmaker.org/admin1.sign.crt
  --admin-key-file-paths: admin签名者的key文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
      比如 ./wx-org1.chainmaker.org/admin1.sign.key,./wx-org2.chainmaker.org/admin1.sign.key
  如果想覆盖sdk配置文件中的配置,则使用以下六个flag且都必填;如不传,则默认使用sdk配置文件中的配置参数
  --org-id: 指定发送交易的用户所属的组织Id, 会覆盖sdk配置文件读取的配置
  --chain-id: 指定链Id, 会覆盖sdk配置文件读取的配置
  --user-tlscrt-file-path: 指定发送交易的用户tls证书文件路径, 会覆盖sdk配置文件读取的配置
  --user-tlskey-file-path: 指定发送交易的用户tls私钥路径, 会覆盖sdk配置文件读取的配置
  --user-signcrt-file-path: 指定发送交易的用户sign证书文件路径, 会覆盖sdk配置文件读取的配置
  --user-signkey-file-path: 指定发送交易的用户sign私钥路径, 会覆盖sdk配置文件读取的配置
  其他flags
  --byte-code-path:指定合约的wasm文件路径
  --contract-name:指定合约名称
  --method:指定调用的合约方法名称
  --runtime-type:指定合约执行虚拟机环境,如 WASMER | EVM | DOCKER_GO 等
  --version:指定合约的版本号,在发布和升级合约时使用
  --sync-result:指定是否同步等待交易执行结果,默认为false,如果设置为true,在发送完交易后会主动查询交易执行结果
  --params:指定发布合约或调用合约时的参数信息
  --concurrency:指定调用合约并发的go routine,用于压力测试
  --total-count-per-goroutine:指定单个go routine发送的交易数量,用于压力测试,和--concurrency配合使用
  --block-height:指定区块高度
  --tx-id:指定交易Id
  --with-rw-set:指定获取区块时是否附带读写集,默认是false
  --abi-file-path:调用evm合约时需要指定被调用合约的abi文件路径,如:--abi-file-path=./testdata/balance-evm-demo/ledger_balance.abi
- 创建wasm合约 - ./cmc client contract user create \ --contract-name=fact \ --runtime-type=WASMER \ --byte-code-path=./testdata/claim-wasm-demo/rust-fact-2.0.0.wasm \ --version=1.0 \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true \ --params="{}" 
- 创建evm合约 - ./cmc client contract user create \ --contract-name=balance001 \ --runtime-type=EVM \ --byte-code-path=./testdata/balance-evm-demo/ledger_balance.bin \ --abi-file-path=./testdata/balance-evm-demo/ledger_balance.abi \ --version=1.0 \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true 
- 调用wasm合约 - ./cmc client contract user invoke \ --contract-name=fact \ --method=save \ --sdk-conf-path=./testdata/sdk_config.yml \ --params="{\"file_name\":\"name007\",\"file_hash\":\"ab3456df5799b87c77e7f88\",\"time\":\"6543234\"}" \ --sync-result=true 
- 调用evm合约 - evm的 –params 是一个数组json格式。如下updateBalance有两个形参,第一个是uint256类型,第二个是address类型。 
 10000对应第一个形参uint256的具体值,a166c92f4c8118905ad984919dc683a7bdb295c1对应第二个形参address的具体值。- ./cmc client contract user invoke \ --contract-name=balance001 \ --method=updateBalance \ --sdk-conf-path=./testdata/sdk_config.yml \ --params="[{\"uint256\": \"10000\"},{\"address\": \"a166c92f4c8118905ad984919dc683a7bdb295c1\"}]" \ --sync-result=true \ --abi-file-path=./testdata/balance-evm-demo/ledger_balance.abi 
- 查询合约 - ./cmc client contract user get \ --contract-name=fact \ --method=find_by_file_hash \ --sdk-conf-path=./testdata/sdk_config.yml \ --params="{\"file_hash\":\"ab3456df5799b87c77e7f88\"}" 
- 升级合约 - ./cmc client contract user upgrade \ --contract-name=fact \ --runtime-type=WASMER \ --byte-code-path=./testdata/claim-wasm-demo/rust-fact-2.0.0.wasm \ --version=2.0 \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --org-id=wx-org1.chainmaker.org \ --sync-result=true \ --params="{}" 
- 冻结合约 - ./cmc client contract user freeze \ --contract-name=fact \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --org-id=wx-org1.chainmaker.org \ --sync-result=true 
- 解冻合约 - ./cmc client contract user unfreeze \ --contract-name=fact \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --org-id=wx-org1.chainmaker.org \ --sync-result=true 
- 吊销合约 - ./cmc client contract user revoke \ --contract-name=fact \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --org-id=wx-org1.chainmaker.org \ --sync-result=true 
- 合约名转换成合约地址 - –address-type=0 是长安链地址类型;–address-type=1 是至信链地址类型 - ./cmc client contract name-to-addr fact --address-type=0 
3.4.1.4. 查询链上数据
查询链上block和transaction 主要参数说明如下:
  --sdk-conf-path:指定cmc使用sdk的配置文件路径
  --chain-id:指定链Id
- 根据区块高度查询链上未归档区块 - #如果不传 blockheight 表示查询最高区块 ./cmc query block-by-height [blockheight] \ --chain-id=chain1 \ --sdk-conf-path=./testdata/sdk_config.yml 
- 根据区块hash查询链上未归档区块 - ./cmc query block-by-hash [blockhash] \ --chain-id=chain1 \ --sdk-conf-path=./testdata/sdk_config.yml 
- 根据txid查询链上未归档区块 - ./cmc query block-by-txid [txid] \ --chain-id=chain1 \ --sdk-conf-path=./testdata/sdk_config.yml 
- 根据txid查询链上未归档tx - ./cmc query tx [txid] \ --chain-id=chain1 \ --sdk-conf-path=./testdata/sdk_config.yml 
3.4.1.5. 链配置
查询及更新链配置 主要参数说明如下:
  sdk配置文件flag
  --sdk-conf-path: 指定cmc使用sdk的配置文件路径
  admin签名者flags,此类flag的顺序及个数必须保持一致,且至少传入一个admin
  --admin-crt-file-paths: admin签名者的crt文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
      比如 ./wx-org1.chainmaker.org/admin1.sign.crt,./wx-org2.chainmaker.org/admin1.sign.crt
  --admin-key-file-paths: admin签名者的key文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
      比如 ./wx-org1.chainmaker.org/admin1.sign.key,./wx-org2.chainmaker.org/admin1.sign.key
  如果想覆盖sdk配置文件中的配置,则使用以下六个flag且都必填;如不传,则默认使用sdk配置文件中的配置参数
  --org-id: 指定发送交易的用户所属的组织Id, 会覆盖sdk配置文件读取的配置
  --chain-id: 指定链Id, 会覆盖sdk配置文件读取的配置
  --user-tlscrt-file-path: 指定发送交易的用户tls证书文件路径, 会覆盖sdk配置文件读取的配置
  --user-tlskey-file-path: 指定发送交易的用户tls私钥路径, 会覆盖sdk配置文件读取的配置
  --user-signcrt-file-path: 指定发送交易的用户sign证书文件路径, 会覆盖sdk配置文件读取的配置
  --user-signkey-file-path: 指定发送交易的用户sign私钥路径, 会覆盖sdk配置文件读取的配置
  --block-interval: 出块时间 单位ms
  --tx-parameter-size: 交易参数最大限制 单位:MB
  --trust-root-org-id: 增加/删除/更新组织证书时指定的组织Id
  --trust-root-path: 组织根证书目录
  --trust-member-path: 增加/删除外部证书时指定的证书路径
  --trust-member-org-id: 增加外部证书时指定的组织Id
  --trust-member-role: 增加外部证书时指定的角色
  --trust-member-node-id: 增加外部证书时指定的nodeId
  --node-id: 增加/删除/更新共识节点Id时指定的节点Id
  --node-ids: 增加/更新共识节点Org时指定的节点Id列表
  --node-org-id: 增加/删除/更新共识节点Id,Org时指定节点的组织Id 
  --address-type: 地址类型 ChainMaker:0, 至信链:1
  --block-timestamp-verify: 是否开启区块时间戳校验(true为校验,false为不校验)
  --block-timeout:区块时间戳校验范围(只在开启区块时间戳校验功能后生效,规则:|当前时间-区块时间戳中时间| <= blockTimeOut)
- 查询链配置 - ./cmc client chainconfig query \ --sdk-conf-path=./testdata/sdk_config.yml 
- 查询链权限列表 - ./cmc client chainconfig permission list --sdk-conf-path=./testdata/sdk_config.yml 
- 更新出块时间 - ./cmc client chainconfig block updateblockinterval \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --block-interval 1000 
- 更新交易参数最大值限制 - ./cmc client chainconfig block updatetxparametersize \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --tx-parameter-size 10 
- 开启区块时间戳校验 - ./cmc client chainconfig block updateblocktimestamp \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --block-timestamp-verify=true \ --block-timeout=10 
- 增加组织根证书 - ./cmc client chainconfig trustroot add \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --trust-root-org-id=wx-org5.chainmaker.org \ --trust-root-path=./testdata/crypto-config/wx-org5.chainmaker.org/ca/ca.crt 
- 删除组织根证书 - ./cmc client chainconfig trustroot remove \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --trust-root-org-id=wx-org5.chainmaker.org 
- 更新组织根证书 - ./cmc client chainconfig trustroot update \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org5.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org5.chainmaker.org/user/admin1/admin1.sign.key \ --trust-root-org-id=wx-org5.chainmaker.org \ --trust-root-path=./testdata/crypto-config/wx-org5.chainmaker.org/ca/ca.crt 
- 增加第三方证书信息 - ./cmc client chainconfig trustmember add \ --sdk-conf-path=./testdata/sdk_config.yml \ --org-id=wx-org1.chainmaker.org \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --trust-member-org-id=wx-org2.chainmaker.org \ --trust-member-path=./testdata/trust-member-demo/node1-sign.pem \ --trust-member-role=admin \ --trust-member-node-id=QmYcfSHGiXjHKkHo65YfxWLT6G7B81Zct7F7ep8GWFtuUK 
- 删除第三方证书信息 - ./cmc client chainconfig trustmember remove \ --sdk-conf-path=./testdata/sdk_config.yml \ --org-id=wx-org1.chainmaker.org \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --trust-member-path=./testdata/trust-member-demo/node1-sign.pem 
- 添加共识节点Org - ./cmc client chainconfig consensusnodeorg add \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --node-ids=QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4,QmaWrR72CbT51nFVpNDS8NaqUZjVuD4Ezf8xcHcFW9SJWF \ --node-org-id=wx-org5.chainmaker.org 
- 删除共识节点Org - ./cmc client chainconfig consensusnodeorg remove \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --node-org-id=wx-org5.chainmaker.org 
- 更新共识节点Org - ./cmc client chainconfig consensusnodeorg update \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --node-ids=QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4,QmaWrR72CbT51nFVpNDS8NaqUZjVuD4Ezf8xcHcFW9SJWF \ --node-org-id=wx-org5.chainmaker.org 
- 添加共识节点Id - ./cmc client chainconfig consensusnodeid add \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --node-id=QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 \ --node-org-id=wx-org5.chainmaker.org 
- 删除共识节点Id - ./cmc client chainconfig consensusnodeid remove \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --node-id=QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 \ --node-org-id=wx-org5.chainmaker.org 
- 更新共识节点Id - ./cmc client chainconfig consensusnodeid update \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-crt-file-paths=./testdata/crypto-config/wx-org5.chainmaker.org/user/admin1/admin1.sign.crt \ --admin-key-file-paths=./testdata/crypto-config/wx-org5.chainmaker.org/user/admin1/admin1.sign.key \ --node-id=QmetNaPLH73r8GBACZTWTMn6ZsU7v7aaapnqA3EpFs5jsw \ --node-id-old=QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4 \ --node-org-id=wx-org5.chainmaker.org 
- 添加一条新链 
修改chainmaker配置文件
在chainmaker.yml的头部将新链的Id和创世块配置添加进去,如下:
blockchain:
  - chainId: chain1
    genesis: ../config/wx-org1/chainconfig/bc1.yml
  - chainId: chain2
    genesis: ../config/wx-org1/chainconfig/bc2.yml
- 使用cmc工具触发chainmaker初始化新链,命令如下: - ./cmc client blockchains checknew --sdk-conf-path=./testdata/sdk_config.yml 
- (v2.4.0+版本中)使用cmc工具触发chainmaker初始化新链(同时更新seeds和custom_chain_trust_roots),命令如下: - ./cmc client blockchains update_node_config --sdk-conf-path=./testdata/sdk_config.yml 
- 开启只允许创建者升级合约功能 - ./cmc client contract user invoke \ --contract-name=CHAIN_CONFIG \ --method=ENABLE_ONLY_CREATOR_UPGRADE \ --sdk-conf-path=./testdata/sdk_config.yml \ --params="{}" \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true \ --result-to-string=true 
- 关闭只允许创建者升级合约功能 - ./cmc client contract user invoke \ --contract-name=CHAIN_CONFIG \ --method=DISABLE_ONLY_CREATOR_UPGRADE \ --sdk-conf-path=./testdata/sdk_config.yml \ --params="{}" \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true \ --result-to-string=true 
3.4.1.6. 归档&恢复功能
cmc的归档功能是指将链上数据转移到独立存储上,归档后的数据具备可查询、可恢复到链上的特性。
为了保持数据一致性和防止误操作,cmc实现了分布式锁,同一时刻只允许一个cmc进程进行转储。
cmc支持增量转储和恢复、断点中继转储和恢复,中途退出不影响数据一致性。
3.4.1.6.1. Dump(在归档中心和链外mysql中选择一种使用)
dump指令从链节点上查询数据,将数据写入到链外存储(当前支持MySQL和归档中心)
- Dump 到链外数据仓库 
注意:mysql需要设置好 sql_mode 以root用户执行 set global sql_mode = ‘ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION’;
- 链外mysql: sdk_config.yaml - archive: type: "mysql" dest: "root:123456:localhost:3306"
- 链外mysql: 数据表设计说明 - 表信息  
- 表字段  
 
- Dump归档中心: sdk_config.yml(推荐使用) - archive: type: "archivecenter" # archivecenter 归档中心, mysql mysql数据库- 注册链到归档中心 
 - # 获取创世区块 ./cmc query block-by-height 0 --chain-id=chain1 --sdk-conf-path=./testdata/sdk_config.yml - # 根据上面获取的创世区块拿到block_hash(如: PnipOpT7Et8m5sqdHuanYIwibSBZmZaXafhublJowVE=) ./cmc util base64tohex PnipOpT7Et8m5sqdHuanYIwibSBZmZaXafhublJowVE= - # 返回 (获取返回的创世区块hash的hex格式数据: 3e78a93a94fb12df26e6ca9d1ee6a7608c226d205999969769f86e6e5268c151) - 将上面获得的创世区块hash的hex格式数据放到sdk_config.yml中 
 - archive_center_config: chain_genesis_hash: 3e78a93a94fb12df26e6ca9d1ee6a7608c226d205999969769f86e6e5268c151 - dump数据 
 - # 转存区块到链外存储 ./cmc archive dump 100 --sdk-conf-path ./testdata/sdk_config.yml --mode quick - # 查询归档中心当前已归档数据状态 ./cmc archive query archived-status --sdk-conf-path ./testdata/sdk_config.yml 
3.4.1.6.2. 节点归档
archive指令向链节点发送清理区块数据命令
# 查询链上当前已归档数据状态命令
./cmc archive query chain-archived-status --sdk-conf-path ./testdata/sdk_config.yml
# 清理链上区块数据命令
./cmc archive archive 10000 --timeout 20  --sdk-conf-path ./testdata/sdk_config.yml
3.4.1.6.3. 节点数据恢复
restore指令从链外存储(MySQL/归档中心)中查询出区块数据,将区块数据恢复到链节点上
# 恢复链上区块数据命令,恢复到指定高度,恢复过程按照区块块高倒序恢复
./cmc archive restore 3000 --sdk-conf-path ./testdata/sdk_config.yml
3.4.1.6.4. 数据仓库数据查询
# 查询归档中心当前已归档数据状态命令
./cmc archive query archived-status --sdk-conf-path ./testdata/sdk_config.yml
# 查询归档中心,根据高度查区块命令
./cmc archive query block-by-height 20  --sdk-conf-path ./testdata/sdk_config.yml
# 查询归档中心,根据txId查询区块命令
./cmc archive query block-by-txid 17221b132a25209aca52fdfc07218265e4377ef0099d46a49edfd032001fc2be --sdk-conf-path ./testdata/sdk_config.yml
# 查询归档中心,根据txId查询交易命令
./cmc archive query tx 17221b132a25209aca52fdfc07218265e4377ef0099d46a49edfd032001fc2be  --sdk-conf-path ./testdata/sdk_config.yml
# 查询归档中心,根据block hash查询区块命令
./cmc archive query block-by-hash 17221b132a25209aca52fdfc07218265e4377ef0099d46a49edfd032001fc2be --sdk-conf-path ./testdata/sdk_config.yml
3.4.1.7. 线上多签
当合约调用(目前仅适用合约管理场景)需要多个用户同时签名才能生效时,可使用线上多签功能。
线上多签有两个版本,一个是两段式多签,一个是三段式多签:
- 两段式多签的含义是:用户发起多签请求,当投票人完成投票后,会自动触发多签请求的执行。整个过程分成”多签请求”、”多签投票”两个过程。 
- 三段式多签的含义是:用户发起多签请求,当投票人完成投票后,多签请求不会被触发执行,需要请求发起人手动触发”多签请求”的执行,整个过程分成”多签请求”、”多签投票”、”多签执行”三个过程。 
 
长安链运行的是”两段式多签”还是”三段式多签”是通过 enable_manual_run 配置项控制的,enable_manual_run = true 表示当前链是使用的三段式多签,enable_manual_run = false 表示使用的是两段式多签。
enable_manual_run 标志位可以写在 bc1.yml 中,作为链初始化的配置,配置方式如下:
# Virtual machine related settings
vm:
  addr_type: 2
  support_list:
    - "wasmer"
    - "gasm"
    - "evm"
    - "dockergo"
    - "wxvm"
  native:
      multisign:
        enable_manual_run: true
也可以在运行过程中,通过 cmc 命令动态调节。
主要参数说明如下:
--sdk-conf-path:指定cmc使用sdk的配置文件路径
--tx-id:指定交易Id
--params:指定发布合约或调用合约时的参数信息
  其格式为:
        {"key":"SYS_CONTRACT_NAME","value":"contractName","IsFile":false}
  其中固定参数:`SYS_CONTRACT_NAME` 被调用的合约名称
              `SYS_METHOD` 被调用的合约方法
                若`IsFile`为true,则value字段请填写文件路径
              其余均为该合约方法所需要的参数
--is-agree: 多签投票时是否同意,true为同意(默认设为true),false为反对
admin签名者flags,此类flag的顺序及个数必须保持一致,且至少传入一个admin
--admin-crt-file-paths: admin签名者的crt文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
     比如 ./wx-org1.chainmaker.org/admin1.sign.crt,./wx-org2.chainmaker.org/admin1.sign.crt
--admin-key-file-paths: admin签名者的key文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
     比如 ./wx-org1.chainmaker.org/admin1.sign.key,./wx-org2.chainmaker.org/admin1.sign.key
- 发起线上多签请求(以创建一个普通的用户合约为例,当参数需要从文件中读取时设置IsFile的值为true) - ./cmc client contract system multi-sign req \ --sdk-conf-path=./testdata/sdk_config.yml \ --params="[{\"key\":\"SYS_CONTRACT_NAME\",\"value\":\"CONTRACT_MANAGE\",\"IsFile\":false},{\"key\":\"SYS_METHOD\",\"value\":\"INIT_CONTRACT\",\"IsFile\":false},{\"key\":\"CONTRACT_NAME\",\"value\":\"contract107\",\"IsFile\":false},{\"key\":\"CONTRACT_VERSION\",\"value\":\"1.0\",\"IsFile\":false},{\"key\":\"CONTRACT_BYTECODE\",\"value\":\"./testdata/claim-wasm-demo/rust-fact-2.0.0.wasm\",\"IsFile\":true},{\"key\":\"CONTRACT_RUNTIME_TYPE\",\"value\":\"WASMER\",\"IsFile\":false}]" 
- 发起线上多签投票 - ./cmc client contract system multi-sign vote \ --sdk-conf-path=./testdata/sdk_config.yml \ --is-agree=true \ --admin-key-file-paths=./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --tx-id=05a0e329c4c94e909575214b41ca516716bd8c83dea94c4c9616dea0910bf719 
- 触发多签请求执行 - ./cmc client contract system multi-sign trig \ --sdk-conf-path=./testdata/sdk_config.yml \ --tx-id=05a0e329c4c94e909575214b41ca516716bd8c83dea94c4c9616dea0910bf719 \ --gas-limit=20000 
- 根据交易Id查询线上多签交易信息 - ./cmc client contract system multi-sign query \ --sdk-conf-path=./testdata/sdk_config.yml \ --truncate-value-len=1024 \ --truncate-model=truncate \ --tx-id=05a0e329c4c94e909575214b41ca516716bd8c83dea94c4c9616dea0910bf719 - 注意:truncate-value-len=1024 是截断参数,表示如果返回多签请求的长度超过1024,则按照 truncate-model 指定的模式(truncate|empty|hash)进行字符串截取。 
- 设置 enable_manual_run 标志位 - ./cmc client chainconfig enable-manual-run \ --multi-sign-enable-manual-run=false \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
3.4.1.8. 系统合约开放管理
对系统合约的开放权限进行管理功能
主要参数说明如下:
--sdk-conf-path:指定cmc使用sdk的配置文件路径
--grant-contract-list:指定需要开放的系统合约列表,以逗号分割合约名称
--revoke-contract-list:指定需要弃用的系统合约列表,以逗号分割合约名称
admin签名者flags,此类flag的顺序及个数必须保持一致,且至少传入一个admin
--admin-crt-file-paths: admin签名者的crt文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
    比如 ./wx-org1.chainmaker.org/admin1.sign.crt,./wx-org2.chainmaker.org/admin1.sign.crt
--admin-key-file-paths: admin签名者的key文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
    比如 ./wx-org1.chainmaker.org/admin1.sign.key,./wx-org2.chainmaker.org/admin1.sign.key
- 开放系统合约 - ./cmc client contract system manage access-grant \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --grant-contract-list=DPOS_ERC20,DPOS_STAKE 
- 弃用系统合约 - ./cmc client contract system manage access-revoke \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --revoke-contract-list=DPOS_ERC20,DPOS_STAKE 
- 查询弃用的系统合约列表 - ./cmc client contract system manage access-query \ --sdk-conf-path=./testdata/sdk_config.yml 
3.4.1.9. 证书别名
证书别名管理。包括添加别名,更新别名的证书,查询别名详细信息,删除别名。
1.证书别名只支持PermissionedWithCert模式的网络
2.需要提前设置sdk配置文件中alias,比如设置为 tools/testdata/sdk_config.yml 中 alias: my_cert_alias
主要参数说明如下:
  --sdk-conf-path:指定cmc使用sdk的配置文件路径
  --cert-alias:查询/更新/删除 时 指定的别名
  --new-cert-path:更新 时 指定的新证书路径
  --sync-result:指定是否同步等待交易执行结果,默认为false,如果设置为true,在发送完交易后会主动查询交易执行结果
  admin签名者flags,此类flag的顺序及个数必须保持一致,且至少传入一个admin
  --admin-crt-file-paths: admin签名者的crt文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
      比如 ./wx-org1.chainmaker.org/admin1.sign.crt,./wx-org2.chainmaker.org/admin1.sign.crt
  --admin-key-file-paths: admin签名者的key文件的路径列表. 单签模式下只需要填写一个即可, 离线多签模式下多个需要用逗号分割
      比如 ./wx-org1.chainmaker.org/admin1.sign.key,./wx-org2.chainmaker.org/admin1.sign.key
- 添加别名 - sdk配置文件sdk_config.yml中alias字段配置好后,cmc每次请求链节点时,将自动检查链上是否已添加此别名,如果没有则自动上链此证书别名。 
- 查询别名 - ./cmc client certalias query --cert-alias=my_cert_alias --sdk-conf-path=./testdata/sdk_config.yml 
- 更新指定别名所关联的证书 - ./cmc client certalias update --cert-alias=my_cert_alias \ --new-cert-path=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true 
- 删除别名 - ./cmc client certalias delete --cert-alias=my_cert_alias \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true 
3.4.1.10. 地址转换
转换成长安链等类型的地址
--hash-type: 指定根据公钥计算地址时使用的 Hash 算法类型, 默认为 0 ,即SAH256。所支持的 Hash 类型如下:
0: SHA256
1: SHA3_256
2: SM3
- public key DER hex转换成地址 - ./cmc address hex-to-addr 3059301306072a8648ce3d020106082a811ccf5501822d034200044a4c24cf037b0c7a027e634b994a5fdbcd0faa718ce9053e3f75fcb9a865523a605aff92b5f99e728f51a924d4f18d5819c42f9b626bdf6eea911946efe7442d \ --hash-type=0 
- 证书pem转换成地址 - ./cmc address cert-to-addr ./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt 
- 合约名转换成地址 - ./cmc address name-to-addr my_cool_contract_name 
3.4.1.11. 交易池
交易池相关查询命令
--sdk-conf-path:指定cmc使用sdk的配置文件路径
--type:指定查询的交易类型, 默认值 3 。所支持的类型如下:
配置交易类型: 1
普通交易类型: 2
所有交易类型: 3
--stage: 指定查询的交易阶段, 默认值 3 。所支持的阶段如下:
in queue阶段: 1
in pending阶段: 2
所有阶段: 3
--tx-ids: 指定根据tx ids获取交易池中存在的txs, 可指定多个txid用逗号分开
- 查询交易池状态 - ./cmc txpool status --sdk-conf-path=./testdata/sdk_config.yml 
- 查询不同交易类型和阶段中的交易Id列表。 - ./cmc txpool txids --sdk-conf-path=./testdata/sdk_config.yml --type=3 --stage=3 
- 根据txIds获取交易池中存在的txs,并返回交易池缺失的tx的txIds - ./cmc txpool txs --sdk-conf-path=./testdata/sdk_config.yml \ --tx-ids="00722edd0da0465fbadaadddcd31be20d24575c42e5246e697a0629b649d20e8,ec366ae0b7024d15a74668846007107284e99f9f2f6544d0bf1a3aee11a50712" 
3.4.1.12. gas管理
gas管理类命令,包括设置 gas admin、充值 gas 等功能
  --sdk-conf-path:指定cmc使用sdk的配置文件路径
  --admin-key-file-paths:多签时,其他admin的私钥路径,多个时用逗号分开,需要与admin-crt-file-paths顺序一致
  --admin-crt-file-paths:多签时,其他admin的证书路径,多个时用逗号分开,需要与admin-key-file-paths顺序一致
- 启用 gas 功能 - ./cmc client gas --gas-enable=true \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
- 设置 gas admin - ./cmc gas set-admin [gas账号地址。如果不传则默认设置sender为 gas admin] \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
- 查询 gas admin - ./cmc gas get-admin --sdk-conf-path=./testdata/sdk_config.yml 
- 充值 gas - ./cmc gas recharge \ --sdk-conf-path=./testdata/sdk_config.yml \ --address=账户地址 \ --amount=1000000 
- 查询 gas 余额 - ./cmc gas get-balance \ --sdk-conf-path=./testdata/sdk_config.yml \ --address=账户地址 
- 退还 gas - ./cmc gas refund \ --sdk-conf-path=./testdata/sdk_config.yml \ --address=账户地址 \ --amount=1 
- 冻结 gas 账户 - ./cmc gas frozen \ --sdk-conf-path=./testdata/sdk_config.yml \ --address=账户地址 
- 解冻 gas 账户 - ./cmc gas unfrozen \ --sdk-conf-path=./testdata/sdk_config.yml \ --address=账户地址 
- 查询 gas 账户的状态,true:账户可用,false:账户被冻结 - ./cmc gas account-status \ --sdk-conf-path=./testdata/sdk_config.yml \ --address=账户地址 
- 设置合约调用时使用的基础 gas 值 - ./cmc gas set-default-gas \ --sdk-conf-path=./testdata/sdk_config.yml \ --amount=2 \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true 
- 设置合约调用时用于计算的 gas 价格 - ./cmc gas set-default-gas-price \ --sdk-conf-path=./testdata/sdk_config.yml \ --price=0.2 \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true 
- 设置合约安装时使用的基础 gas 值 - ./cmc gas set-install-base-gas \ --sdk-conf-path=./testdata/sdk_config.yml \ --amount=200000 \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true 
- 设置合约安装时用于计算的 gas 价格 - ./cmc gas set-install-gas-price \ --sdk-conf-path=./testdata/sdk_config.yml \ --price=0.1 \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt \ --sync-result=true 
- gas 代扣功能 - cmc 命令支持用户自主设置扣费账号,支付交易费用,命令如下: - ./cmc client contract user invoke \ --contract-name=fact \ --method=save \ --sdk-conf-path=./testdata/sdk_config.yml \ --params="{\"file_name\":\"name007\",\"file_hash\":\"ab3456df5799b87c77e7f88\",\"time\":\"6543234\"}" \ --payer-org-id="wx-org2.chainmaker.org" \ --payer-crt-file-path=./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt \ --payer-key-file-path=./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key \ --gas-limit=600000 \ --sync-result=true - 其中, –payer-org-id, –payer-crt-file-path, –payer-key-file-path 三个参数指定的是支付该笔交易费用的账号对应的证书以及私钥文件 
3.4.1.13. 交易ID黑名单管理
v2.3.2新功能
可实现如下功能:
全链所有节点在查询黑名单内的交易、区块、订阅时缺失某些字段,并替换为该交易违规,内容已屏蔽字样。
其管理员权限复用gas管理员权限(sdk_config_pk的sign path需要用gas管理员方可添加、删除交易ID黑名单),详见上方gas管理。
- 添加交易ID黑名单 
添加交易ID黑名单,以逗号分隔交易id(sdk_config.yml中的sign key/crt需要用gas管理员的)
./cmc client contract user invoke \
--contract-name=TRANSACTION_MANAGER \
--method=ADD_BLACKLIST_TX_IDS \
--sdk-conf-path=./testdata/sdk_config.yml \
--params="{\"txIds\":\"174ef6a4eb8ef354caf90589ec63287c4e0890f33b0c4caea31c461ed0c5453b,174e5c8e4dd8c58ccac99b9b6dde5b5bbec3c48cc6c44e269e4b7ad456beddb0\"}" \
--sync-result=true \
--result-to-string=true
- 删除交易ID黑名单 
./cmc client contract user invoke \
--contract-name=TRANSACTION_MANAGER \
--method=DELETE_BLACKLIST_TX_IDS \
--sdk-conf-path=./testdata/sdk_config.yml \
--params="{\"txIds\":\"174ef6a4eb8ef354caf90589ec63287c4e0890f33b0c4caea31c461ed0c5453b,174e4e556f3ccb0cca6d9aee6d7bbf44ea15706bc3c04aeaa852b2277c1994a2\"}" \
--sync-result=true \
--result-to-string=true
- 获取交易ID黑名单 
返回字符串数组,1表示在黑名单
./cmc client contract user get \
--contract-name=TRANSACTION_MANAGER \
--method=GET_BLACKLIST_TX_IDS \
--sdk-conf-path=./testdata/sdk_config.yml \
--params="{\"txIds\":\"174e5c8ce60dfcd4caaa9061ebe79d8ad567a19b2afd4b258add324de922700c,174e5c8e4dd8c58ccac99b9b6dde5b5bbec3c48cc6c44e269e4b7ad456beddb0,174e4e556f3ccb0cca6d9aee6d7bbf44ea15706bc3c04aeaa852b2277c1994a2\"}" \
--result-to-string=true
3.4.1.14. 链上权限管理
- 新增权限策略 - 新增对合约 myContract 中方法 FuncName 的权限策略 - 允许任何单一ADMIN或CLIENT签名即可调用myContract的FuncName方法 - ./cmc client chainconfig permission add \ --permission-resource-name=myContract-FuncName \ --permission-resource-policy-roleList=ADMIN,CLIENT \ --permission-resource-policy-rule=ANY \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
- 更新权限策略 - 更新对合约 myContract 中方法 FuncName 权限策略 - 过半ADMIN签名才能调用myContract的FuncName方法 - ./cmc client chainconfig permission update \ --permission-resource-name=myContract-FuncName \ --permission-resource-policy-roleList=ADMIN \ --permission-resource-policy-rule=MAJORITY \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
- 删除权限策略 - 删除对合约 myContract 中FuncName 方法的权限策略 - ./cmc client chainconfig permission delete \ --permission-resource-name=myContract-FuncName \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
- 获取链上权限策略列表 - ./cmc client chainconfig permission list --sdk-conf-path=./testdata/sdk_config.yml 
3.4.1.15. 共识扩展数据管理
- 新增共识扩展数据 - ./cmc client chainconfig consensusextra add \ --extra-config-key=test_key \ --extra-config-value=test_value \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
- 更新共识扩展数据 - ./cmc client chainconfig consensusextra update \ --extra-config-key=test_key \ --extra-config-value=new_test_value \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
- 删除共识扩展数据 - ./cmc client chainconfig consensusextra delete \ --extra-config-key=test_key \ --sdk-conf-path=./testdata/sdk_config.yml \ --admin-key-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.key,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.key \ --admin-crt-file-paths=./testdata/crypto-config/wx-org1.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org2.chainmaker.org/user/admin1/admin1.sign.crt,./testdata/crypto-config/wx-org3.chainmaker.org/user/admin1/admin1.sign.crt 
3.4.2. 压力测试
CMC性能测试工具支持批量发起交易,实时统计网络环境中的交易请求TPS(每秒事务处理量)及单位时间内成功上链的交易结果
PS: 当前命令适用于非国密单证书链场景。若为其他链类型(如国密双证书链等),请根据实际需求调整相应参数。
./cmc parallel invoke \
--loop-num=100 \
--print-time=3 \
--thread-num=2 \
--timeout=3600 	\
--sleep-time=1 \
--climb-time=5 \
--contract-name=T \
--method=P \
--chain-id=chain1 \
--org-IDs=wx-org1.chainmaker.org \
--hosts=127.0.0.1:12301 \
--sign-keys=./testdata/crypto-config/wx-org1.chainmaker.org/user/client1/client1.sign.key \
--sign-crts=./testdata/crypto-config/wx-org1.chainmaker.org/user/client1/client1.sign.crt
参数说明:
| 参数 | 默认值 | 说明 | 
|---|---|---|
| thread-num | 10 | 线程数量 | 
| loop-num | 1000 | 单线程执行次数 | 
| timeout | 2 | 线程运行时间(单位:秒) | 
| print-time | 1 | 打印时间间隔(单位:秒) | 
| sleep-time | 100 | 线程执行一次休眠时间(单位:秒) | 
| climb-time | 10 | 爬升时间(单位:秒) | 
| hosts | localhost:17988,localhost:27988 | 目标主机列表,多个服务器地址用都逗号分隔 | 
| sign-crts | 指定签名证书路径,用于身份验证,多个路径用逗号分隔 cert模式忽略该值 | |
| sign-keys | 指定签名秘钥路径,与证书配合使用,多个路径用逗号分隔 | |
| user-crts | tls证书路径,多个路径用逗号分隔,未开启tls忽略该值 | |
| user-keys | tls秘钥路径,多个路径用逗号分隔,未开启tls忽略该值 | |
| user-enc-keys | 双证书模式下的,enc key,未开启tls与国密双证书时忽略该值 | |
| user-enc-crts | 双证书模式下的,enc crt,未开启tls与国密双证书时忽略该值 | |
| org-IDs | 指定组织ID列表,模式不为crt时忽略该值 | |
| record-log | false | 请求失败是否记录sdk.log:true、false | 
| output-result | false | 是否打印请求结果:true、false | 
| show-key | false | 是否展示payload:true,false | 
| hash-algorithm | SHA256 | 哈希算法(SHA256,SM3) | 
| ca-path | CA证书路径,多个用逗号拼接 | |
| use-tls | false | 是否使用TLS加密连接:true,false | 
| admin-sign-keys | 管理员签名私钥,多个用逗号拼接 | |
| admin-sign-crts | 管理员签名证书:多个用逗号拼接 | |
| chain-id | chain1 | 区块链id | 
| contract-name | contract1 | 合约名字 | 
| use-short-crt | false | 是否使用短证书:true、false | 
| request-timeout | 5 | 请求超时时间,单位:秒 | 
| auth-type | 1 | 认证类型:PermissionedWithCert:1,PermissionedWithKey:2,Public:3 | 
| gas-limit | 0 | 执行交易的gas | 
| tls-host-names | chainmaker.org | tls主机名,多个主机用逗号分隔 | 
| check-interval | 1 | 完成所有线程后,在N秒内没又产生区块开始统计,单位:秒 | 
| only-send | false | 是否只发送请求不进行链上交易统计 | 
| pairs | "[{\"key\":\"key\",\"value\":\"counter1\",\"unique\":false}]" | 合约自定义传入参数 | 
| pairs-file | 合约自定义传入参数的json文件,同时传入pairs参数与pairs-file参数则仅有pairs-file参数生效 | |
| abi-path | evm合约的abi文件,如果测试的是solidity合约填写该参数 | |
| method | 合约的方法名 | 
执行结果:
{
    "chainResult": {
        "nodes": {
            "node0": {
                "firstBlockHeight": 359,
                "lastBlockHeight": 360,
                "firstBlockTime": "2025-02-12 16:44:04.000",
                "lastBlockTime": "2025-02-12 16:44:04.000",
                "blockOutAvg": 0.8699039,
                "blockNum": 2,
                "blockTxNumAvg": 500,
                "ctps": 434.95197,
                "successCount": 1000,
                "dealMax": 0,
                "dealMin": 0,
                "avgTxLatency": 0.36911700000000003,
                "txVariance": 0.010355579310999974,
                "avgBlockLatency": 0.344,
                "blockVariance": 0.23956089267199998
            }
        }
    },
    "elapsed": 2.2991045,
    "endTime": "2025-02-12 16:44:06",
    "loopNum": 10,
    "rpcResult": {
        "tps": 434.95197,
        "successCount": 1000,
        "failCount": 0,
        "count": 1000,
        "minTime": 1,
        "maxTime": 61,
        "avgTime": 18.442,
        "nodes": {
            "node0": {
                "tps": 434.95197,
                "successCount": 1000,
                "failCount": 0,
                "count": 1000,
                "minTime": 0,
                "maxTime": 61,
                "avgTime": 18.442
            }
        }
    },
    "startTime": "2025-02-12 16:44:04",
    "threadNum": 100
}
结果说明:
| 字段 | 类型 | 说明 | 
|---|---|---|
| chainResult | object | 基于链上交易的结果统计只有执行方式为 cmc parallel invoke 才返回此对象 | 
| --nodes | map[stirng]object | 节点的区块信息 | 
| --node0 | string | 节点索引 node0代表逗号分割后的第一个节点 | 
| --firstBlockHeight | int | 第一个区块高度 | 
| --lastBlockHeight | int | 最后一个区块的高度 | 
| --firstBlockTime | string | 第一个区块的出块时间 | 
| --lastBlockTime | stirng | 最后一个区块的出块时间 | 
| --blockOutAvg | float | 平均出块时间,单位:块/秒 | 
| --blockNum | int | 出块总数 | 
| --blockTxNumAvg | float | 块内平均交易数 | 
| --ctps | float | 链上平均每秒处理交易数 | 
| --maxTxBlock | object | 最大交易数的区块 | 
| --blockHeight | int | 区块高度 | 
| --txCount | int | 交易数量 | 
| --minTxBlock | object | 最小交易数的区块 | 
| --blockHeight | int | 区块高度 | 
| --txCount | int | 交易数量 | 
| --successCount | int | 成功上链的交易数量 | 
| --dealMax | int | 最大每秒上链交易数 | 
| --dealMin | int | 最小每秒上链交易数 | 
| avgTxLatency | float | 平均交易延时 | 
| txVariance | float | 交易延时方差 | 
| avgBlockLatency | float | 平均出块区块延时 | 
| blockVariance | float | 出块延时方差 | 
| startTime | string | 开始时间 | 
| endTime | string | 结束时间 | 
| threadNum | int | 线程数 | 
| loopNum | int | 循环数 | 
| rpcResult | object | 基于rpc的请求结果统计 | 
| elapsed | float | 请求用时,单位:秒 | 
| --tps | float | 吞吐量 | 
| --successCount | int | 收到成功响应的请求数 | 
| --failCount | int | 收到失败响应的请求数 | 
| --count | int | 总请求数 | 
| --minTime | float | 单次请求最小响应时长,单位:毫秒 | 
| --maxTime | float | 单次请求最大响应时长,单位:毫秒 | 
| --avgTime | float | 平均请求时长,单位:毫秒 | 
| --nodes | map[stirng]object | 基于节点的rpc请求统计结果,详情参考如上rpc参数字段 | 
计算方法说明:
以上述统计结果为例:
- blockOutAvg = blockNum / elapsed 
- blockTxNumAvg = successCount / blockNum 
- ctps = txCount / elapsed 
- tps = successCount / elapsed 
- avgTime = 成功请求总耗时 / successCount 
CMC性能分析工具用于统计指定区块高度区间(左开右闭,如(1,20])内的链上交易数据,并输出交易处理结果及性能指标。
PS: 当前命令适用于非国密单证书链场景。若为其他链类型(如国密双证书链等),请根据实际需求调整相应参数。
./cmc parallel analyse \
--start-block=1 \
--end-block=1000 \
--auth-type=1 \
--use-tls=false \
--chain-id=chain1 \
--hosts=127.0.0.1:12301 \
--org-IDs=wx-org1.chainmaker.org \
--sign-keys=./testdata/crypto-config/wx-org1.chainmaker.org/user/client1/client1.sign.key \
--sign-crts=./testdata/crypto-config/wx-org1.chainmaker.org/user/client1/client1.sign.crt
| 参数 | 默认值 | 说明 | 
|---|---|---|
| sign-keys | 签名私钥 | |
| sign-crts | 签名证书 | |
| org-IDs | 组织id 仅在crt模式生效 | |
| use-tls | false | 是否开启tls:true,false | 
| user-crts | tls证书路径,多个路径用逗号分隔,未开启tls忽略该值 | |
| user-keys | tls秘钥路径,多个路径用逗号分隔,未开启tls忽略该值 | |
| user-enc-keys | 双证书模式下的,enc key,未开启tls与国密双证书时忽略该值 | |
| user-enc-crts | 双证书模式下的,enc crt,未开启tls与国密双证书时忽略该值 | |
| ca-path | ca证书根路径 | |
| hosts | 节点ip,多节点用逗号拼接 | |
| hash-algorithm | SHA256 | 哈希算法,(SHA256,SM3) | 
| chain-id | chain1 | 链id | 
| tls-host-names | chainmaker.org | tls主机名,多个主机用逗号分隔 | 
| auth-type | 1 | 认证类型:PermissionedWithCert:1,PermissionedWithKey:2,Public:3 | 
| check-interval | 1 | 无区块产出后检查时间,单位: s | 
| start-block | 0 | 订阅开始的区块高度 | 
| end-block | 1 | 订阅结束的区块高度 | 
执行结果:
{
  "nodes": {
    "node0": {
      "firstBlockHeight": 359,
      "lastBlockHeight": 360,
      "firstBlockTime": "2025-02-12 16:44:04.000",
      "lastBlockTime": "2025-02-12 16:44:04.000",
      "blockOutAvg": 0.8699039,
      "blockNum": 2,
      "blockTxNumAvg": 500,
      "ctps": 434.95197,
      "successCount": 1000,
      "dealMax": 0,
      "dealMin": 0,
      "avgTxLatency": 0.36911700000000003,
      "txVariance": 0.010355579310999974,
      "avgBlockLatency": 0.344,
      "blockVariance": 0.23956089267199998
    }
  }
}
返回字段说明:
| 字段 | 类型 | 说明 | 
|---|---|---|
| --nodes | map[stirng]object | 节点的区块信息 | 
| --node0 | string | 节点索引 node0代表逗号分割后的第一个节点 | 
| --firstBlockHeight | int | 第一个区块高度 | 
| --lastBlockHeight | int | 最后一个区块的高度 | 
| --firstBlockTime | string | 第一个区块的出块时间 | 
| --lastBlockTime | stirng | 最后一个区块的出块时间 | 
| --blockOutAvg | float | 平均出块时间,单位:块/秒 | 
| --blockNum | int | 出块总数 | 
| --blockTxNumAvg | float | 块内平均交易数 | 
| --ctps | float | 链上平均每秒处理交易数 | 
| --maxTxBlock | object | 最大交易数的区块 | 
| --blockHeight | int | 区块高度 | 
| --txCount | int | 交易数量 | 
| --minTxBlock | object | 最小交易数的区块 | 
| --blockHeight | int | 区块高度 | 
| --txCount | int | 交易数量 | 
| --successCount | int | 成功上链的交易数量 | 
| --dealMax | int | 最大每秒上链交易数 | 
| --dealMin | int | 最小每秒上链交易数 | 
| avgTxLatency | float | 平均交易延时 | 
| txVariance | float | 交易延时方差 | 
| avgBlockLatency | float | 平均出块区块延时 | 
| blockVariance | float | 出块延时方差 |