core, trie: Correctly propagate blocknum/hash, and fix a consensus issue

This commit is contained in:
Nick Johnson 2016-10-26 11:52:32 +01:00
parent 6d4b9987d3
commit 5c5de90f0c
3 changed files with 6 additions and 4 deletions

View file

@ -547,7 +547,7 @@ func (self *BlockChain) GetBlockByNumber(number uint64) *types.Block {
// IsCanonChainBlock checks whether the given block is in the current canonical chain.
func (self *BlockChain) IsCanonChainBlock(number uint64, hash common.Hash) bool {
return number < uint64(self.currentBlock.Number().Int64()) && GetCanonicalHash(self.chainDb, number) == hash
return GetCanonicalHash(self.chainDb, number) == hash
}
// [deprecated by eth/62]

View file

@ -188,7 +188,7 @@ func (self *StateDB) SetBlockContext(blockHash common.Hash, blockNum uint64, val
if validator == nil {
validator = &trie.NullCacheValidator{}
}
storage := trie.NewDirectCache(self.trie, self.db, CachePrefix, validator, true)
storage := trie.NewDirectCache(self.trie, self.db, CachePrefix, blockNum, blockHash, validator, true)
self.storage = trie.NewSecure(storage, self.db)
}

View file

@ -79,11 +79,13 @@ func (cv *NullCacheValidator) IsCanonChainBlock(num uint64, hash common.Hash) bo
return false
}
func NewDirectCache(pm PersistentMap, db Database, keyPrefix []byte, validator CacheValidator, complete bool) *DirectCache {
func NewDirectCache(pm PersistentMap, db Database, keyPrefix []byte, blockNum uint64, blockHash common.Hash, validator CacheValidator, complete bool) *DirectCache {
return &DirectCache{
data: pm,
db: db,
keyPrefix: keyPrefix,
blockNum: blockNum,
blockHash: blockHash,
validator: validator,
complete: complete,
dirty: make(map[string]bool),
@ -151,7 +153,7 @@ func (dc *DirectCache) getCached(key []byte) ([]byte, bool) {
return nil, false
}
canonical := dc.validator.IsCanonChainBlock(data.BlockNum, data.BlockHash)
canonical := dc.blockNum > 0 && data.BlockNum < dc.blockNum && dc.validator.IsCanonChainBlock(data.BlockNum, data.BlockHash)
return data.Value, canonical
}