From 05c7c1402315b30df532e056351e6f8e02e64fc2 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 3 Feb 2017 01:14:26 -0600 Subject: [PATCH] blockchain: Ignore side chains in exists check. Since the code base is currently in the process of changing over to decouple download and connection logic, but not all of the necessary parts are updated yet, ensure blocks that are in the database, but do not have an associated main chain block index entry, are treated as if they do not exist for the purposes of chain connection and selection logic. --- blockchain/process.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/blockchain/process.go b/blockchain/process.go index 5a2e5ab17..9bc686237 100644 --- a/blockchain/process.go +++ b/blockchain/process.go @@ -52,6 +52,24 @@ func (b *BlockChain) blockExists(hash *chainhash.Hash) (bool, error) { err := b.db.View(func(dbTx database.Tx) error { var err error exists, err = dbTx.HasBlock(hash) + if err != nil || !exists { + return err + } + + // Ignore side chain blocks in the database. This is necessary + // because there is not currently any record of the associated + // block index data such as its block height, so it's not yet + // possible to efficiently load the block and do anything useful + // with it. + // + // Ultimately the entire block index should be serialized + // instead of only the current main chain so it can be consulted + // directly. + _, err = dbFetchHeightByHash(dbTx, hash) + if isNotInMainChainErr(err) { + exists = false + return nil + } return err }) return exists, err