diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-01-05 19:26:38 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-01-05 19:26:38 +0800 |
commit | 32226f1b0cb98286cfd3f2898c344df1dfca45ec (patch) | |
tree | 4eeb1c35b75915fa3686d0e9ae3fd75796fdf4a0 /core | |
parent | a7fc4fa9b7c72059d7f58d705488c9de35413907 (diff) | |
parent | 9e011ff1cd7fe060e106608d0823e48431ef12e9 (diff) | |
download | dexon-32226f1b0cb98286cfd3f2898c344df1dfca45ec.tar.gz dexon-32226f1b0cb98286cfd3f2898c344df1dfca45ec.tar.zst dexon-32226f1b0cb98286cfd3f2898c344df1dfca45ec.zip |
Merge pull request #2097 from karalabe/block-state-checks
core, eth/downloader: ensure state presence in ancestor lookup
Diffstat (limited to 'core')
-rw-r--r-- | core/blockchain.go | 13 | ||||
-rw-r--r-- | core/state/statedb.go | 1 |
2 files changed, 13 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 9d526e352..95ed06d8d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -587,6 +587,19 @@ func (bc *BlockChain) HasBlock(hash common.Hash) bool { return bc.GetBlock(hash) != nil } +// HasBlockAndState checks if a block and associated state trie is fully present +// in the database or not, caching it if present. +func (bc *BlockChain) HasBlockAndState(hash common.Hash) bool { + // Check first that the block itself is known + block := bc.GetBlock(hash) + if block == nil { + return false + } + // Ensure the associated state is also present + _, err := state.New(block.Root(), bc.chainDb) + return err == nil +} + // GetBlock retrieves a block from the database by hash, caching it if found. func (self *BlockChain) GetBlock(hash common.Hash) *types.Block { // Short circuit if the block's already in the cache, retrieve otherwise diff --git a/core/state/statedb.go b/core/state/statedb.go index ab93870bf..413321057 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -57,7 +57,6 @@ type StateDB struct { func New(root common.Hash, db ethdb.Database) (*StateDB, error) { tr, err := trie.NewSecure(root, db) if err != nil { - glog.Errorf("can't create state trie with root %x: %v", root[:], err) return nil, err } return &StateDB{ |