Skip to content

Commit 519b0bc

Browse files
committed
Make last disconnected block BLOCK_FAILED_VALID, even when aborted
1 parent 8d22041 commit 519b0bc

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/validation.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,25 +2829,30 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
28292829
// and be left unable to start as they have no tip candidates (as there
28302830
// are no blocks that meet the "have data and are not invalid per
28312831
// nStatus" criteria for inclusion in setBlockIndexCandidates).
2832-
invalid_walk_tip->nStatus |= BLOCK_FAILED_CHILD;
2832+
invalid_walk_tip->nStatus |= BLOCK_FAILED_VALID;
28332833
setDirtyBlockIndex.insert(invalid_walk_tip);
28342834
setBlockIndexCandidates.erase(invalid_walk_tip);
28352835
setBlockIndexCandidates.insert(invalid_walk_tip->pprev);
2836+
if (invalid_walk_tip->pprev == to_mark_failed && (to_mark_failed->nStatus & BLOCK_FAILED_VALID)) {
2837+
// We only want to mark the last disconnected block as BLOCK_FAILED_VALID; its children
2838+
// need to be BLOCK_FAILED_CHILD instead.
2839+
to_mark_failed->nStatus = (to_mark_failed->nStatus ^ BLOCK_FAILED_VALID) | BLOCK_FAILED_CHILD;
2840+
setDirtyBlockIndex.insert(to_mark_failed);
2841+
}
28362842

2837-
// If we abort invalidation after this iteration, make sure
2838-
// the last disconnected block gets marked failed (rather than
2839-
// just child of failed)
2843+
// Track the last disconnected block, so we can correct its BLOCK_FAILED_CHILD status in future
2844+
// iterations, or, if it's the last one, call InvalidChainFound on it.
28402845
to_mark_failed = invalid_walk_tip;
28412846
}
28422847

28432848
{
2844-
// Mark pindex (or the last disconnected block) as invalid, regardless of whether it was in the main chain or not.
28452849
LOCK(cs_main);
28462850
if (chainActive.Contains(to_mark_failed)) {
28472851
// If the to-be-marked invalid block is in the active chain, something is interfering and we can't proceed.
28482852
return false;
28492853
}
28502854

2855+
// Mark pindex (or the last disconnected block) as invalid, even when it never was in the main chain
28512856
to_mark_failed->nStatus |= BLOCK_FAILED_VALID;
28522857
setDirtyBlockIndex.insert(to_mark_failed);
28532858
setBlockIndexCandidates.erase(to_mark_failed);

0 commit comments

Comments
 (0)