aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-12-29 20:01:08 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-01-04 22:27:23 +0800
commit9e011ff1cd7fe060e106608d0823e48431ef12e9 (patch)
treeed17707f94d73f16bec16d97cd368590d38096bb /core/blockchain.go
parent36137623edc18c086815b653b2eb0291579ffd22 (diff)
downloaddexon-9e011ff1cd7fe060e106608d0823e48431ef12e9.tar
dexon-9e011ff1cd7fe060e106608d0823e48431ef12e9.tar.gz
dexon-9e011ff1cd7fe060e106608d0823e48431ef12e9.tar.bz2
dexon-9e011ff1cd7fe060e106608d0823e48431ef12e9.tar.lz
dexon-9e011ff1cd7fe060e106608d0823e48431ef12e9.tar.xz
dexon-9e011ff1cd7fe060e106608d0823e48431ef12e9.tar.zst
dexon-9e011ff1cd7fe060e106608d0823e48431ef12e9.zip
core, eth/downloader: ensure state presence in ancestor lookup
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go13
1 files changed, 13 insertions, 0 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