Add a skiplist to the CBlockIndex structure. #4420

pull sipa wants to merge 3 commits into bitcoin:master from sipa:skiplist changing 5 files +163 −2
  1. sipa commented at 6:28 PM on June 26, 2014: member

    Another piece of logic that is needed in headersfirst: a fast way to determine whether a tip of the header chain is an descendant of what a particular peer has available.

    A skip list is easy to add to the existing structure, and allows fast (O(log n)) access to far predecessor blocks.

    The current code only uses it to speed up CChain::FindFork and CChain::GetLocator.

  2. gavinandresen commented at 7:06 PM on June 26, 2014: contributor

    You sure this will increase performance? In practice, aren't header chains likely to be just a few blocks long?

    If N is typically smaller than a few dozen I'd expect the simpler iterate-prev-pointers (and smaller, more cache-friendly CBlockIndex) to outperform any more complicated code.

  3. sipa commented at 7:09 PM on June 26, 2014: member

    Within minutes after starting IBD you'll have a header chain 300000 long, with a few 1000 long blockchain.

  4. sipa commented at 7:10 PM on June 26, 2014: member

    Anyway, I'm fine with waiting with this, and developing the code that uses it in parallel.

    Just trying to cut it up in nice indidvidually-reviewable pieces.

  5. laanwj commented at 8:17 AM on June 29, 2014: member

    Code changes look good to me.

    This needs a unit test for BuildSkip/GetAncestor.

  6. sipa commented at 1:37 PM on June 29, 2014: member

    Added a unit test.

  7. Track peers' available blocks aa81564700
  8. Add a skiplist to the CBlockIndex structure.
    This allows fast (O(log n)) access to far predecessor blocks.
    Use it to speed up CChain::FindFork and CChain::GetLocator.
    c9a0918330
  9. Add skiplist unit tests 236982c2b6
  10. sipa commented at 7:53 PM on June 29, 2014: member

    Including #4407 in this, so I don't need to maintain two independent branches and merge them for successor pull requests.

  11. BitcoinPullTester commented at 8:24 PM on June 29, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4420_236982c2b6de619f0744c9c17ea7208b64a4afb3/ for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  12. sipa commented at 8:25 PM on June 29, 2014: member

    @gavinandresen Just so there's no misunderstanding: currently this pull has nearly no benefit; I use the new functions where possible because they improve some worst case time and to give the code exposure, but it hardly matters for the current use sites.

    The reason for adding is that in a successor patch I need it for finding the next blocks to fetch from a peer (which has a known tip), and there is no pnext pointer as different peers may have different ones. Alternatives are either:

    • Building a CChain for each peer with their known blocks (which adds a few megabytes, and takes time to build); O(nBlocks * nPeers) memory cost but O(1) access cost.
    • Not building any index structure, and walk back from the tip for each block to be requested, which means O(300000) iterations for every block during early IBD. 0 memory cost, but O(nBlocks) access cost.

    A skiplist adds a O(nBlocks) memory cost, but O(log nBlocks) worst-case access cost, which seems a nice compromise.

  13. gavinandresen commented at 12:21 PM on June 30, 2014: contributor

    Ok: code-reviewed-but-untested ACK.

  14. gavinandresen referenced this in commit 6fba25ef26 on Jun 30, 2014
  15. gavinandresen merged this on Jun 30, 2014
  16. gavinandresen closed this on Jun 30, 2014

  17. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 09:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me