Commit 25c888d6 authored by Jason Yellick's avatar Jason Yellick
Browse files

[FAB-1700] Determinsitic BlockData hashing

This is a companion item to

It removes the protobuf serialization of the BlockData in favor a simple
concatenation of the byte contents.  Eventually, this should be encoded
as a Merkle tree at the configured width, but, like with our hashing
algorithm, for v1, we will make it configurable at a later date, see:

Change-Id: I8a09e84f1c35d8fe1269339a443c44ba01b841a8
Signed-off-by: default avatarJason Yellick <>
parent 7104614a
......@@ -18,6 +18,7 @@ package chainconfig
import (
cb ""
......@@ -144,8 +145,8 @@ func (pm *DescriptorImpl) ProposeConfig(configItem *cb.ConfigurationItem) error
return fmt.Errorf("Unmarshaling error for BlockDataHashingStructure: %s", err)
if blockDataHashingStructure.Width == 0 {
return fmt.Errorf("BlockDataHashStructure width must not be zero")
if blockDataHashingStructure.Width != math.MaxUint32 {
return fmt.Errorf("BlockDataHashStructure width only supported at MaxUint32 in this version")
pm.pendingConfig.blockDataHashingStructureWidth = blockDataHashingStructure.Width
......@@ -21,7 +21,6 @@ import (
......@@ -75,12 +74,15 @@ func (b *BlockHeader) Hash() []byte {
return util.ComputeCryptoHash(b.Bytes())
// Bytes returns a deterministically serialized version of the BlockData
// eventually, this should be replaced with a true Merkle tree construction,
// but for the moment, we assume a Merkle tree of infinite width (uint32_max)
// which degrades to a flat hash
func (b *BlockData) Bytes() []byte {
return util.ConcatenateBytes(b.Data...)
// Hash returns the hash of the marshaled representation of the block data.
func (b *BlockData) Hash() []byte {
data, err := proto.Marshal(b) // XXX this is wrong, protobuf is not the right mechanism to serialize for a hash, AND, it is not a MerkleTree hash
if err != nil {
panic("This should never fail and is generally irrecoverable")
return util.ComputeCryptoHash(data)
return util.ComputeCryptoHash(b.Bytes())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment