Skip to content

Commit 79d78d0

Browse files
mzumsandestratospher
authored andcommitted
validation: Add ancestors of reconsiderblock to setBlockIndexCandidates
When we call reconsiderblock for some block, ResetBlockFailureFlags puts the descendants of that block into setBlockIndexCandidates (if they meet the criteria, i.e. have more work than the tip etc.) We also clear the failure flags of the ancestors, but we never put any of those into setBlockIndexCandidates this is wrong and could lead to failures in CheckBlockIndex().
1 parent e486597 commit 79d78d0

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/validation.cpp

+2-12
Original file line numberDiff line numberDiff line change
@@ -3837,9 +3837,9 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
38373837

38383838
int nHeight = pindex->nHeight;
38393839

3840-
// Remove the invalidity flag from this block and all its descendants.
3840+
// Remove the invalidity flag from this block and all its descendants and ancestors.
38413841
for (auto& [_, block_index] : m_blockman.m_block_index) {
3842-
if (!block_index.IsValid() && block_index.GetAncestor(nHeight) == pindex) {
3842+
if (!block_index.IsValid() && (block_index.GetAncestor(nHeight) == pindex || pindex->GetAncestor(block_index.nHeight) == &block_index)) {
38433843
block_index.nStatus &= ~BLOCK_FAILED_MASK;
38443844
m_blockman.m_dirty_blockindex.insert(&block_index);
38453845
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveNumChainTxs() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
@@ -3852,16 +3852,6 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
38523852
m_chainman.m_failed_blocks.erase(&block_index);
38533853
}
38543854
}
3855-
3856-
// Remove the invalidity flag from all ancestors too.
3857-
while (pindex != nullptr) {
3858-
if (pindex->nStatus & BLOCK_FAILED_MASK) {
3859-
pindex->nStatus &= ~BLOCK_FAILED_MASK;
3860-
m_blockman.m_dirty_blockindex.insert(pindex);
3861-
m_chainman.m_failed_blocks.erase(pindex);
3862-
}
3863-
pindex = pindex->pprev;
3864-
}
38653855
}
38663856

38673857
void Chainstate::TryAddBlockIndexCandidate(CBlockIndex* pindex)

0 commit comments

Comments
 (0)