[Feature request] getblock with block height #6011

issue jl2012 openend this issue on April 14, 2015
  1. jl2012 commented at 5:33 pm on April 14, 2015: contributor
    Currently, in order to obtain the raw block by block height, it requires to run getblockhash followed by getblock. Is it possible to combine these 2 commands as one? It saves lots of overhead for such request
  2. LivInTheLookingGlass commented at 2:47 pm on April 16, 2015: none

    Point me where these commands are* and I’ll try to come up with a draft.

    *I’m trying to start developing here, this seems like a good excuse.

  3. LivInTheLookingGlass commented at 3:17 pm on April 16, 2015: none
    Am I correct in assuming that getblock refers to this function?
  4. sipa commented at 3:28 pm on April 16, 2015: member

    Gabe: that is correct. That’s the implementation for the getblock RPC, which returns information about a block, specified by hash.

    The request is to have one that works by height.

    If you want to get to understand the code, this is probably a nice assignment, but I’m not sure it’s something we’d be willing to merge. It feels like feature creep to me.

  5. gavinandresen commented at 4:01 pm on April 16, 2015: contributor

    Mild NACK from me on this feature, because the obvious way it would be used is something like:

    for i in 1…current block height get block data for block i

    … to get the current chain data.

    That is not as horribly inefficient as it was before sipa implemented a skip list to quickly find blocks by height, but it is less efficient than the “right” way to do it:

    hash = getbestblockhash blockdata = getblock(hash) while blockdata.height > 1: blockdata = getblock(blockdata.prevblock)

    I’d be willing to switch to a mild ACK if there is a really good use case for “I need a block at a particular height” (besides “I’m implementing a poor man’s block explorer”).

  6. jl2012 commented at 4:58 pm on April 16, 2015: contributor
    @gavinandresen , this is for this proposal: https://github.com/NicolasDorier/BIP-MnemoReference/blob/master/bip-mnemo.mediawiki . While decoding an address, we need to request a block at a particular height.
  7. sipa commented at 6:07 pm on April 16, 2015: member

    Gavin: it’s just getblockhash HEIGHT + getblock of the resulting hash you need right now. Efficiency is not the problem. They’re only complaining about the fact that they need 2 RPC calls instead of 1. Also, the skiplist doesn’t matter here. Indexing into chainActive is O(1) (it has a by-height vector).

    jl2012: that BIP sounds horrible to me. I don’t think we should encourage people to use the blockchain as a mnemonic code.

  8. jl2012 commented at 6:43 pm on April 16, 2015: contributor
    sipa: I just want to show why I have this request. For the BIP you may discuss at https://bitcointalk.org/index.php?topic=965957
  9. LivInTheLookingGlass commented at 2:32 pm on April 20, 2015: none
    I’m going to take a look at how this might be done anyhow, since it looks like there isn’t much I can immediately help on, but I’m generally in agreement with sipa here.
  10. laanwj commented at 12:00 pm on May 18, 2015: member

    NACK from me. This is already possible, and it’s not desirable to burden the interface with ‘shortcuts’. Sounds like feature creep to me as well.

    If request round-trip latency is the problem - say, when requesting lots of block data - use batch JSON-RPC and two phases. In phase one request the block hashes with getblockhash. Then in phase two request the block data. An example can be found in linearize.py (https://github.com/bitcoin/bitcoin/tree/master/contrib/linearize).

    Also: mind that, in contrast to block hashes, block heights are not stable identifiers for a block. This is because of reorganizations.

  11. laanwj closed this on May 18, 2015

  12. jonasschnelli commented at 12:16 pm on May 18, 2015: contributor
    Depends on the use-case but maybe a more optimized way of getting a block at a certain height could be to use REST interface (https://github.com/bitcoin/bitcoin/blob/master/doc/REST-interface.md). There someone could load the tips via rest/chaininfos, with some following rest/block/notxdetails or rest/getheaders if someone likes to start with the genesis block.
  13. DrahtBot locked this on Dec 16, 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: 2024-09-29 01:12 UTC

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