mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-08 14:47:31 +02:00
support multiple block status checks in CheckBlockDataAvailability
This commit is contained in:
@@ -623,10 +623,18 @@ const CBlockIndex& BlockManager::GetFirstBlock(const CBlockIndex& upper_block, u
|
||||
return *last_block;
|
||||
}
|
||||
|
||||
bool BlockManager::CheckBlockDataAvailability(const CBlockIndex& upper_block, const CBlockIndex& lower_block)
|
||||
bool BlockManager::CheckBlockDataAvailability(const CBlockIndex& upper_block, const CBlockIndex& lower_block, BlockStatus block_status)
|
||||
{
|
||||
if (!(upper_block.nStatus & BLOCK_HAVE_DATA)) return false;
|
||||
return &GetFirstBlock(upper_block, BLOCK_HAVE_DATA, &lower_block) == &lower_block;
|
||||
if (!(upper_block.nStatus & block_status)) return false;
|
||||
const auto& first_block = GetFirstBlock(upper_block, block_status, &lower_block);
|
||||
// Special case: the genesis block has no undo data
|
||||
if (block_status & BLOCK_HAVE_UNDO && lower_block.nHeight == 0 && first_block.nHeight == 1) {
|
||||
// This might indicate missing data, or it could simply reflect the expected absence of undo data for the genesis block.
|
||||
// To distinguish between the two, check if all required block data *except* undo is available up to the genesis block.
|
||||
BlockStatus flags{block_status & ~BLOCK_HAVE_UNDO};
|
||||
return first_block.pprev && first_block.pprev->nStatus & flags;
|
||||
}
|
||||
return &first_block == &lower_block;
|
||||
}
|
||||
|
||||
// If we're using -prune with -reindex, then delete block files that will be ignored by the
|
||||
|
||||
Reference in New Issue
Block a user