Fix CChain::GetLocator
This commit is contained in:
parent
e81e2e8f7c
commit
3c85d2ec37
14
src/main.cpp
14
src/main.cpp
@ -423,15 +423,13 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
|
|||||||
break;
|
break;
|
||||||
// Exponentially larger steps back, plus the genesis block.
|
// Exponentially larger steps back, plus the genesis block.
|
||||||
int nHeight = std::max(pindex->nHeight - nStep, 0);
|
int nHeight = std::max(pindex->nHeight - nStep, 0);
|
||||||
// Jump back quickly to the same height as the chain.
|
if (Contains(pindex)) {
|
||||||
if (pindex->nHeight > nHeight)
|
// Use O(1) CChain index if possible.
|
||||||
pindex = pindex->GetAncestor(nHeight);
|
|
||||||
// In case pindex is not in this chain, iterate pindex->pprev to find blocks.
|
|
||||||
while (!Contains(pindex))
|
|
||||||
pindex = pindex->pprev;
|
|
||||||
// If pindex is in this chain, use direct height-based access.
|
|
||||||
if (pindex->nHeight > nHeight)
|
|
||||||
pindex = (*this)[nHeight];
|
pindex = (*this)[nHeight];
|
||||||
|
} else {
|
||||||
|
// Otherwise, use O(log n) skiplist.
|
||||||
|
pindex = pindex->GetAncestor(nHeight);
|
||||||
|
}
|
||||||
if (vHave.size() > 10)
|
if (vHave.size() > 10)
|
||||||
nStep *= 2;
|
nStep *= 2;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user