Skip to content

Commit ad66ca1

Browse files
committed
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.
1 parent 57b8336 commit ad66ca1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/node/blockstorage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,13 @@ bool BlockManager::LoadBlockIndex()
259259
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
260260
CBlockIndexHeightOnlyComparator());
261261

262+
CBlockIndex* previous_index{nullptr};
262263
for (CBlockIndex* pindex : vSortedByHeight) {
263264
if (m_interrupt) return false;
265+
if (previous_index && pindex->nHeight > previous_index->nHeight + 1) {
266+
return error("%s: block index is non-contiguous, index of height %d missing", __func__, previous_index->nHeight + 1);
267+
}
268+
previous_index = pindex;
264269
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
265270
pindex->nTimeMax = (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime) : pindex->nTime);
266271

0 commit comments

Comments
 (0)