rpc: fix `getblockstats` for genesis block #26369

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202210-rpc-support_getblockstats_for_genesis_block changing 1 files +9 −5
  1. theStack commented at 11:15 PM on October 22, 2022: contributor

    For the genesis block there is no undo data available, i.e. we can simply use an empty CBlockUndo instance instead of aborting with an "Can't read undo data from disk" error (-1) in this case.

    master branch:

    $ ./src/bitcoin-cli getblockstats 0
    error code: -1
    error message:
    Can't read undo data from disk
    

    PR branch:

    $ ./src/bitcoin-cli getblockstats 0
    {
      "avgfee": 0,
      "avgfeerate": 0,
      "avgtxsize": 0,
      "blockhash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
      "feerate_percentiles": [
        0,
        0,
        0,
        0,
        0
      ],
      "height": 0,
      "ins": 0,
      "maxfee": 0,
      "maxfeerate": 0,
      "maxtxsize": 0,
      "medianfee": 0,
      "mediantime": 1231006505,
      "mediantxsize": 0,
      "minfee": 0,
      "minfeerate": 0,
      "mintxsize": 0,
      "outs": 1,
      "subsidy": 5000000000,
      "swtotal_size": 0,
      "swtotal_weight": 0,
      "swtxs": 0,
      "time": 1231006505,
      "total_out": 0,
      "total_size": 0,
      "total_weight": 0,
      "totalfee": 0,
      "txs": 1,
      "utxo_increase": 1,
      "utxo_size_inc": 117
    }
    
  2. rpc: fix `getblockstats` for genesis block
    For the genesis block there is no undo data available, i.e. we can
    simply use an empty CBlockUndo instance instead of aborting with an
    "Can't read undo data from disk" error (-1) in this case.
    446b11e494
  3. fanquake commented at 11:17 PM on October 22, 2022: member
  4. DrahtBot added the label RPC/REST/ZMQ on Oct 22, 2022
  5. theStack commented at 11:39 PM on October 22, 2022: contributor

    #19888

    Oh nice, I forgot about that one even though I Concept ACKed it a while ago. Some more backgroud why it would be helpful to have the exception for the genesis block in master soon: #26325 (review)

  6. in src/rpc/blockchain.cpp:598 in 446b11e494
     598 | -    }
     599 |  
     600 | -    if (!UndoReadFromDisk(blockUndo, pblockindex)) {
     601 | -        throw JSONRPCError(RPC_MISC_ERROR, "Can't read undo data from disk");
     602 | +    // Ignore genesis block
     603 | +    if (pblockindex->nHeight > 0) {
    


    furszy commented at 11:59 PM on October 22, 2022:

    to minimize the changes to a single line, could just return early if height is 0. e.g.

    // Ignore genesis block
    if (pblockindex->nHeight == 0) return {};
    
    CBlockUndo blockUndo;
    // etc..
    
  7. DrahtBot commented at 10:31 AM on October 23, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26308 (rpc/rest/zmq: reduce LOCK(cs_main) scope: ~6 times as many requests per second by andrewtoth)
    • #19888 (rpc, test: Improve getblockstats for unspendables by fjahr)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  8. theStack commented at 11:58 AM on October 27, 2022: contributor

    Closed in favor of #19888.

  9. theStack closed this on Oct 27, 2022

  10. theStack deleted the branch on Oct 27, 2022
  11. bitcoin locked this on Oct 27, 2023

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-13 15:13 UTC

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