Provider refusals
write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.
1 major finding · 2 minor findings · 2 suggestions
Findings
[major] · Template destruction can access BlockTemplateManager after shutdown resets it
A connected IPC client holding templates can trigger an abort or undefined behavior during shutdown; the exact outcome depends on thread scheduling.
Location: src/node/interfaces.cpp:894 (head).
Details and suggested fix
~BlockTemplateImpl now calls block_template_manager(), which dereferences m_node.block_template_manager through Assert. During shutdown, disconnectIncoming() queues server-object destruction asynchronously, but shutdown resets the manager without waiting for that cleanup. If an IPC client such as sv2-tp still holds templates, their destructor may run after the reset and Assert may abort, or it may race with the reset and access freed manager state. This occurs only during an already-requested shutdown with a connected IPC client; chainstate has already been flushed, so the effect is an abort or undefined behavior on the way out, not an attacker-caused availability loss. Move the reference-count map into a std::shared_ptr-owned tracker retained by each template, or make shutdown wait for IPC cleanup before resetting the manager. A null check alone would not prevent the race.
[minor] · Memory estimate omits each non-mempool transaction's own allocation
getMemoryLoad() underreports non-mempool transactions held by templates, especially when they contain many small transactions.
Location: src/node/block_template_manager.cpp:105 (head).
Details and suggested fix
RecursiveDynamicUsage(*tx_ref) selects the CTransaction overload, which counts the input and output vectors and their nested allocations but omits the heap-allocated transaction object and its shared-pointer control block. Those allocations remain while a template holds the reference. The std::shared_ptr overload includes them, as used for mempool entries. Pass tx_ref rather than *tx_ref so the estimate includes the shared-pointer allocation overhead.
[minor] · Wtxid-keyed tracking merges separate allocations of the same transaction
After a transaction is removed and readmitted, the map can hide a retained copy from getMemoryLoad() and keep it alive; no production occurrence or frequency was identified.
Location: src/node/block_template_manager.h:46 (head).
Details and suggested fix
TxTemplateMap compares transactions by wtxid, so tracking a second allocation with the same wtxid increments the first allocation's entry instead of recording the second. This can occur when a template retains allocation A, the transaction leaves the mempool, and a fresh allocation B is readmitted and included in another template. While B is in the mempool, the memory estimate skips the entry because that wtxid exists, even though only the first template holds A. When the first template is released, the map key keeps A alive until the second template is released. After B leaves the mempool, the allocations are counted once. No production occurrence or frequency was identified; the behavior requires a template to outlive the transaction's removal and readmission. Key entries by const CTransaction* and store the corresponding CTransactionRef and count as the value; skip an entry only when the mempool returns that same pointer.
Optional improvements
[suggestion] · Template refcounting test relies on a crash unavailable in release builds
Overlapping-template refcounting regressions can pass this test in non-Debug builds, and leaked entries are not detected.
Location: test/functional/interface_ipc_mining.py:328 (head).
Details and suggested fix
The test comment says a refcounting regression “should result in a crash,” but a missing entry reaches Assume, which aborts only in Debug builds with ABORT_ON_FAILED_ASSUME or in fuzzing builds. Too few decrements can leak entries without triggering that check. The usage check in this block runs while all template transactions remain in the mempool, so it can pass even if nothing is tracked. While template4 through template6 are alive, mine their transactions out of the mempool and assert that usage is greater than zero. Destroy one template that shares those transactions and assert that usage remains greater than zero, then destroy the rest and assert that usage is zero. Update the comment so it does not promise a crash.
[suggestion] · New SanityCheck() helper is never called
Its invariant checks never run, and the fuzzer mentioned in the PR description is not included in this patch.
Location: src/node/block_template_manager.cpp:110 (head).
Details and suggested fix
The repository references BlockTemplateManager::SanityCheck() only in its declaration and definition. No unit test or fuzz target calls it or the tracking and memory-usage methods, although the PR description says the GetTemplateMemoryUsage commit “includes a fuzzer.” Remove the unused helper, or add a test or fuzz target that builds overlapping templates and calls SanityCheck() after each change.