diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-07-06 13:37:32 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-07-06 13:42:29 +0200 |
commit | 3c85d2ec37c3725e407649e487fbeb2a36606d74 (patch) | |
tree | f0fa95df091b17aeb530e6f47eb8403cb0c460f4 /src | |
parent | e81e2e8f7cdee307227f150a6a2408c01fcafbf2 (diff) | |
download | bitcoin-3c85d2ec37c3725e407649e487fbeb2a36606d74.tar.xz |
Fix CChain::GetLocator
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index b2773953d1..3de60ee3ec 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; } |