mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
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.
This commit is contained in:
@@ -5305,6 +5305,7 @@ void ChainstateManager::CheckBlockIndex()
|
||||
// are not yet validated.
|
||||
CChain best_hdr_chain;
|
||||
assert(m_best_header);
|
||||
assert(!(m_best_header->nStatus & BLOCK_FAILED_MASK));
|
||||
best_hdr_chain.SetTip(*m_best_header);
|
||||
|
||||
std::multimap<CBlockIndex*,CBlockIndex*> forward;
|
||||
@@ -5418,6 +5419,8 @@ void ChainstateManager::CheckBlockIndex()
|
||||
if (pindexFirstInvalid == nullptr) {
|
||||
// Checks for not-invalid blocks.
|
||||
assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0); // The failed mask cannot be set for blocks without invalid parents.
|
||||
} else {
|
||||
assert(pindex->nStatus & BLOCK_FAILED_MASK); // Invalid blocks and their descendants must be marked as invalid
|
||||
}
|
||||
// Make sure m_chain_tx_count sum is correctly computed.
|
||||
if (!pindex->pprev) {
|
||||
@@ -5431,6 +5434,8 @@ void ChainstateManager::CheckBlockIndex()
|
||||
// block, and must be set if it is.
|
||||
assert((pindex->m_chain_tx_count != 0) == (pindex == snap_base));
|
||||
}
|
||||
// There should be no block with more work than m_best_header, unless it's known to be invalid
|
||||
assert((pindex->nStatus & BLOCK_FAILED_MASK) || pindex->nChainWork <= m_best_header->nChainWork);
|
||||
|
||||
// Chainstate-specific checks on setBlockIndexCandidates
|
||||
for (auto c : GetAll()) {
|
||||
|
||||
Reference in New Issue
Block a user