2 suggestions
Optional improvements
[suggestion] · The cache test does not check per-manager ownership
The new unit test exercises only one manager, so a process-wide cache with the same rebuild rules could satisfy every assertion when this case runs in isolation.
Location: src/test/miner_tests.cpp:994 (head).
Details and suggested fix
Every refresh() targets m_node.block_template_manager, so the pointer comparisons check replacement and reuse without distinguishing instance-owned storage from shared storage. After building first, construct a local node::BlockTemplateManager with the fixture's existing mempool, chainman and notifications. Keep first alive and leave the tip, clock and mempool counter unchanged. Under cs_main, require that the local manager returns a different template, then check that both managers keep reusing their own. This covers instance isolation without another fixture or mined block. Optionally, check that a weak_ptr expires after releasing the local snapshot and destroying its manager to cover lifetime too. The current member-based implementation is correct; these assertions would protect it against regression.
[suggestion] · GetCachedTransactionsUpdated() is not checked while counters differ
The unit test would accept an accessor that returned the live mempool counter rather than the cached snapshot used by the RPC's non-string longpoll branch.
Location: src/test/miner_tests.cpp:1014 (head).
Details and suggested fix
The only accessor check follows the rebuild of second, when the cached and live counters agree. Returning m_mempool.GetTransactionsUpdated() from the accessor would satisfy it, and later rebuild assertions would not expose that change because the rebuild helper reads the cached field directly. The next section already increments the live counter and advances the mock clock exactly to the interval boundary, where the strict > check keeps second cached. Capture that refresh and assert that both its transactions_updated and GetCachedTransactionsUpdated() under cs_main still equal second.transactions_updated, while the live counter differs. The accessor is correct today; this protects its snapshot semantics for the RPC's non-string longpoll branch, whose behavior BIP22 leaves unspecified.