获取当前channel的高度
- 获取orderer里一个channel的ledger高度
export ORDERERADDR=<ordererhost>:7050
export CORE_PEER_LOCALMSPID=<mspid>
export CORE_PEER_MSPCONFIGPATH=/path/to/msp
export CHANNEL=testchainid
export BLOCK=newest
$ peer channel fetch ${BLOCK} config.pb -o ${ORDERERADDR} -c ${CHANNEL}"
$ configtxlator proto_decode --input config.pb --type common.Block > config.json
$ jq .header config.json
{
"data_hash": "lHFu5kenNW3pC+6k5wa9gvuM0frsThksfUJMtY7syoQ=",
"number": "9",
"previous_hash": "kYsldRIUIsxEEMhRkIRUYUQp+0s647kNWYYJeFanYm0="
}
从orderer取一个块,使用参数newest获取最后一个块(可以指定数字块号,0, 1, 2, ...,还可以使用config指定最新的一个config块);然后分析块头信息header.number就是ledger高度。
其实这个块号在peer channel fetch命令的输出日志里面也有:
2020-04-28 18:19:38.434 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2020-04-28 18:19:38.439 UTC [cli.common] readBlock -> INFO 004 Received block: 9
- 获取peer里一个channel的ledger高度
export CORE_PEER_ADDRESS=<peerhost>:7051
export FABRIC_CFG_PATH=/path/to/config
export CHANNEL= testchainid
$ peer channel getinfo -c ${CHANNEL}"
2020-04-28 18:28:08.999 UTC [channelCmd] InitCmdFactory -> INFO 002 Endorser and orderer connections initialized
Blockchain info: {"height":8,"currentBlockHash":"7GsNILFixljhaq67Vdr/YW+kdjDnD1RaR9LIsdqFnJ0=","previousBlockHash":"NGOd3gex/c5La8vEq0wn7K1T1zgW6ZEvOsj0YWkZXww="}
注意FABRIC_CFG_PATH目录下面必须包含对应peer的core.yaml文件,另外好像这个命令不用在peer本身的container环境下面运行。







网友评论