From b5b2956bda32b7b4ebc25c83b4d792ecd01f02b4 Mon Sep 17 00:00:00 2001 From: stratospher <44024636+stratospher@users.noreply.github.com> Date: Fri, 7 Feb 2025 12:56:09 +0530 Subject: [PATCH] validation: reset BLOCK_FAILED_CHILD to BLOCK_FAILED_VALID when loading from disk - there maybe existing block indexes stored in disk with BLOCK_FAILED_CHILD - since they don't exist anymore, clean up block index entries with BLOCK_FAILED_CHILD and reset it to BLOCK_FAILED_VALID. --- src/node/blockstorage.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 62abcbc007d..a8d5018fd33 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -487,10 +487,18 @@ bool BlockManager::LoadBlockIndex(const std::optional& snapshot_blockha pindex->m_chain_tx_count = pindex->nTx; } } + + if (pindex->nStatus & BLOCK_FAILED_CHILD) { + // BLOCK_FAILED_CHILD is deprecated, but may still exist on disk. Replace it with BLOCK_FAILED_VALID. + pindex->nStatus = (pindex->nStatus & ~BLOCK_FAILED_CHILD) | BLOCK_FAILED_VALID; + m_dirty_blockindex.insert(pindex); + } if (!(pindex->nStatus & BLOCK_FAILED_MASK) && pindex->pprev && (pindex->pprev->nStatus & BLOCK_FAILED_MASK)) { + // All descendants of invalid blocks are invalid too. pindex->nStatus |= BLOCK_FAILED_VALID; m_dirty_blockindex.insert(pindex); } + if (pindex->pprev) { pindex->BuildSkip(); }