aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-07-07 10:24:20 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-07-07 10:28:09 +0200
commit5e1b7a23b056734c84226b20176aa221903ea28e (patch)
treeba81499450dbdd99ed2c73819045560536db04c0 /src/main.cpp
parentbc06e8f402ec1859133a3d79c8946f2ce91e315c (diff)
parentf4b00beae52f22fc6958855a85e1012387c3c33e (diff)
Merge pull request #4470
f4b00be Add CChain::GetLocator() unit test (Pieter Wuille) 3c85d2e Fix CChain::GetLocator (Pieter Wuille)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp
index e08b794184..86e60e4c63 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -423,15 +423,13 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
break;
// Exponentially larger steps back, plus the genesis block.
int nHeight = std::max(pindex->nHeight - nStep, 0);
- // Jump back quickly to the same height as the chain.
- if (pindex->nHeight > nHeight)
- 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)
+ if (Contains(pindex)) {
+ // Use O(1) CChain index if possible.
pindex = (*this)[nHeight];
+ } else {
+ // Otherwise, use O(log n) skiplist.
+ pindex = pindex->GetAncestor(nHeight);
+ }
if (vHave.size() > 10)
nStep *= 2;
}