[pull] master from bitcoin:master - #1872
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 : )