Search code examples
hyperledger-fabricmerkle-tree

How to calculate the merkle root in a hyperledger fabric?


How can I calculate the merkle root of a hyperledger fabric? I have a hard time finding merkle root in Fabric.

The block header contains number , prefix_hash , data_hash . Are any of the above three related data related to the merkle root?

Or can I calculate a merkle root manually?

I have hashed the data I used when I submitted the data to the ledger. But it is could not be found in the block header...

How can I calculate the merkle root of a hyperledger fabric?


Solution

  • Hyperledger Fabric does not track a hash of world state in the block headers. Instead, the hash-chain is formed over the block contents.

    The two fields you will find in the block header are the data_hash and the previous_block_hash.

    The data_hash is a hash over the concatenation of the bytes of the transactions in the data section of the block.

    The previous_block_hash is the hash of the header of the previous block. The hash of the block header is computed by converting the contents to ASN1, then hashing a marshaled representation.

    You can see specifically how the Fabric components implementing their hashing here: https://github.com/hyperledger/fabric/blob/a5bd17f9ec21241c324f453f0ded3d045bd28ff3/protoutil/blockutils.go#L38-L79