Skip to content

Commit 14250f4

Browse files
mzumsandestratospher
authored andcommitted
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 47eb7f9 commit 14250f4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/validation.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -5316,6 +5316,7 @@ void ChainstateManager::CheckBlockIndex()
53165316
// are not yet validated.
53175317
CChain best_hdr_chain;
53185318
assert(m_best_header);
5319+
assert(!(m_best_header->nStatus & BLOCK_FAILED_MASK));
53195320
best_hdr_chain.SetTip(*m_best_header);
53205321

53215322
std::multimap<CBlockIndex*,CBlockIndex*> forward;
@@ -5429,8 +5430,7 @@ void ChainstateManager::CheckBlockIndex()
54295430
if (pindexFirstInvalid == nullptr) {
54305431
// Checks for not-invalid blocks.
54315432
assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0); // The failed mask cannot be set for blocks without invalid parents.
5432-
}
5433-
else if (pindexFirstInvalid != pindex) {
5433+
} else if (pindexFirstInvalid != pindex) {
54345434
// pindexFirstInvalid -> ...... -> pindex
54355435
// we check that descendants are BLOCK_FAILED_CHILD and not BLOCK_FAILED_VALID
54365436
assert((pindex->nStatus & BLOCK_FAILED_VALID) == 0);
@@ -5451,6 +5451,8 @@ void ChainstateManager::CheckBlockIndex()
54515451
// block, and must be set if it is.
54525452
assert((pindex->m_chain_tx_count != 0) == (pindex == snap_base));
54535453
}
5454+
// There should be no block with more work than m_best_header, unless it's known to be invalid
5455+
assert((pindex->nStatus & BLOCK_FAILED_MASK) || pindex->nChainWork <= m_best_header->nChainWork);
54545456

54555457
// Chainstate-specific checks on setBlockIndexCandidates
54565458
for (auto c : GetAll()) {

0 commit comments

Comments
 (0)