aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-12-29 20:01:08 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2016-01-05 19:31:45 +0800
commit8938768f75c6a3c5a0bfb8ae0fed43b7d9fb7e7a (patch)
treeafe8fdc63b2dcf8d793e5b718bb74254984233d5 /core
parent5490437942967638bcc6198035315f6811febaa8 (diff)
downloadgo-tangerine-8938768f75c6a3c5a0bfb8ae0fed43b7d9fb7e7a.tar
go-tangerine-8938768f75c6a3c5a0bfb8ae0fed43b7d9fb7e7a.tar.gz
go-tangerine-8938768f75c6a3c5a0bfb8ae0fed43b7d9fb7e7a.tar.bz2
go-tangerine-8938768f75c6a3c5a0bfb8ae0fed43b7d9fb7e7a.tar.lz
go-tangerine-8938768f75c6a3c5a0bfb8ae0fed43b7d9fb7e7a.tar.xz
go-tangerine-8938768f75c6a3c5a0bfb8ae0fed43b7d9fb7e7a.tar.zst
go-tangerine-8938768f75c6a3c5a0bfb8ae0fed43b7d9fb7e7a.zip
core, eth/downloader: ensure state presence in ancestor lookup
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go13
-rw-r--r--core/state/statedb.go1
2 files changed, 13 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 5e1fc9424..16ef67e09 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -591,6 +591,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 a9de71409..15705dd06 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -55,7 +55,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{