Make FindBlockByHeight constant-time #2644

pull sipa wants to merge 1 commits into bitcoin:master from sipa:constfindblock changing 5 files +36 −51
  1. sipa commented at 1:54 PM on May 12, 2013: member

    Remove the pnext pointer in CBlockIndex, and replace it with a vBlockIndexByHeight vector (no effect on memory usage). pnext can now be replaced by vBlockIndexByHeight[nHeight+1], but FindBlockByHeight becomes constant-time.

    This also means the entire mapBlockIndex structure and the block index entries in it become purely blocktree-related data, and independent from the currently active chain, potentially allowing them to be protected by separate mutexes in the future.

  2. Make FindBlockByHeight constant-time.
    Remove the pnext pointer in CBlockIndex, and replace it with a
    vBlockIndexByHeight vector (no effect on memory usage). pnext can
    now be replaced by vBlockIndexByHeight[nHeight+1], but
    FindBlockByHeight becomes constant-time.
    
    This also means the entire mapBlockIndex structure and the block
    index entries in it become purely blocktree-related data, and
    independent from the currently active chain, potentially allowing
    them to be protected by separate mutexes in the future.
    0fe8010a10
  3. BitcoinPullTester commented at 6:20 PM on May 12, 2013: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/0fe8010a10bafd67f9131b2da034fb9cd7fc5024 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.

  4. jgarzik commented at 6:46 PM on May 12, 2013: contributor

    Code looks sane and ACK-worthy. The concept is similar to something I did in pynode.

    Did you actually instrument "no effect on memory usage", or is that a guess? I would like to see before and after numbers proving that :)

  5. sipa commented at 7:45 PM on May 12, 2013: member

    @jgarzik Just reasoning. For each CBlockIndex representing a node in the active chain, we remove 8 bytes from the CBlockIndex, and add 8 bytes to vBlockIndexByHeight. Actually, it should reduce memory usage slightly, as non-best-chain nodes also lose 8 bytes.

  6. jgarzik referenced this in commit d397715661 on May 30, 2013
  7. jgarzik merged this on May 30, 2013
  8. jgarzik closed this on May 30, 2013

  9. DrahtBot 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