diff options
author | Jonas Schnelli <dev@jonasschnelli.ch> | 2019-05-02 20:41:01 +0200 |
---|---|---|
committer | Jonas Schnelli <dev@jonasschnelli.ch> | 2021-02-11 11:39:45 +0100 |
commit | 6abe9f5b11cd4a5ecb6caca8443fe2950a417842 (patch) | |
tree | 54c2d223a6ae3c780369289d67e7ebbf49a2a40c /src/index/base.cpp | |
parent | a59e7ed0bc34cd9fc0d03f0e2f29239104a98f8f (diff) | |
download | bitcoin-6abe9f5b11cd4a5ecb6caca8443fe2950a417842.tar.xz |
Allow blockfilter in conjunction with prune
Diffstat (limited to 'src/index/base.cpp')
-rw-r--r-- | src/index/base.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/index/base.cpp b/src/index/base.cpp index 3d3dda95b1..38958a82e9 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -65,6 +65,43 @@ bool BaseIndex::Init() m_best_block_index = g_chainman.m_blockman.FindForkInGlobalIndex(::ChainActive(), locator); } m_synced = m_best_block_index.load() == ::ChainActive().Tip(); + if (!m_synced) { + bool prune_violation = false; + if (!m_best_block_index) { + // index is not built yet + // make sure we have all block data back to the genesis + const CBlockIndex* block = ::ChainActive().Tip(); + while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) { + block = block->pprev; + } + prune_violation = block != ::ChainActive().Genesis(); + } + // in case the index has a best block set and is not fully synced + // check if we have the required blocks to continue building the index + else { + const CBlockIndex* block_to_test = m_best_block_index.load(); + if (!ChainActive().Contains(block_to_test)) { + // if the bestblock is not part of the mainchain, find the fork + // and make sure we have all data down to the fork + block_to_test = ::ChainActive().FindFork(block_to_test); + } + const CBlockIndex* block = ::ChainActive().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)) { + if (block_to_test == block) { + prune_violation = false; + break; + } + block = block->pprev; + } + } + if (prune_violation) { + // throw error and graceful shutdown if we can't build the index + FatalError("%s: %s best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)", __func__, GetName()); + return false; + } + } return true; } @@ -177,6 +214,10 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip); // In the case of a reorg, ensure persisted block locator is not stale. + // Pruning has a minimum of 288 blocks-to-keep and getting the index + // out of sync may be possible but a users fault. + // In case we reorg beyond the pruned depth, ReadBlockFromDisk would + // throw and lead to a graceful shutdown m_best_block_index = new_tip; if (!Commit()) { // If commit fails, revert the best block index to avoid corruption. |