Skip to content

Commit 3c39a55

Browse files
committed
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 5757de4 commit 3c39a55

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

src/validation.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,9 +3849,9 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
38493849

38503850
int nHeight = pindex->nHeight;
38513851

3852-
// Remove the invalidity flag from this block and all its descendants.
3852+
// Remove the invalidity flag from this block and all its descendants and ancestors.
38533853
for (auto& [_, block_index] : m_blockman.m_block_index) {
3854-
if (!block_index.IsValid() && block_index.GetAncestor(nHeight) == pindex) {
3854+
if (!block_index.IsValid() && (block_index.GetAncestor(nHeight) == pindex || pindex->GetAncestor(block_index.nHeight) == &block_index)) {
38553855
block_index.nStatus &= ~BLOCK_FAILED_MASK;
38563856
m_blockman.m_dirty_blockindex.insert(&block_index);
38573857
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveNumChainTxs() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
@@ -3863,15 +3863,6 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) {
38633863
}
38643864
}
38653865
}
3866-
3867-
// Remove the invalidity flag from all ancestors too.
3868-
while (pindex != nullptr) {
3869-
if (pindex->nStatus & BLOCK_FAILED_MASK) {
3870-
pindex->nStatus &= ~BLOCK_FAILED_MASK;
3871-
m_blockman.m_dirty_blockindex.insert(pindex);
3872-
}
3873-
pindex = pindex->pprev;
3874-
}
38753866
}
38763867

38773868
void Chainstate::TryAddBlockIndexCandidate(CBlockIndex* pindex)

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ class Chainstate
731731
/** Set invalidity status to all descendants of a block */
732732
void SetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
733733

734-
/** Remove invalidity status from a block and its descendants. */
734+
/** Remove invalidity status from a block, its descendants and ancestors and reconsider them for activation */
735735
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
736736

737737
/** Replay blocks that aren't fully applied to the database. */

0 commit comments

Comments
 (0)