validation: don't update BLOCK_FAILED_VALID to BLOCK_FAILED_CHILD in InvalidateBlock
- there is no functional difference between BLOCK_FAILED_VALID and BLOCK_FAILED_CHILD and it's unnecessary code complexity to correctly categorise them.
This commit is contained in:
1 parent
acefdce083
commit
18f11695c7
1 file changed
+3
-12
+3
-12
@@ -3637,15 +3637,8 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde
|
|||||||
m_blockman.m_dirty_blockindex.insert(invalid_walk_tip);
|
m_blockman.m_dirty_blockindex.insert(invalid_walk_tip);
|
||||||
setBlockIndexCandidates.erase(invalid_walk_tip);
|
setBlockIndexCandidates.erase(invalid_walk_tip);
|
||||||
setBlockIndexCandidates.insert(invalid_walk_tip->pprev);
|
setBlockIndexCandidates.insert(invalid_walk_tip->pprev);
|
||||||
if (invalid_walk_tip == to_mark_failed->pprev && (to_mark_failed->nStatus & BLOCK_FAILED_VALID)) {
|
|
||||||
// We only want to mark the last disconnected block as BLOCK_FAILED_VALID; its children
|
|
||||||
// need to be BLOCK_FAILED_CHILD instead.
|
|
||||||
to_mark_failed->nStatus = (to_mark_failed->nStatus ^ BLOCK_FAILED_VALID) | BLOCK_FAILED_CHILD;
|
|
||||||
m_blockman.m_dirty_blockindex.insert(to_mark_failed);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark out-of-chain descendants of the invalidated block as invalid
|
// Mark out-of-chain descendants of the invalidated block as invalid
|
||||||
// (possibly replacing a pre-existing BLOCK_FAILED_VALID with BLOCK_FAILED_CHILD)
|
|
||||||
// Add any equal or more work headers that are not invalidated to setBlockIndexCandidates
|
// Add any equal or more work headers that are not invalidated to setBlockIndexCandidates
|
||||||
// Recalculate m_best_header if it became invalid.
|
// Recalculate m_best_header if it became invalid.
|
||||||
auto candidate_it = highpow_outofchain_headers.lower_bound(invalid_walk_tip->pprev->nChainWork);
|
auto candidate_it = highpow_outofchain_headers.lower_bound(invalid_walk_tip->pprev->nChainWork);
|
||||||
@@ -3659,9 +3652,8 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde
|
|||||||
while (candidate_it != highpow_outofchain_headers.end()) {
|
while (candidate_it != highpow_outofchain_headers.end()) {
|
||||||
CBlockIndex* candidate{candidate_it->second};
|
CBlockIndex* candidate{candidate_it->second};
|
||||||
if (candidate->GetAncestor(invalid_walk_tip->nHeight) == invalid_walk_tip) {
|
if (candidate->GetAncestor(invalid_walk_tip->nHeight) == invalid_walk_tip) {
|
||||||
// Children of failed blocks should be marked as BLOCK_FAILED_CHILD instead.
|
// Children of failed blocks are marked as BLOCK_FAILED_VALID.
|
||||||
candidate->nStatus &= ~BLOCK_FAILED_VALID;
|
candidate->nStatus |= BLOCK_FAILED_VALID;
|
||||||
candidate->nStatus |= BLOCK_FAILED_CHILD;
|
|
||||||
m_blockman.m_dirty_blockindex.insert(candidate);
|
m_blockman.m_dirty_blockindex.insert(candidate);
|
||||||
// If invalidated, the block is irrelevant for setBlockIndexCandidates
|
// If invalidated, the block is irrelevant for setBlockIndexCandidates
|
||||||
// and for m_best_header and can be removed from the cache.
|
// and for m_best_header and can be removed from the cache.
|
||||||
@@ -3682,8 +3674,7 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde
|
|||||||
++candidate_it;
|
++candidate_it;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track the last disconnected block, so we can correct its BLOCK_FAILED_CHILD status in future
|
// Track the last disconnected block to call InvalidChainFound on it.
|
||||||
// iterations, or, if it's the last one, call InvalidChainFound on it.
|
|
||||||
to_mark_failed = invalid_walk_tip;
|
to_mark_failed = invalid_walk_tip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user