Implements a way to track the memory footprint of all non-mempool transactions that are still being referenced by block templates, see discussion in #33899. It does not impose a limit.
IPC clients can query this footprint (total, across all clients) using the getMemoryLoad() IPC method. Its client-side usage is demonstrated here:
Additionally, the functional test in interface_ipc.py is expanded to demonstrate how template memory management works: templates are not released until the client disconnects or calls the destroy() method. The latter happens automatically for clients using libmultiprocess, as sv2-tp does.
The PR starts with preparation refactor commits:
- Tweaks
interface_ipc.pysodestroy()calls happen in an order that’s useful to later demonstrate memory management - Change
std::unique_ptr<BlockTemplate> block_templatefrom astaticdefined inrpc/mining.cpptoNodeContext. This prevents a crash when we switch to a non-trivial destructor later (which usesm_node).
Then the main commits:
- Add
template_tx_refstoNodeContextto track how many templates contain any given transaction. This map is updated by theBlockTemplateconstructor and destructor. - Add
GetTemplateMemoryUsage()which loops over this map and sums up the memory footprint for transactions outside the mempool - Expose this information to IPC clients via
getMemoryLoad()and add test coverage