Optimize JSON-RPC getblockhash #1612

pull luke-jr wants to merge 1 commits into bitcoin:master from luke-jr:opti_getblkhash changing 3 files +21 −4
  1. luke-jr commented at 8:09 PM on July 19, 2012: member
    • If the height is in the first half, start at the genesis block and go up, rather than at the top
    • Cache the last lookup and use it as a reference point if it's close to the next request, to make linear lookups always fast
  2. gmaxwell commented at 3:50 AM on July 30, 2012: contributor

    Good idea, I've noticed this being slow in some of my tools. Unfortunately, during a reorg I think your cache could end up pointing off into space. It's probably fine to just invalidate the cache every time the chain is updated.

  3. jgarzik commented at 5:15 PM on August 1, 2012: contributor

    or do what pynode does, and maintain a (height)->(list of block hashes) index... ;)

    weak ACK, but sounds like it needs updating based on @gmaxwell 's comments

  4. Optimize JSON-RPC getblockhash
    - If the height is in the first half, start at the genesis block and go up, rather than at the top
    - Cache the last lookup and use it as a reference point if it's close to the next request, to make linear lookups always fast
    1be064190e
  5. luke-jr commented at 6:24 PM on August 1, 2012: member

    Moved to main.cpp and added code to clear the cache whenever the best block changes.

  6. gmaxwell commented at 6:49 PM on August 1, 2012: contributor

    Tests out fine for me.

  7. gmaxwell referenced this in commit 8ce7915aad on Aug 1, 2012
  8. gmaxwell merged this on Aug 1, 2012
  9. gmaxwell closed this on Aug 1, 2012

  10. 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-14 15:16 UTC

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