AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 19 Bitcoin

Merge bitcoin/bitcoin#35675: mining: add block template manager

Public commit record

What the developer wrote

Authored by Ryan Ofsky

91/100 · Strong
Merge bitcoin/bitcoin#35675: mining: add block template manager

3d7d190b6995b3c0adb6528c2d9eac81a8f839d9 ci: enforce iwyu for block template manager (ismaelsadeeq)
ffe3a631f38b1224db8b0ea246a3c976f358c59e node: remove NodeContext::mining and EnsureMining (ismaelsadeeq)
6c71166bcfa4339d5019f2b27d477eb45ce7fe86 test: create templates via BlockTemplateManager (ismaelsadeeq)
ec4f24ef181a7987bcea72a21e507f59dc1b8126 rpc: wait for tips via BlockTemplateManager (ismaelsadeeq)
8372721f20e2ea2c15bae38a046476736169d801 rpc: build generation templates via BlockTemplateManager (ismaelsadeeq)
38556f817e060187b48cd31490f578cdf63134ee rpc: only copy the header in getblocktemplate (ismaelsadeeq)
951fac807d37302e7de5e289c0ab05f8dfcb1e1c rpc: do not copy template data in getblocktemplate (ismaelsadeeq)
0998c0bbdfcc3c3f7c105a1fb7223bace529556a rpc: build getblocktemplate via BlockTemplateManager (ismaelsadeeq)
011cbfbcd2e3a3282ae7e5afdfd923bc444d1845 rpc: route getblocktemplate internals through node (ismaelsadeeq)
400ac328c91b653e793bd140b89e8fabfb42e3ac interfaces: create block template via BlockTemplateManager (ismaelsadeeq)
037d3519f2ff9937aa82060a42939aafab4179f1 node: move tip and wait helpers into BlockTemplateManager (ismaelsadeeq)
07964c525d4769d00004b9942225a2cb1306e09d miner: move SubmitBlock into BlockTemplateManager (ismaelsadeeq)
bcdadf2b7111a061d2bbeba350233db7b258a787 node: move mining_args to BlockTemplateManager (ismaelsadeeq)
482a5d27124c4241c27ed323659914cd38409650 node: introduce BlockTemplateManager (ismaelsadeeq)

Pull request description:

This PR introduces `node::BlockTemplateManager` and moves block template
creation, submission, and mining wait helpers behind it.

#### Motivation

Instead of keeping template-related state and helper functions spread across
`NodeContext`, `miner.cpp`, the mining interface, RPC, and tests, the manager
now owns the node's init-time mining options and exposes methods needed by callers.

This also prevents some redundant copies previously done when using the mining
interface to create a block template and then retrieve the template data.

This keeps the IPC `Mining` interface focused on IPC-facing mining objects, while RPC
and tests use the block template manager directly.

#### Changes

- `NodeContext` no longer stores `BlockCreateOptions` directly.
- `BlockTemplateManager` stores the parsed init-time mining options and applies
them to unset per-call options before creating templates.
- Block submission through the mining interface is routed through
`BlockTemplateManager::SubmitBlock()`, preserving the existing
`BlockChecked` state-capture behavior.
- Tip lookup, tip waiting, cooldown, and `waitNext()` template creation helpers
are moved from miner helper functions into `BlockTemplateManager`.
- In-process RPC and tests create raw `CBlockTemplate` objects directly through
`BlockTemplateManager`, avoiding cached `BlockTemplateImpl` objects that hold
`NodeContext` references during shutdown.

#### Note: This change is intended to be a pure refactor that preserves behavior.

ACKs for top commit:
Sjors:
re-ACK 3d7d190b6995b3c0adb6528c2d9eac81a8f839d9
marcofleon:
light code review ACK 3d7d190b6995b3c0adb6528c2d9eac81a8f839d9
pablomartin4btc:
re-ACK 3d7d190b6995b3c0adb6528c2d9eac81a8f839d9

Tree-SHA512: 885af752ecd105f9813e75de87b9e022b151e5959aae3ef00de838ca4b07ce19ee24a80629dd80bb5261d4b090b4f7832f09c4d8147e4265c54c7f8926694590
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This is a large internal code reorganization (refactor) in Bitcoin Core. It creates a new BlockTemplateManager class that takes over block-template creation, block submission, and tip-waiting helpers that were previously spread across several modules. The pull request description explicitly says it is intended to be a pure refactor that preserves behavior. No new user-facing feature is added and no vulnerability is evident in the diff.

Recommended action

No immediate security action required. Treat as a normal refactor review: verify CI passes, confirm the new reset ordering prevents use-after-free during shutdown/reindex, and monitor for any follow-up fixes if behavior diverges from the old Mining interface.

Security signals we found

01

Large refactor touching mining, RPC, interfaces, and test shutdown paths

02

New object lifetime dependency: BlockTemplateManager holds references to mempool, chainman, and notifications; explicit reset ordering added in Shutdown/InitAndLoadChainstate/test setups

03

Removal of early-init node.mining interface; BlockTemplateManager is now created after chainstate load, with a comment that it must exist before setChainstateLoaded(true) unblocks IPC waiters

04

getblocktemplate no longer copies the entire CBlock; works with block_template->block header and fields directly

05

Fuzz harness marks additional mining/wait RPCs as unsafe for fuzzing

Risk score

Why this scored 19/100

Our methodology →
Potential impact 2/30
Exploitability 1/25
Stealth signal 1/15
Affected reach 3/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.