mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-29 22:21:21 +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
|
*Header
|
||||||
*Validation
|
*Validation
|
||||||
*Data
|
*Data
|
||||||
|
|
||||||
// Volatile
|
|
||||||
hash []byte
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basic validation that doesn't involve state data.
|
// 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 {
|
func (b *Block) Hash() []byte {
|
||||||
if b.hash == nil {
|
hashes := [][]byte{
|
||||||
hashes := [][]byte{
|
b.Header.Hash(),
|
||||||
b.Header.Hash(),
|
b.Validation.Hash(),
|
||||||
b.Validation.Hash(),
|
b.Data.Hash(),
|
||||||
b.Data.Hash(),
|
|
||||||
}
|
|
||||||
// Merkle hash from sub-hashes.
|
|
||||||
b.hash = merkle.HashFromHashes(hashes)
|
|
||||||
}
|
}
|
||||||
return b.hash
|
// Merkle hash from sub-hashes.
|
||||||
|
return merkle.HashFromHashes(hashes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience.
|
// Convenience.
|
||||||
@ -95,7 +89,7 @@ func (b *Block) StringIndented(indent string) string {
|
|||||||
indent, b.Header.StringIndented(indent+" "),
|
indent, b.Header.StringIndented(indent+" "),
|
||||||
indent, b.Validation.StringIndented(indent+" "),
|
indent, b.Validation.StringIndented(indent+" "),
|
||||||
indent, b.Data.StringIndented(indent+" "),
|
indent, b.Data.StringIndented(indent+" "),
|
||||||
indent, b.hash)
|
indent, b.Hash())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Block) StringShort() string {
|
func (b *Block) StringShort() string {
|
||||||
@ -117,25 +111,20 @@ type Header struct {
|
|||||||
LastBlockHash []byte
|
LastBlockHash []byte
|
||||||
LastBlockParts PartSetHeader
|
LastBlockParts PartSetHeader
|
||||||
StateHash []byte
|
StateHash []byte
|
||||||
|
|
||||||
// Volatile
|
|
||||||
hash []byte
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Header) Hash() []byte {
|
func (h *Header) Hash() []byte {
|
||||||
if h.hash == nil {
|
buf := new(bytes.Buffer)
|
||||||
buf := new(bytes.Buffer)
|
hasher, n, err := sha256.New(), new(int64), new(error)
|
||||||
hasher, n, err := sha256.New(), new(int64), new(error)
|
binary.WriteBinary(h, buf, n, err)
|
||||||
binary.WriteBinary(h, buf, n, err)
|
if *err != nil {
|
||||||
if *err != nil {
|
panic(err)
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
log.Debug("Hashing", "bytes", buf.Bytes())
|
|
||||||
hasher.Write(buf.Bytes())
|
|
||||||
h.hash = hasher.Sum(nil)
|
|
||||||
log.Debug("Hashing got", "hash", h.hash)
|
|
||||||
}
|
}
|
||||||
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 {
|
func (h *Header) StringIndented(indent string) string {
|
||||||
@ -157,7 +146,7 @@ func (h *Header) StringIndented(indent string) string {
|
|||||||
indent, h.LastBlockHash,
|
indent, h.LastBlockHash,
|
||||||
indent, h.LastBlockParts,
|
indent, h.LastBlockParts,
|
||||||
indent, h.StateHash,
|
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.
|
// 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))
|
blockParts = blk.NewPartSetFromData(binary.BinaryBytes(block))
|
||||||
pol = cs.LockedPOL // If exists, is a PoUnlock.
|
pol = cs.LockedPOL // If exists, is a PoUnlock.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user