From ad66ca1e475d2546dbbda206465307613108a15d Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Fri, 2 Jun 2023 16:36:01 -0400 Subject: init: abort loading of blockindex in case of missing height. If a height is missing we are facing a non-contiguous block index db, and could previously hit an assert in GetAncestor() called from BuildSkip() instead of returning an error. --- src/node/blockstorage.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 78416ec576..a292ffe869 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -259,8 +259,13 @@ bool BlockManager::LoadBlockIndex() std::sort(vSortedByHeight.begin(), vSortedByHeight.end(), CBlockIndexHeightOnlyComparator()); + CBlockIndex* previous_index{nullptr}; for (CBlockIndex* pindex : vSortedByHeight) { if (m_interrupt) return false; + if (previous_index && pindex->nHeight > previous_index->nHeight + 1) { + return error("%s: block index is non-contiguous, index of height %d missing", __func__, previous_index->nHeight + 1); + } + previous_index = pindex; pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex); pindex->nTimeMax = (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime) : pindex->nTime); -- cgit v1.2.3