Skip to content

Commit 3c85d2e

Browse files
committed
Fix CChain::GetLocator
1 parent e81e2e8 commit 3c85d2e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/main.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,13 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
423423
break;
424424
// Exponentially larger steps back, plus the genesis block.
425425
int nHeight = std::max(pindex->nHeight - nStep, 0);
426-
// Jump back quickly to the same height as the chain.
427-
if (pindex->nHeight > nHeight)
428-
pindex = pindex->GetAncestor(nHeight);
429-
// In case pindex is not in this chain, iterate pindex->pprev to find blocks.
430-
while (!Contains(pindex))
431-
pindex = pindex->pprev;
432-
// If pindex is in this chain, use direct height-based access.
433-
if (pindex->nHeight > nHeight)
426+
if (Contains(pindex)) {
427+
// Use O(1) CChain index if possible.
434428
pindex = (*this)[nHeight];
429+
} else {
430+
// Otherwise, use O(log n) skiplist.
431+
pindex = pindex->GetAncestor(nHeight);
432+
}
435433
if (vHave.size() > 10)
436434
nStep *= 2;
437435
}

0 commit comments

Comments
 (0)