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 drops references to them, or calls the template destroy method, or disconnects. The destroy method is called automatically by clients using libmultiprocess, as sv2-tp does. In the Python tests it also happens when references are destroyed or go out of scope.
Based on:
Commits:
- refactor: move CTransactionRefComp to util/hasher
- mining: track non-mempool memory usage: add
TxTemplateMaptoBlockTemplateManagerto track how many templates contain any given transaction. This map is updated by theBlockTemplateconstructor and destructor. - mining: add GetTemplateMemoryUsage() - loops over this map and sums up the memory footprint for transactions outside the mempool (includes a fuzzer)
- ipc: add getMemoryLoad() expose this information to IPC clients and add test coverage