Disable block hash caching

Our consensus differ from Ethereum's: The proposed block header is
incomplete until the preparer/committer bitmaps and signatures are
known, where Ethereum's proposed block is already immutable.  Ethereum
code calls, especially from validator logic, block.Hash() liberally
without ill effect, but in our case the validation logic is called
before the finalization of committer bitmap, and the block.Hash() calls
embedded in the validation fixates and finalizes the block hash
prematurely.

Until we have a better logic to deal with this, disable block hash
caching, and always recompute the block hash using the actual header.
pull/839/head
Eugene Kim 6 years ago
parent a7ba9a1b67
commit 0782151f75
  1. 7
      core/types/block.go

@ -430,9 +430,10 @@ func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block {
// Hash returns the keccak256 hash of b's header.
// The hash is computed on the first call and cached thereafter.
func (b *Block) Hash() common.Hash {
if hash := b.hash.Load(); hash != nil {
return hash.(common.Hash)
}
//if hash := b.hash.Load(); hash != nil {
// return hash.(common.Hash)
//}
//b.Logger(utils.GetLogger()).Debug("finalizing and caching block hash")
v := b.header.Hash()
b.hash.Store(v)
return v

Loading…
Cancel
Save