From c99667583dd9b57612edf4c04611cd4857250600 Mon Sep 17 00:00:00 2001 From: stratospher <44024636+stratospher@users.noreply.github.com> Date: Fri, 7 Feb 2025 09:29:31 +0530 Subject: [PATCH] validation: fix traversal condition to mark BLOCK_FAILED_CHILD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this block of code is not reached on master since other than initialisation, all other iterations have invalid_walk_tip and to_mark_failed pointers in some form of this layout where 1, 2, 3 and 4 are block heights. invalid_walk_tip ↓ 1 <- 2 <- 3 <- 4 ↑ to_mark_failed fix it so that blocks are correctly marked as BLOCK_FAILED_CHILD if it's a descendant of BLOCK_FAILED_VALID block. --- src/validation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index 0384018bc36..673c9272fe6 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3747,7 +3747,7 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde m_blockman.m_dirty_blockindex.insert(invalid_walk_tip); setBlockIndexCandidates.erase(invalid_walk_tip); setBlockIndexCandidates.insert(invalid_walk_tip->pprev); - if (invalid_walk_tip->pprev == to_mark_failed && (to_mark_failed->nStatus & BLOCK_FAILED_VALID)) { + 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;