Review report

bitcoin/bitcoin: PR #36525

1 minor finding · 2 suggestions

Earlier concerns neither republished nor resolved: 3 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · Failure-path cleanup can destroy a template still used by the writer

On test timeout or a reader exception, cancelling the Python tasks can leave submitSolution() running while cleanup destroys its template, causing a secondary crash or sanitizer failure.

Location: test/functional/interface_ipc_mining.py:923 (head).

Details and suggested fix

If the outer timeout cancels the loops, or read_loop raises while the writer RPC is executing, cancelling and gathering the Python tasks does not drain that native call. ServerCall releases its cancellation lock during execution and observes cancellation only afterward. The exit stack nevertheless calls destroy(reader_ctx), whose handler resets m_impl independently of the writer worker. The writer retains the ProxyServer wrapper, not a separate implementation owner, so destruction can free BlockTemplateImpl and its mutex while the writer mutates or copies the block, or reads m_node to obtain the manager. The window ends once SubmitBlock() runs on its local shared pointer; successful runs await the calls and are unaffected. A secondary failure can obscure the original test failure. Stop the loops cooperatively using done in both loops, then await a bounded barrier such as getBlockHeader(writer_ctx) before explicit destruction. If the barrier cannot complete, skip the exit stack's destroy() callback and drop the capability instead, allowing the in-flight call's reference to defer implementation cleanup.


Optional improvements

Link

[suggestion] · getTotalFees() leaves prioritisation deltas undocumented

The new IPC getter returns actual fees, not modified fees, but its contract does not state that distinction or connect the total to waitNext()'s fee threshold.

Location: src/interfaces/mining.h:50 (head).

Details and suggested fix

When transactions have prioritisetransaction deltas, nFees still sums entry.GetFee(), and getTotalFees() returns that sum, matching sum(getTxFees()) rather than the modified fees used for selection. The prioritised-mining test explicitly expects 2,000 satoshis with deltas excluded. Document in mining.h and CBlockTemplate::m_total_fees that the value is the sum of actual fees for non-coinbase transactions, excluding prioritisation deltas and the block subsidy, and that waitNext() measures fee_threshold against this total. This clarifies the new IPC contract without changing fee accounting.


Link

[suggestion] · Concurrent template test omits the merkle-path getter

The new reader loop never exercises getCoinbaseMerklePath(), although that getter reads the same coinbase entry that submitSolution() replaces.

Location: test/functional/interface_ipc_mining.py:907 (head).

Details and suggested fix

getCoinbaseMerklePath() calls TransactionMerklePath(), which reads every block.vtx entry, including vtx[0]. This read occurs even when a coinbase-only template produces an empty branch. No functional or unit test currently calls the getter. Add await template.getCoinbaseMerklePath(reader_ctx) to read_loop to exercise it alongside the writer under TSan at little additional cost. The getter is correctly locked, and GUARDED_BY(m_mutex) already makes a lock-only removal a Clang thread-safety error in CI, so this adds runtime coverage alongside the existing static checks.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.