Skip to content

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

Open
chriszeng1010 wants to merge 1 commit into
bitcoin:masterfrom
chriszeng1010:gbt-shutdown-error
Open

chriszeng1010 wants to merge 1 commit into
bitcoin:masterfrom
chriszeng1010:gbt-shutdown-error

Conversation

@chriszeng1010

Copy link
Copy Markdown

Problem

createNewBlock() returns nullptr only when the node is shutting down (WaitTipChanged returns nullopt on interrupt and nothing else). The mining RPCs wrapped the result in CHECK_NONFATAL, reporting an expected shutdown condition as "Internal bug detected".

Fix

getblocktemplate and generateblock now throw "Shutting down" (RPC_CLIENT_NOT_CONNECTED), matching how getblocktemplate's longpoll path already reports the same condition. generateBlocks stops mining and returns the blocks found so far, matching its existing interrupt handling.

Testing

Add regression coverage: a longpoll getblocktemplate interrupted by shutdown must error with "Shutting down". Without the fix this raced ~50/50 between the correct error and the internal-bug error, because the IsRPCRunning() check runs before RPC is disabled during shutdown.

Fixes #34262

@DrahtBot

DrahtBot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

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

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35675 (mining: add block template manager by ismaelsadeeq)
  • #35581 (node: add block template manager and track waitNext fee inflow by ismaelsadeeq)
  • #33922 (mining: add getMemoryLoad() and track template non-mempool memory footprint by Sjors)
  • #32468 (rpc: generateblock to allow multiple outputs by polespinasa)

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.

getblocktemplate and generateblock now throw "Shutting down"
(RPC_CLIENT_NOT_CONNECTED), matching how getblocktemplate's longpoll
path already reports the same condition.
@DrahtBot

Copy link
Copy Markdown
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@sedited

sedited commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Ping for rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rpc: Assertion 'block_template' failed in getblocktemplate (during shutdown or startup)

3 participants