Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the blockchain height in hyperledger-fabric

I am playing with hyperledger-fabric v.1.0 - actually a newbie. How can I check the chain height ? Is there a command or something that I can use to "ask" about the blockchain height? Thanks in advance.

like image 598
saradiss Avatar asked Dec 11 '22 10:12

saradiss


2 Answers

Well, you have a few options of how you can do it:

  1. You can leverage peer cli command line tool to obtain latest available block by running

    peer channel fetch newest -o ordererIP:7050 -c mychannel  last.block
    

Next you can leverage configtxlator to decode content of the block as following:

curl -X POST --data-binary @last.block http://localhost:7059/protolator/decode/common.Block

(note you need to start configtxlator first)

  1. Alternative path assumes you are going to use one of available SDK's to invoke QSCC (Query System ChainCode) with GetChainInfo command. This will return you back following structure:

    type BlockchainInfo struct {
         Height            uint64 `protobuf:"varint,1,opt,name=height" json:"height,omitempty"`
         CurrentBlockHash  []byte `protobuf:"bytes,2,opt,name=currentBlockHash,proto3" json:"currentBlockHash,omitempty"`
         PreviousBlockHash []byte `protobuf:"bytes,3,opt,name=previousBlockHash,proto3" json:"previousBlockHash,omitempty"`
    }
    

Which has information about current ledger height.

like image 194
Artem Barger Avatar answered Dec 23 '22 17:12

Artem Barger


Another alternative. Using the cli peer command line (for example docker exec -it cli bash) you can do:

peer channel getinfo -c mychannel

like image 39
Michele Macagno Avatar answered Dec 23 '22 17:12

Michele Macagno