Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
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. |
|
🚧 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. |
5cdb565 to
1c02f2a
Compare
|
Updated to match the latest changes in the upstream PR. Notable changes:
|
1c02f2a to
a066bd8
Compare
Mirror bitcoin/bitcoin#36097. Long-running calls can now be stopped by dropping their promise, so explicit interrupt methods are no longer needed.
Mirror bitcoin/bitcoin#36097. Long-running calls can now be stopped by dropping their promise, so explicit interrupt methods are no longer needed.
Mirror bitcoin/bitcoin#36097. Long-running calls can now be stopped by dropping their promise, so explicit interrupt methods are no longer needed.
a066bd8 to
a4e7b2e
Compare
a4e7b2e to
201738b
Compare
baa1510 to
d5aad83
Compare
Add an optional StopToken parameter to the blocking Mining methods waitTipChanged, createNewBlock, and waitNext, and deprecate interrupt() and interruptWait(). Each method registers a StopCallback that interrupts the wait when stop is requested or the request is canceled. Use std::stop_token for interfaces::StopToken where the standard library provides it. Since libc++ 19 only provides it with -fexperimental-library, use a minimal replacement with stop_token, stop_source, and stop_callback semantics, made cancelable over IPC by overloads in ipc/capnp/common-types.h. In the Cap'n Proto schema, annotate the C++ StopToken parameter with Proxy.extraParam and enable RPC request cancellation with Cxx.allowCancellation. Update miner_tests to stop waitNext() from another thread; update ipc_tests to cancel a call by requesting stop; and update interface_ipc_mining.py to drop the response promise and verify that the node logs the cancellation. Add drop_promise() to ipc_util.py to abandon Cap'n Proto promises.
d5aad83 to
4e377f9
Compare
|
🐙 This pull request conflicts with the target branch and needs rebase. |

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 an optional
StopTokenparameter to those blocking methods and deprecates the interrupt methods. Each method registers aStopCallbackon the token that interrupts the wait when stop is requested, or the IPC request is canceled.In the capnp schema, use the
Proxy.extraParamannotation for the C++StopTokenparameter and theCxx.allowCancellationannotation to enable request cancellation at the RPC layer.interfaces::StopTokenisstd::stop_tokenwhere the standard library provides it by default, and libmultiprocess'smp/type-stop-token.hmakes it cancelable over IPC. libc++ 19, the minimum supported Clang version, and the FreeBSD base-system library only provide it with-fexperimental-library. There,interfaces::StopTokenis a minimal replacement type withstop_token/stop_source/stop_callbacksemantics, and theCustomBuildExtraParam/CustomReadExtraParamoverloads inipc/capnp/common-types.hmake it cancelable over IPC. These can be removed once the minimum supported libc++ providesstd::stop_tokenby default.In tests, update miner_tests to stop
waitNext()from another thread, ipc_tests to cancel awaitCancelcall by requesting stop, and interface_ipc_mining.py to drop the response promise and check that the node logs the cancellation. Also adddrop_promise()to ipc_util.py to abandon capnp promises.Additional note: this is the Bitcoin Core side of approach 4 in #33575.