rpc: add bestblockhash to getmininginfo #36081

pull jakubtrnka wants to merge 1 commits into bitcoin:master from jakubtrnka:rpc-getmininginfo-bestblockhash changing 4 files +12 −0
  1. jakubtrnka commented at 4:04 PM on August 25, 2026: none

    I'm working with pool side mining software.

    I noticed there is a race condition between obtaining bestblockhash and next block nbits. The chaintips may change.

    I thought it might be useful to include bestblockhash in getmininginfo rpc response.

  2. DrahtBot added the label RPC/REST/ZMQ on Aug 25, 2026
  3. DrahtBot commented at 4:04 PM on August 25, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36081.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK Sjors
    Concept ACK pablomartin4btc

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. Sjors commented at 5:19 PM on August 25, 2026: member

    Concept ACK

    We use the tip hash in a few other places to deal with race conditions, e.g. waitfornewblock takes the current tip as an argument.

    utACK 6522d443e8d0326552ac89550313578dbb3bd208 if CI passes

  5. jakubtrnka commented at 5:27 PM on August 25, 2026: none

    CI needs a maintainer to approve the workflow run, I believe.

  6. in doc/release-notes-36081.md:1 in 6522d443e8 outdated


    pablomartin4btc commented at 2:57 AM on August 26, 2026:

    minor nit (if you have to retouch): the release notes filename doesn't follow the naming convention — every other file under doc/ is release-notes-<PR#>.md (so it would be release-notes-36081.md here).


    jakubtrnka commented at 8:17 AM on August 26, 2026:

    ok, good point. I renamed the file.

  7. in src/rpc/mining.cpp:457 in 6522d443e8 outdated
     453 | @@ -454,6 +454,7 @@ static RPCMethod getmininginfo()
     454 |                      RPCResult::Type::OBJ, "", "",
     455 |                      {
     456 |                          {RPCResult::Type::NUM, "blocks", "The current block"},
     457 | +                        {RPCResult::Type::STR_HEX, "bestblockhash", "The hash of the current best block"},
    


    pablomartin4btc commented at 3:04 AM on August 26, 2026:

    On src/rpc/mining.cpp:457: getblockchaininfo's bestblockhash is declared RPCResult::Type::STR, while this one is STR_HEX, which I think is more correct (matches how other hash fields in this file are typed), but worth noting the two now don't match for a field with the same name and meaning.


    Sjors commented at 7:16 AM on August 26, 2026:

    STR_HEX indeed seems better. It might be ok to add refactor commit to switch getblockchaininfo over.

  8. pablomartin4btc commented at 3:05 AM on August 26, 2026: member

    Concept ACK, and utACK at 6522d443e8d0326552ac89550313578dbb3bd208 on the mechanism — nice fix.

    Left a couple of comments (none blocker).

  9. rpc: add bestblockhash to getmininginfo
    Mining software building a block template from getmininginfo's `next`
    object (next height, nBits, target) also needs the hash of the tip that
    `next` was derived from. Today that requires a second call
    (getblockchaininfo or getbestblockhash), which can race with a tip
    change - notably a same-height reorg at a retarget boundary, where the
    two competing tips imply different next nBits.
    
    Return the tip hash from getmininginfo itself so all values come from
    the same tip under a single cs_main lock.
    74e1cd38f2
  10. jakubtrnka force-pushed on Aug 26, 2026
  11. DrahtBot added the label CI failed on Aug 26, 2026
  12. DrahtBot commented at 10:13 AM on August 26, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task Windows native, fuzz, VS: https://github.com/bitcoin/bitcoin/actions/runs/32946989507/job/98116580388</sub> <sub>LLM reason (✨ experimental): CI failed because the fuzz target rpc crashed (exit code 3221225477, likely an access violation) during the fuzz corpus run.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  13. DrahtBot removed the label CI failed on Aug 26, 2026
  14. Sjors commented at 4:59 PM on August 26, 2026: member

    re-ACK 74e1cd38f2a381977b5e46fab6bb15ca17efd349 (just the release note file rename)

  15. DrahtBot requested review from pablomartin4btc on Aug 26, 2026

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-08-31 18:51 UTC

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