mining: add Block interface, fix template data race

bitcoin/bitcoin: PR #36525

1 minor finding · 2 suggestions

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

Findings

Link

[minor] · Concurrency-test cleanup can free BlockTemplateImpl during submitSolution()

After an assertion failure or timeout, the IPC concurrency test can free BlockTemplateImpl while submitSolution() still accesses it, masking the original failure with a use-after-free; this has not been observed.

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

Details and suggested fix

ServerCall checks request_canceled only after the C++ method returns, so cancelling and gathering the Python tasks does not drain the writer request. thisCap() retains the proxy, not the implementation after invokeDestroy() resets m_impl. The stack.aclose() callback sends destroy(reader_ctx) on the other worker, which can free the receiver while the writer copies m_block_template->block or reads m_node. The unsafe window ends once SubmitBlock() is running with the local block and manager reference; passing runs already await every submission.

Stop the submit loop cooperatively and await a bounded barrier on writer_ctx before explicitly destroying the template. If that barrier times out, skip explicit destruction and let capability-lifetime cleanup defer deletion until the active call finishes.


Optional improvements

Link

[suggestion] · Breaking mining.capnp changes lack release notes

The intentional break of the experimental mining IPC interface retires five working methods and changes submission results, but no release-note fragment explains how clients should migrate.

Location: src/ipc/capnp/mining.capnp:51 (head).

Details and suggested fix

doc/developer-notes.md requests a release-note fragment for API changes. The existing IPC release entry covers only the earlier submitSolution @7 retirement, not this migration. Add a doc/release-notes-<PR>.md fragment under IPC Interface mapping getBlockHeader(), getBlock() and getCoinbaseMerklePath() to block().header(), block().data() and block().coinbaseMerklePath(). Identify the replacements block @11, submitSolution @12 and Mining.submitBlock @10, and explain that the retired methods now throw. Both submission methods expose accepted separately from the returned Block, which is available even on rejection. Also document that a null coinbase now throws instead of returning false, that submitSolution() leaves the template unchanged, and that clients should destroy unused Block handles because they retain the block and its transactions.


Link

[suggestion] · Submission-handle independence is not covered by the IPC test

The current per-call allocation is correct, but the IPC test reads each submitted Block only before the next submission, so it would miss reuse of mutable storage between returned handles.

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

Details and suggested fix

In run_coinbase_and_submission_test(), the missing-witness result is overwritten by the successful submitSolution() call. The later assertions read template_block, so they cover template immutability, not preservation of a rejected submission. Keep the rejected Block capability and its expected bytes from returned.serialize(). After the accepted submission, assert that the retained handle still returns those bytes, then destroy it. The existing stripped and full coinbases have distinct serializations, so this checks the documented preservation contract without another submission.


Coverage details

Earlier concerns

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

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The mining IPC interface was explicitly considered experimental: intentional breaking changes were acceptable, and compatibility with previously released versions was not an unconditional guarantee.

In the historical backward-compatibility-test proposal, Sjors explicitly allowed breaking changes and replacing the reference version until stabilization. This distinguishes the current retirement of old getter and submission ordinals from violating a promise that every existing mining client would remain functional.

Source 1 · Source 2 · Source 3

The historical testing debate distinguished detecting accidental incompatibility from making compatibility mandatory. The stated tradeoff was regression detection versus friction and premature maintenance burden while the interface remained experimental.

Sjors argued that accidental breaks could be bugs and that intentional breaks should remain possible. stickies-v opposed compatibility-test friction during experimentation; Sjors subsequently said the related change would omit the backward-compatibility test. These statements explain why compatibility checking should not itself be read as a promise to retain working legacy methods.

Source 1 · Source 2 · Source 3 · Source 4