#36357 mining: move BlockAssembler statics into BlockTemplateManager

ReviewabilityReviewsAgreementSize
#36357 w0xlt mining: move BlockAssembler statics into BlockTemplateManagerWaiting on author0Strong110 + 91 tests
  • Ensure getmininginfo reports actual mining templates rather than fee estimator templates
  • Eliminate thread-unsafe global state for block weight and transaction counts
  • Concept approval for consolidating template caching in BlockTemplateManager (ismaelsadeeq)
  • Open suggestion to also move the block template cache into BlockTemplateManager (ismaelsadeeq)
  • 110 lines added or modified outside tests
  • 91 lines added or modified in tests
  • 44 lines removed in total
  • 5 files, 3 commits
Mining#9 of 17
P3 · bug fix
  • P3 because it fixes inaccurate template statistics reported by getmininginfo during fee estimation
  • Eliminates global static variables to improve thread safety and multi-node isolation
Reviewability: ReadyStalePaused
Agreement: StrongPositivePositive w/ caveatsNeutralMildDisputedBlockedCrickets
Reviews: current code-review ACKs, then (+stale ACKs) and -NACKs; greener = more ACKs.
Size: lines added or modified outside tests, then in tests; greener = smaller.

Goal

Moves process-wide block template statistics from BlockAssembler into per-instance fields, recording them in BlockTemplateManager under cs_main. The getmininginfo RPC is updated to read currentblockweight and currentblocktx from BlockTemplateManager rather than process-wide statics.

Problem: getmininginfo reads global static variables that lack thread-safety annotations and are overwritten by any call to BlockAssembler::CreateNewBlock(). Background operations like mempool fee estimation build templates with BlockAssembler, causing getmininginfo to report fee estimation templates instead of actual mining templates, while also hindering multi-node context isolation.

Evidence of importance:

  • PR description: "getmininginfo reports currentblockweight and currentblocktx from two process-wide statics, BlockAssembler::m_last_block_weight and m_last_block_num_txs, which every BlockAssembler::CreateNewBlock() call overwrites... the mempool fee estimator builds its own templates with BlockAssembler, so getmininginfo can report the fee estimator's template instead of the last mining template."
  • Commit e47e7acca3: "Behavior change: only templates built through BlockTemplateManager (getblocktemplate, the generate RPCs and the mining interface) update these fields. Templates that the mempool fee estimator builds with BlockAssembler directly no longer do..."
  • Issue #33758: completes the 'Remove remaining global states' item in the BlockTemplateManager tracking issue.

Scope: Stacked on PR #36356; the diff includes commits from #36356 that move getblocktemplate caching into BlockTemplateManager.

Risk of a mistake: medium (rpc_api, other). Holding cs_main across template creation or mishandling template cache state could introduce locking contention or report inaccurate mining statistics in RPC responses.

Reviewability

Paused · Waiting on author

Open objection from ismaelsadeeq with no author reply for 34 days; review would repeat what has been asked.

Waiting on (from the thread read):

  • author: response to ismaelsadeeq's suggestion to move the block template cache into BlockTemplateManager 2026-09-28
  • author: response to ismaelsadeeq's suggestion about caching in BlockTemplateManager 2026-09-28

Agreement

Strong

substantive support, no open objection (ismaelsadeeq)

Thread notes: Initial record. ismaelsadeeq gave Concept ACK and suggested moving the template cache into BlockTemplateManager. / Initial record. ismaelsadeeq gave a Concept ACK and suggested extending the scope to include block template caching.

Objections, suggestions, and questions:

ReviewerTypeHarm, request, or questionStatusMust beAuthor repliedQuote
ismaelsadeeq (member)suggestion, scopeMove the block template cache into BlockTemplateManager to consolidate caching and reduce fee estimator dependenciesopenansweredno2026-09-28: 'Now that #34075 is merged, we can also move its cache in there, i.e cache the block template based on time and tip changes.'

Support:

  • ismaelsadeeq (member) (Concept ACK, 2026-09-28) [read: BlockTemplateManager]: moving cache into BlockTemplateManager consolidates template caching and reduces fee estimator reliance on chainstate manager

Participants:

  • ismaelsadeeq (member, support, 1 statements 2026-09-28 to 2026-09-28): Concept ACK; suggests moving the #34075 block template cache into BlockTemplateManager

Dependencies

Depends on: #36356

Files

91 lines under test/bench/ci.

  • src/test/miner_tests.cpp +91/-0
  • src/node/block_template_manager.cpp +49/-2
  • src/rpc/mining.cpp +12/-36
  • src/node/block_template_manager.h +45/-2
  • src/node/miner.h +4/-4

Card

The short text the ranking pass compares across PRs.

Moves process-wide block statistics from BlockAssembler into instance variables and stores mining stats in BlockTemplateManager under cs_main. Currently, getmininginfo reads unannotated global statics that are overwritten by any template build across the process, including non-mining templates generated by the mempool fee estimator. With this change, getmininginfo reports metrics solely from templates built for mining, and template state is cleanly scoped to each node context. Based on PR #36356.

Data

dossier JSON · extract JSON · model ledger, generated 2026-09-29T01:26, confidence high, input hash bcc8c0d9a0eb0ae1
thread read through 2026-09-28 (1 statements), head e47e7acca3
labels: Mining · draft

Categories

Mining

P3 · bug fix

Fixes inaccurate mining statistics reporting in getmininginfo and eliminates thread-unsafe global state. As noted in the description, 'the mempool fee estimator builds its own templates with BlockAssembler, so getmininginfo can report the fee estimator's template instead of the last mining template,' and moving these fields to BlockTemplateManager resolves this cross-subsystem contamination while progressing issue #33758.

Membership: Carries the Mining label and modifies src/node/miner.h, src/node/block_template_manager.{h,cpp}, and src/rpc/mining.cpp to manage block template metrics.

Factors: security/stability 1, bug 1, performance 0, user value 1, leverage 1