From 698c524698c33595a4d555eaa9e21bc19b4d3e93 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Tue, 26 Oct 2021 22:25:04 +0200 Subject: [PATCH] index: Fix backwards search for bestblock This allows filters to be reconstructed when the best known block is the Genesis block without needing to reindex. It fixes Init errors seen in #23289. --- src/index/base.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index/base.cpp b/src/index/base.cpp index fc6dd77a72f..8525dcbfa02 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -91,11 +91,12 @@ bool BaseIndex::Init() const CBlockIndex* block = active_chain.Tip(); prune_violation = true; // check backwards from the tip if we have all block data until we reach the indexes bestblock - while (block_to_test && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) { + while (block_to_test && block && (block->nStatus & BLOCK_HAVE_DATA)) { if (block_to_test == block) { prune_violation = false; break; } + assert(block->pprev); block = block->pprev; } }