rpc: Assertion ‘block_template’ failed in getblocktemplate (during shutdown or startup) #34262

issue dergoegge openend this issue on January 12, 2026
  1. dergoegge commented at 1:55 pm on January 12, 2026: member

    The CHECK_NONFATAL check here may fail when getblocktemplate is called during shutdown or during startup.

    0rpc/mining.cpp:875 auto getblocktemplate()::(anonymous class)::operator()(const RPCHelpMan &, const JSONRPCRequest &) const: Assertion `block_template' failed.
    

    See attached debug logs of two examples.

    getblocktemplate_during_startup.log getblocktemplate_during_shutdown.log

    This was found with a test running on Antithesis.

  2. dergoegge renamed this:
    rpc: Assertion `block_template' failed in `getblocktemplate` (during shutdown or startup)
    rpc: Assertion 'block_template' failed in `getblocktemplate` (during shutdown or startup)
    on Jan 12, 2026
  3. maflcko added the label RPC/REST/ZMQ on Jan 12, 2026
  4. maflcko added the label Mining on Jan 12, 2026
  5. maflcko added the label interfaces on Jan 12, 2026
  6. maflcko removed the label interfaces on Jan 12, 2026
  7. DevPatel-11 commented at 2:04 pm on January 17, 2026: none
    I’d like to work on this. Looking at the code now.
  8. DevPatel-11 commented at 6:14 am on January 19, 2026: none

    I tried reproducing this locally by spamming getblocktemplate calls during startup and shutdown, but couldn’t trigger the race condition (given the timing window).

    Looking at the debug logs:

    • Shutdown case: “Shutdown in progress…” message appears right before the assertion failure
    • Startup case: Assertion fails while node is still initializing (network threads just starting)

    Both show Assertion 'block_template' failed, which means createNewBlock() returned nullptr when the mining subsystem wasn’t available.

    The issue is that CHECK_NONFATAL assumes this should never happen, but nullptr is actually a valid return during these states. The fix is to replace the assertion with a proper null check and return an RPC error instead.

    I’ll open a PR with the fix.


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-01-27 06:13 UTC

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