@@ -75,7 +75,7 @@ func (b *Block) ValidateBasic() error {
75
75
}
76
76
77
77
// NOTE: b.Data.Txs may be nil, but b.Data.Hash() still works fine.
78
- if w , g := b .Data .Hash (), b .DataHash ; ! bytes .Equal (w , g ) {
78
+ if w , g := b .Data .Hash (false ), b .DataHash ; ! bytes .Equal (w , g ) {
79
79
return fmt .Errorf ("wrong Header.DataHash. Expected %X, got %X. Len of txs %d" , w , g , len (b .Data .Txs ))
80
80
}
81
81
@@ -99,7 +99,7 @@ func (b *Block) fillHeader() {
99
99
b .LastCommitHash = b .LastCommit .Hash ()
100
100
}
101
101
if b .DataHash == nil {
102
- b .DataHash = b .Data .Hash ()
102
+ b .DataHash = b .Data .Hash (false )
103
103
}
104
104
if b .EvidenceHash == nil {
105
105
b .EvidenceHash = b .Evidence .Hash ()
@@ -1298,13 +1298,16 @@ type Data struct {
1298
1298
}
1299
1299
1300
1300
// Hash returns the hash of the data
1301
- func (data * Data ) Hash () tmbytes.HexBytes {
1301
+ func (data * Data ) Hash (overwrite bool ) tmbytes.HexBytes {
1302
1302
if data == nil {
1303
1303
return (Txs {}).Hash ()
1304
1304
}
1305
- //if data.hash == nil {
1306
- data .hash = data .Txs .Hash () // NOTE: leaves of merkle tree are TxIDs
1307
- //}
1305
+ if data .hash != nil && overwrite {
1306
+ data .hash = data .Txs .Hash ()
1307
+ }
1308
+ if data .hash == nil {
1309
+ data .hash = data .Txs .Hash () // NOTE: leaves of merkle tree are TxIDs
1310
+ }
1308
1311
return data .hash
1309
1312
}
1310
1313
0 commit comments