diff --git a/blockchain/process.go b/blockchain/process.go index 5a2e5ab1..9bc68623 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