diff --git a/src/validation.cpp b/src/validation.cpp index d5e92600d4f..495154ad616 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3849,9 +3849,9 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex) { int nHeight = pindex->nHeight; - // Remove the invalidity flag from this block and all its descendants. + // Remove the invalidity flag from this block and all its descendants and ancestors. for (auto& [_, block_index] : m_blockman.m_block_index) { - if (!block_index.IsValid() && block_index.GetAncestor(nHeight) == pindex) { + if (!block_index.IsValid() && (block_index.GetAncestor(nHeight) == pindex || pindex->GetAncestor(block_index.nHeight) == &block_index)) { block_index.nStatus &= ~BLOCK_FAILED_MASK; m_blockman.m_dirty_blockindex.insert(&block_index); 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) { } } } - - // Remove the invalidity flag from all ancestors too. - while (pindex != nullptr) { - if (pindex->nStatus & BLOCK_FAILED_MASK) { - pindex->nStatus &= ~BLOCK_FAILED_MASK; - m_blockman.m_dirty_blockindex.insert(pindex); - } - pindex = pindex->pprev; - } } void Chainstate::TryAddBlockIndexCandidate(CBlockIndex* pindex) diff --git a/src/validation.h b/src/validation.h index c7e70e3adbc..8ba126b9931 100644 --- a/src/validation.h +++ b/src/validation.h @@ -731,7 +731,7 @@ public: /** Set invalidity status to all descendants of a block */ void SetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); - /** Remove invalidity status from a block and its descendants. */ + /** Remove invalidity status from a block, its descendants and ancestors and reconsider them for activation */ void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Replay blocks that aren't fully applied to the database. */