Skip to content

Commit ed764ea

Browse files
committed
validation: Add more checks to CheckBlockIndex()
This adds checks that 1) Descendants of invalid block indexes are also marked invalid 2) m_best_header cannot be invalid, and there can be no valid block with more work than it.
1 parent 9a70883 commit ed764ea

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/validation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5305,6 +5305,7 @@ void ChainstateManager::CheckBlockIndex()
53055305
// are not yet validated.
53065306
CChain best_hdr_chain;
53075307
assert(m_best_header);
5308+
assert(!(m_best_header->nStatus & BLOCK_FAILED_MASK));
53085309
best_hdr_chain.SetTip(*m_best_header);
53095310

53105311
std::multimap<CBlockIndex*,CBlockIndex*> forward;
@@ -5418,6 +5419,8 @@ void ChainstateManager::CheckBlockIndex()
54185419
if (pindexFirstInvalid == nullptr) {
54195420
// Checks for not-invalid blocks.
54205421
assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0); // The failed mask cannot be set for blocks without invalid parents.
5422+
} else {
5423+
assert(pindex->nStatus & BLOCK_FAILED_MASK); // Invalid blocks and their descendants must be marked as invalid
54215424
}
54225425
// Make sure m_chain_tx_count sum is correctly computed.
54235426
if (!pindex->pprev) {
@@ -5431,6 +5434,8 @@ void ChainstateManager::CheckBlockIndex()
54315434
// block, and must be set if it is.
54325435
assert((pindex->m_chain_tx_count != 0) == (pindex == snap_base));
54335436
}
5437+
// There should be no block with more work than m_best_header, unless it's known to be invalid
5438+
assert((pindex->nStatus & BLOCK_FAILED_MASK) || pindex->nChainWork <= m_best_header->nChainWork);
54345439

54355440
// Chainstate-specific checks on setBlockIndexCandidates
54365441
for (auto c : GetAll()) {

0 commit comments

Comments
 (0)