#36047 rpc: handle createNewBlock() returning nullptr during shutdown

ReviewabilityReviewsAgreementSize
#36047 chriszeng1010 rpc: handle createNewBlock() returning nullptr during shutdownAuthor silent 73d0Crickets6 + 34 tests
  • Prevent false internal bug assertions when mining RPCs run during node shutdown
  • Return a standard shutdown error to mining RPC clients instead of an assertion failure
  • Ready to review
  • No review verdicts recorded
  • No reviews or discussion yet
  • No substantive feedback either way
  • 6 lines added or modified outside tests
  • 34 lines added or modified in tests
  • 4 lines removed in total
  • 2 files, 1 commits
Mining#6 of 17
P3 · bug fix
  • P3 because benign shutdown during mining calls triggers false internal bug assertions
  • Affects miners using getblocktemplate or longpolling while stopping the node
  • Ranking pass: Moved up: it is the only fix for a user-reported failure (#34262) miners hit in normal operation, so it leads the P3 block ahead of tooling and refactors.
RPC / REST / ZMQ#27 of 55
P3 · bug fix
  • P3 because callers receive misleading assertion failures rather than standard shutdown error codes
  • Ensures predictable error handling for RPC clients when the node shuts down
  • Ranking pass: Moved up 12: spurious 'Internal bug detected' responses to mining clients at shutdown is a user-visible false error, not cosmetic.
Reviewability: ReadyStalePaused
Agreement: StrongPositivePositive w/ caveatsNeutralMildDisputedBlockedCrickets
Reviews: current code-review ACKs, then (+stale ACKs) and -NACKs; greener = more ACKs.
Size: lines added or modified outside tests, then in tests; greener = smaller.

Goal

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.

Reviewability

Stale · Author silent 73d

No author activity for 73 days; a review may wait a long time for a response.

Waiting on (from the thread read):

Agreement

Crickets

no substantive comment either way

Thread notes: Initial record. Only statement is a process ping from sedited requesting a rebase. / Initial record. No reviews or substantive comments yet, only a rebase ping from sedited.

Objections, suggestions, and questions: none recorded.

Participants:

  • sedited (member, neutral, 1 statements 2026-10-19 to 2026-10-19): pinged for rebase

Files

35 lines under test/bench/ci.

  • test/functional/mining_getblocktemplate_longpoll.py +34/-1
  • src/rpc/mining.cpp +6/-3

Card

The short text the ranking pass compares across PRs.

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.

Data

dossier JSON · extract JSON · model ledger, generated 2026-10-20T01:15, confidence high, input hash 60c62a7f717a12f7
thread read through 2026-10-19 (1 statements), head b1fa37ea86
labels: RPC/REST/ZMQ, Needs rebase

Categories

Mining

P3 · bug fix (ranking pass: Moved up: it is the only fix for a user-reported failure (#34262) miners hit in normal operation, so it leads the P3 block ahead of tooling and refactors.)

Fixes mining RPCs to cleanly handle shutdown rather than triggering a CHECK_NONFATAL assertion. When getblocktemplate longpolls or runs during node shutdown, createNewBlock() returns nullptr, which previously raised a non-fatal assertion reporting an internal bug.

Membership: Changes getblocktemplate and generateblock error handling in src/rpc/mining.cpp when createNewBlock() returns nullptr.

Factors: security/stability 1, bug 1, performance 0, user value 1, leverage 0

RPC / REST / ZMQ

P3 · bug fix (ranking pass: Moved up 12: spurious 'Internal bug detected' responses to mining clients at shutdown is a user-visible false error, not cosmetic.)

Ensures standard RPC error codes are returned instead of internal assertion errors during shutdown. Rather than reporting a non-fatal internal bug, getblocktemplate and generateblock throw standard RPC_CLIENT_NOT_CONNECTED ('Shutting down') errors.

Membership: Labeled RPC/REST/ZMQ and modifies error handling in src/rpc/mining.cpp to return standard RPC_CLIENT_NOT_CONNECTED on shutdown.

Factors: security/stability 1, bug 1, performance 0, user value 1, leverage 0