mining: replace interrupt methods with cancellation arguments - #36097
mining: replace interrupt methods with cancellation arguments#36097xyzconstant wants to merge 2 commits into
Conversation
Add an optional `CancelArg` parameter to the blocking Mining methods `waitTipChanged`, `createNewBlock` and `waitNext`, and deprecate `interrupt()` and `interruptWait()`. The methods pass a CancelFn to the argument, which registers it to run if the call is canceled. In capnp schema, use the `Proxy.extraParam` annotation for the C++ `CancelArg` parameter and the `Cxx.allowCancellation` annotation to enable request cancels at the RPC layer. Update miner_tests to cancel `waitNext()` from another thread, and interface_ipc_mining.py to drop the response promise and check the node logs the cancellation. Also add `drop_promise()` to ipc_util.py to abandon capnp promises.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36097. ReviewsSee the guideline and AI policy for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible typos and grammar issues:
2026-08-27 05:33:17 |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
Wow, this is very cool. The PR contains a lot of boilerplate updates but the heart of the change (5cdb565) is simply: --- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -926,8 +926,9 @@ public:
return SubmitBlock(chainman(), std::make_shared<const CBlock>(m_block_template->block), reason, debug);
}
- std::unique_ptr<BlockTemplate> waitNext(BlockWaitOptions options) override
+ std::unique_ptr<BlockTemplate> waitNext(BlockWaitOptions options, interfaces::CancelArg cancel) override
{
+ if (cancel) cancel([this] { InterruptWait(notifications(), m_interrupt_wait); });
auto new_template = WaitAndCreateNewBlock(chainman(),
notifications(),
m_node.mempool.get(),
@@ -939,11 +940,6 @@ public:
return nullptr;
}
- void interruptWait() override
- {
- InterruptWait(notifications(), m_interrupt_wait);
- }
-
const BlockCreateOptions m_create_options;
const std::unique_ptr<CBlockTemplate> m_block_template;Dropping the With that change rust, python, and c++ clients can now cancel blocking requests more simply and efficiently using cap'n protos native cancellation mechanism, instead of needing to make new IPC calls to cancel previous ones. There's an nontrivial amount of code to review here, but this is a very nice end-to-end implementation and demonstration that supporting this cancellation mechanism is worthwhile and makes things simpler for clients and servers. It could also become more important in the future if we want to have blocking calls that are individually cancellable instead of the current situation where interrupt methods can cancel multiple calls. |
Depends on bitcoin-core/libmultiprocess#342. Only the last commit belongs to this PR.
The blocking methods (
waitTipChanged,createNewBlock, andBlockTemplate::waitNext) currently rely oninterrupt()/interruptWait()to cancel them when they are in progress (#33676, #34184). With request cancellation support in libmultiprocess (bitcoin-core/libmultiprocess#342), this is no longer needed.This PR adds
CancelArgarguments to those blocking methods to register a callback that runs on cancellation and deprecates the interrupt methods.In the capnp schema, use the
Proxy.extraParamannotation for the C++CancelArgparameter and theCxx.allowCancellationannotation to enable request cancellation at the RPC layer.In tests, update miner_tests to cancel
waitNext()from another thread, and interface_ipc_mining.py to drop the response promise. Also adddrop_promise()to ipc_util.py to abandon capnp promises.Additional note: this is the Bitcoin Core side of approach 4 in #33575.