From 9e011ff1cd7fe060e106608d0823e48431ef12e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 29 Dec 2015 14:01:08 +0200 Subject: core, eth/downloader: ensure state presence in ancestor lookup --- core/blockchain.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'core/blockchain.go') 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 -- cgit v1.2.3