mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-28 21:51:22 +00:00
don't cache the block/header hashes. fixes a cache invalidation bug
This commit is contained in:
parent
b7b88cd763
commit
6c48642ff9
@ -19,9 +19,6 @@ type Block struct {
|
||||
*Header
|
||||
*Validation
|
||||
*Data
|
||||
|
||||
// Volatile
|
||||
hash []byte
|
||||
}
|
||||
|
||||
// Basic validation that doesn't involve state data.
|
||||
@ -57,16 +54,13 @@ func (b *Block) ValidateBasic(lastBlockHeight uint, lastBlockHash []byte,
|
||||
}
|
||||
|
||||
func (b *Block) Hash() []byte {
|
||||
if b.hash == nil {
|
||||
hashes := [][]byte{
|
||||
b.Header.Hash(),
|
||||
b.Validation.Hash(),
|
||||
b.Data.Hash(),
|
||||
}
|
||||
// Merkle hash from sub-hashes.
|
||||
b.hash = merkle.HashFromHashes(hashes)
|
||||
hashes := [][]byte{
|
||||
b.Header.Hash(),
|
||||
b.Validation.Hash(),
|
||||
b.Data.Hash(),
|
||||
}
|
||||
return b.hash
|
||||
// Merkle hash from sub-hashes.
|
||||
return merkle.HashFromHashes(hashes)
|
||||
}
|
||||
|
||||
// Convenience.
|
||||
@ -95,7 +89,7 @@ func (b *Block) StringIndented(indent string) string {
|
||||
indent, b.Header.StringIndented(indent+" "),
|
||||
indent, b.Validation.StringIndented(indent+" "),
|
||||
indent, b.Data.StringIndented(indent+" "),
|
||||
indent, b.hash)
|
||||
indent, b.Hash())
|
||||
}
|
||||
|
||||
func (b *Block) StringShort() string {
|
||||
@ -117,25 +111,20 @@ type Header struct {
|
||||
LastBlockHash []byte
|
||||
LastBlockParts PartSetHeader
|
||||
StateHash []byte
|
||||
|
||||
// Volatile
|
||||
hash []byte
|
||||
}
|
||||
|
||||
func (h *Header) Hash() []byte {
|
||||
if h.hash == nil {
|
||||
buf := new(bytes.Buffer)
|
||||
hasher, n, err := sha256.New(), new(int64), new(error)
|
||||
binary.WriteBinary(h, buf, n, err)
|
||||
if *err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Debug("Hashing", "bytes", buf.Bytes())
|
||||
hasher.Write(buf.Bytes())
|
||||
h.hash = hasher.Sum(nil)
|
||||
log.Debug("Hashing got", "hash", h.hash)
|
||||
buf := new(bytes.Buffer)
|
||||
hasher, n, err := sha256.New(), new(int64), new(error)
|
||||
binary.WriteBinary(h, buf, n, err)
|
||||
if *err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return h.hash
|
||||
log.Debug("Hashing", "bytes", buf.Bytes())
|
||||
hasher.Write(buf.Bytes())
|
||||
hash := hasher.Sum(nil)
|
||||
log.Debug("Hashing got", "hash", hash)
|
||||
return hash
|
||||
}
|
||||
|
||||
func (h *Header) StringIndented(indent string) string {
|
||||
@ -157,7 +146,7 @@ func (h *Header) StringIndented(indent string) string {
|
||||
indent, h.LastBlockHash,
|
||||
indent, h.LastBlockParts,
|
||||
indent, h.StateHash,
|
||||
indent, h.hash)
|
||||
indent, h.Hash())
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -635,7 +635,11 @@ func (cs *ConsensusState) RunActionPropose(height uint, round uint) {
|
||||
}
|
||||
|
||||
// Set the blk.Header.StateHash.
|
||||
cs.state.SetBlockStateHash(block)
|
||||
err := cs.state.SetBlockStateHash(block)
|
||||
if err != nil {
|
||||
log.Error("Error setting state hash", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
blockParts = blk.NewPartSetFromData(binary.BinaryBytes(block))
|
||||
pol = cs.LockedPOL // If exists, is a PoUnlock.
|
||||
|
Loading…
x
Reference in New Issue
Block a user