Skip to content

mining: add getMemoryLoad() using BlockTemplateManager#120

Closed
Sjors wants to merge 11 commits into
masterfrom
2026/06/blockman-memusage
Closed

mining: add getMemoryLoad() using BlockTemplateManager#120
Sjors wants to merge 11 commits into
masterfrom
2026/06/blockman-memusage

Conversation

@Sjors

@Sjors Sjors commented Jun 24, 2026

Copy link
Copy Markdown
Owner

ismaelsadeeq and others added 10 commits July 7, 2026 18:47
Add BlockTemplateManager as an encapsulation
that wraps BlockAssembler::CreateNewBlock().

Add a simple unit test that verifies that block
template can be created via the block template manager.
Pass the parsed mining args to BlockTemplateManager at construction and
expose them via GetInitBlockCreateOptions(), 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 mining tip lookup and block-template waiting helpers into
BlockTemplateManager so the manager owns the template waiting flow,
including the notification wait helpers used by waitNext.
Route the Mining interface's createNewBlock() through
BlockTemplateManager::CreateNewTemplate() instead of constructing a
BlockAssembler directly.
Use BlockTemplateManager directly for in-process RPC and test block
template creation instead of going through the IPC Mining interface.

This keeps RPC-created templates untracked and prevents process-static RPC
caches from owning BlockTemplateImpl objects whose destructor reaches back
into NodeContext during shutdown.
Add a fuzz target that creates block templates through
BlockTemplateManager under fuzzed mining options and asserts a template
is always produced.
IPC clients can hold on to block templates indefinately, which has the
same impact as when the node holds a shared pointer to the
CBlockTemplate. Because each template in turn tracks CTransactionRefs,
transactions that are removed from the mempool will not have
their memory cleared.

This commit adds bookkeeping to the block template constructor and
destructor that will let us track the resulting memory footprint.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Calculate the non-mempool memory footprint for template transaction
references.

Add bench logging to collect data on whether caching or simplified
heuristics are needed, such as not checking for mempool presence.
Allow IPC clients to inspect the amount of memory consumed by
non-mempool transactions in blocks.

Returns a MemoryLoad struct which can later be expanded to e.g.
include a limit.

Expand the interface_ipc.py test to demonstrate the behavior and
to illustrate how clients can call destroy() to reduce memory
pressure.
@Sjors Sjors force-pushed the 2026/06/blockman-memusage branch from 1350116 to 1178895 Compare July 7, 2026 16:54
@Sjors

Sjors commented Jul 8, 2026

Copy link
Copy Markdown
Owner Author

I'm going to use this in bitcoin#33922.

@Sjors Sjors closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants