Skip to content

[pull] master from bitcoin:master - #1872

Merged
pull[bot] merged 15 commits into
All-Blockchains:masterfrom
bitcoin:master
Sep 24, 2026
Merged

pull[bot] merged 15 commits into
All-Blockchains:masterfrom
bitcoin:master

Conversation

@pull

@pull pull Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

ismaelsadeeq and others added 15 commits September 13, 2026 11:33
Add BlockTemplateManager, a wrapper around
BlockAssembler::CreateNewBlock(), and store it in NodeContext.

Wire it into node init and test setup so it is reset before its
mempool/chainman dependencies, and update tests and fuzz setups that
rebuild chainman or mempool. Add a unit test that verifies a block
template can be created through the manager.
Pass the parsed mining args to BlockTemplateManager at construction
and expose them via BlockCreateArgs(), so the manager owns the
init-time block create options instead of NodeContext.
Move SubmitBlockStateCatcher and SubmitBlock from miner.cpp into
BlockTemplateManager as a member function. This groups block submission
with block creation in the same class. The function uses m_chainman
directly instead of taking it as a parameter.
Move the mining tip lookup and block-template waiting helpers (GetTip,
WaitTipChanged, WaitAndCreateNewBlock, InterruptWait,
CooldownIfHeadersAhead) into BlockTemplateManager so the manager owns
the template waiting flow. The manager now takes KernelNotifications
at construction.
Route the Mining interface's createNewBlock() through
BlockTemplateManager::CreateNewTemplate() instead of constructing a
BlockAssembler directly. Merging the init-time defaults into unset
options now happens inside CreateNewTemplate(), so every caller gets
them applied.
Add EnsureBlockTemplateManager() and use it in getblocktemplate for tip
lookup and longpoll waiting, while using ChainstateManager directly for
test-chain and IBD checks.
The transactions, fees and sigops costs, and the coinbase outputs
are only read, so reference them from the template instead of copying
them out of it.
The block copy exists solely to apply header adjustments (time, nonce,
version bits) that must not mutate the cached template. Now that the
transactions are read directly from the template, copy only the header
instead of the entire block.
generateblock is no longer safe for fuzzing: it previously threw at
EnsureMining (node.mining is never set in the fuzz setup), but with
EnsureBlockTemplateManager it now executes, mining and submitting a
real block. Submission mutates the chain state shared across fuzz
iterations and writes the block to disk.
The waitforblock, waitforblockheight and waitfornewblock RPCs are no
longer safe for fuzzing: they previously threw at EnsureMining
(node.mining is never set in the fuzz setup), but with
EnsureBlockTemplateManager they now really wait. The tip never changes
during fuzzing and nothing interrupts the wait, so a call without a
timeout blocks forever.
3d7d190 ci: enforce iwyu for block template manager (ismaelsadeeq)
ffe3a63 node: remove NodeContext::mining and EnsureMining (ismaelsadeeq)
6c71166 test: create templates via BlockTemplateManager (ismaelsadeeq)
ec4f24e rpc: wait for tips via BlockTemplateManager (ismaelsadeeq)
8372721 rpc: build generation templates via BlockTemplateManager (ismaelsadeeq)
38556f8 rpc: only copy the header in getblocktemplate (ismaelsadeeq)
951fac8 rpc: do not copy template data in getblocktemplate (ismaelsadeeq)
0998c0b rpc: build getblocktemplate via BlockTemplateManager (ismaelsadeeq)
011cbfb rpc: route getblocktemplate internals through node (ismaelsadeeq)
400ac32 interfaces: create block template via BlockTemplateManager (ismaelsadeeq)
037d351 node: move tip and wait helpers into BlockTemplateManager (ismaelsadeeq)
07964c5 miner: move SubmitBlock into BlockTemplateManager (ismaelsadeeq)
bcdadf2 node: move mining_args to BlockTemplateManager (ismaelsadeeq)
482a5d2 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 3d7d190
  marcofleon:
    light code review ACK 3d7d190
  pablomartin4btc:
    re-ACK 3d7d190

Tree-SHA512: 885af752ecd105f9813e75de87b9e022b151e5959aae3ef00de838ca4b07ce19ee24a80629dd80bb5261d4b090b4f7832f09c4d8147e4265c54c7f8926694590
@pull pull Bot locked and limited conversation to collaborators Sep 24, 2026
@pull pull Bot added the ⤵️ pull label Sep 24, 2026
@pull
pull Bot merged commit 5c726f2 into All-Blockchains:master Sep 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants