{
 "number": 36047,
 "repo": "bitcoin/bitcoin",
 "url": "https://github.com/bitcoin/bitcoin/pull/36047",
 "title": "rpc: handle createNewBlock() returning nullptr during shutdown",
 "author": "chriszeng1010",
 "author_association": "FIRST_TIME_CONTRIBUTOR",
 "created_at": "2026-08-20T19:20:28Z",
 "updated_at": "2026-09-15T07:05:23Z",
 "age_days": 27,
 "draft": false,
 "labels": [
  "RPC/REST/ZMQ"
 ],
 "milestone": null,
 "base": "master",
 "head_sha": "b1fa37ea86818cf68ef70e695e55eed93b850881",
 "head_ref": "gbt-shutdown-error",
 "head_repo": "chriszeng1010/bitcoin",
 "head_history": [
  {
   "t": "2026-08-20T19:23:17Z",
   "sha": "c283ed3f349d1764424291ca98b61314e4ba60d5"
  },
  {
   "t": "2026-08-20T19:24:03Z",
   "sha": "b1fa37ea86818cf68ef70e695e55eed93b850881"
  }
 ],
 "additions": 40,
 "deletions": 4,
 "changed_files": 2,
 "commit_count": 1,
 "size_bucket": "S",
 "mergeable_state": "unknown",
 "bot": {
  "drahtbot": {
   "present": true,
   "reviews": {},
   "conflicts": [
    {
     "number": 35675,
     "title": "mining: add block template manager",
     "author": "ismaelsadeeq"
    },
    {
     "number": 35581,
     "title": "node: add block template manager and track waitNext fee inflow",
     "author": "ismaelsadeeq"
    },
    {
     "number": 33922,
     "title": "mining: add getMemoryLoad() and track template non-mempool memory footprint",
     "author": "Sjors"
    },
    {
     "number": 32468,
     "title": "rpc: generateblock to allow multiple outputs",
     "author": "polespinasa"
    }
   ]
  }
 },
 "acks_parsed": {},
 "acks_tally": {
  "ack": 0,
  "stale_ack": 0,
  "concept_ack": 0,
  "approach_ack": 0,
  "nack": 0,
  "concept_nack": 0,
  "approach_nack": 0
 },
 "reviews": {
  "approved": 0,
  "changes_requested": 0,
  "distinct_reviewers": []
 },
 "signals": {
  "needs_rebase": false,
  "ci_failed": false,
  "mergeable_state": "unknown",
  "last_author_activity": "2026-08-20T19:24:03Z",
  "last_reviewer_activity": null,
  "last_reviewer": null,
  "author_silent_days": 27,
  "waiting_on_author_days": 0,
  "days_since_update": 2
 },
 "refs": {
  "mentioned": [
   34262
  ],
  "depends_on": [],
  "fixes": [
   34262
  ],
  "linked_issues": [
   {
    "number": 34262,
    "type": "issue",
    "state": "open",
    "merged": false,
    "merged_at": null,
    "title": "rpc: Assertion 'block_template' failed in `getblocktemplate` (during shutdown or startup)"
   }
  ],
  "references": [
   {
    "number": 34262,
    "type": "issue",
    "state": "open",
    "merged": false,
    "merged_at": null,
    "title": "rpc: Assertion 'block_template' failed in `getblocktemplate` (during shutdown or startup)"
   }
  ],
  "conflicts": [
   35675,
   35581,
   33922,
   32468
  ]
 },
 "stack": {
  "shares_commits_with": [],
  "based_on": [],
  "base_for": []
 },
 "review_paths": [],
 "body": "### Problem\ncreateNewBlock() 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\".\n\n### Fix\ngetblocktemplate 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.\n\n### Testing\nAdd 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.\n\nFixes #34262",
 "commits": [
  {
   "sha": "b1fa37ea86818cf68ef70e695e55eed93b850881",
   "date": "2026-08-20T19:24:00Z",
   "message": "rpc: handle createNewBlock() returning nullptr during shutdown\n\ngetblocktemplate and generateblock now throw \"Shutting down\"\n(RPC_CLIENT_NOT_CONNECTED), matching how getblocktemplate's longpoll\npath already reports the same condition."
  }
 ],
 "timeline": [
  {
   "t": "2026-08-20T19:23:17Z",
   "kind": "force_push",
   "who": "chriszeng1010",
   "commit": "c283ed3f349d1764424291ca98b61314e4ba60d5"
  },
  {
   "t": "2026-08-20T19:24:03Z",
   "kind": "force_push",
   "who": "chriszeng1010",
   "commit": "b1fa37ea86818cf68ef70e695e55eed93b850881"
  }
 ],
 "labels_log": [
  {
   "t": "2026-08-20T19:20:32Z",
   "action": "labeled",
   "label": "RPC/REST/ZMQ",
   "who": "DrahtBot"
  }
 ],
 "state_log": [],
 "text_chars": 1156,
 "text_tokens_estimate": 289,
 "changed_paths": [
  "src/rpc/mining.cpp",
  "test/functional/mining_getblocktemplate_longpoll.py"
 ],
 "files": [
  {
   "path": "src/rpc/mining.cpp",
   "add": 6,
   "del": 3
  },
  {
   "path": "test/functional/mining_getblocktemplate_longpoll.py",
   "add": 34,
   "del": 1
  }
 ],
 "test_lines": 35,
 "git": {
  "head": "b1fa37ea86818cf68ef70e695e55eed93b850881",
  "head_matches_backup": true,
  "base": "f72537037d3350e2974efd760eaa7b04f820880c",
  "commits": [
   {
    "sha": "b1fa37ea86",
    "subject": "rpc: handle createNewBlock() returning nullptr during shutdown",
    "files": 2,
    "add": 40,
    "del": 4
   }
  ],
  "patch_truncated": false
 },
 "input_hash": "06dc27db3b4e8dc2",
 "extracted_at": "2026-09-17T16:15:31+00:00"
}