#36047 rpc: handle createNewBlock() returning nullptr during shutdown
https://github.com/bitcoin/bitcoin/pull/36047 · · +40/-4 in 2 files, 1 commits · labels: RPC/REST/ZMQ
Goal
- Prevent mining RPCs from throwing misleading internal bug assertions when called during node shutdown
- Return a clean shutdown error or abort gracefully when block template creation fails on exit
Fixes mining RPC handling when createNewBlock() returns nullptr on node shutdown. Instead of failing a CHECK_NONFATAL assertion and reporting an internal bug, getblocktemplate and generateblock throw a standard RPC_CLIENT_NOT_CONNECTED ("Shutting down") error, and generateBlocks stops mining cleanly.
Problem: When getblocktemplate or generateblock is executed or waiting on longpoll during node shutdown, createNewBlock() returns nullptr. Previously, CHECK_NONFATAL treated this benign shutdown condition as an internal bug.
Category: Mining (#9 of 13)
P3 · bug fix
- P3 because it fixes a minor error-handling race in mining RPCs during node shutdown
- Avoids spurious internal failure reports while longpolling or requesting templates as the node stops
P3 because it fixes a shutdown race in mining RPCs without affecting block validity or template construction logic. Issue #34262 reported assertion failures in getblocktemplate during shutdown; treating nullptr gracefully as an expected shutdown condition avoids false-positive internal error alerts.
Membership: Modifies getblocktemplate, generateblock, and generateBlocks in src/rpc/mining.cpp and updates mining longpoll functional tests.
Factors: security/stability 1, bug 1, performance 0, user value 1, leverage 0
Category: RPC / REST / ZMQ (#30 of 52)
P3 · bug fix
- P3 because it replaces an unhandled assertion failure with a standard shutting down RPC error
- Improves error reporting consistency for clients calling block generation calls during shutdown
P3 because it aligns error reporting across RPC methods during shutdown with the standard RPC_CLIENT_NOT_CONNECTED error.
Membership: Changes RPC exception handling and response codes for getblocktemplate and generateblock in src/rpc/mining.cpp.
Factors: security/stability 1, bug 1, performance 0, user value 1, leverage 0
Reviewability: Ready
- Ready for review
- Small patch with a reproduction functional test and passing CI
The PR has green CI, no conflicts, clean diff with functional test coverage, and no open reviewer requests.
Author status: silent since submission
Agreement: Crickets
- No reviews or concept comments yet
No feedback yet from reviewers
The PR has received no comments or reviews since being opened.
Objections: none enumerated.
State derived from the lists: no substantive comment either way
Review verdicts (DrahtBot): 0
Files
35 lines under test/bench/ci.
- test/functional/mining_getblocktemplate_longpoll.py +34/-1
- src/rpc/mining.cpp +6/-3
Card
This PR handles createNewBlock() returning nullptr during shutdown in getblocktemplate, generateblock, and generateBlocks, replacing a CHECK_NONFATAL assertion with a standard 'Shutting down' RPC error. This resolves issue #34262 where miners using longpolling hit spurious 'Internal bug detected' errors when stopping bitcoind. The PR includes functional test coverage for getblocktemplate longpoll shutdown behavior. It is currently unreviewed.