mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 09:35:38 +00:00
WIP: mining: replace interrupt methods with cancellation arguments #36097
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36097
Loading…
Reference in a new issue
No description provided.
Delete branch "ipc-cancellation-support"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.
Conflicts
Reviewers, this pull request conflicts with the following ones:
-Wunusedby fanquake)CAmounta class by hodlinator)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.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/33042822923/job/98420040676LLM reason (✨ experimental): CI failed due to a clang build error treated as fatal: a C++23 lambda attribute (
[[noreturn]]) is used inmp/proxy-types.h, triggering-Wc++23-lambda-attributesunder-Werror.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
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 (
5cdb565ee5) is simply:Dropping the
interruptWaitmethod, replacing it with aCancelArgargument, and calling the argument with a lambda containing the code that used to be ininterruptWaitmethod.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.
Updated to match the latest changes in the upstream PR.
5cdb565ee5->1c02f2abea(compare)Notable changes:
CustomBuildExtraParam/CustomReadExtraParamoverloads forCancelArgnow live inipc/capnp/common-types.h, andCancelFn/CancelArgmoved tointerfaces/types.h.CancelArgnow returns aCancelGuardthat unregisters the callback when destroyed, so the event loop can't run it after the wrapped method goes out of scope.waitCancelmethod to the ipc_testsFooInterfaceto exercise both the client and server hooks.🐙 This pull request conflicts with the target branch and needs rebase.
This is a draft pull request, so Ralph reviewed only its concept. Code review runs on the first push after it is marked ready for review.
Earlier concerns neither republished nor resolved: 1 major finding · 7 minor findings · 7 suggestions. See the Run archive linked from the Review report for their assessments.
Design and approach
The goal is to stop unwanted mining waits without destroying templates needed for late solutions. This approach is worth pursuing: a Rust client already drops
waitNextpromises, and the proposed integration connects abandonment to the existing cooperative interruption paths, avoiding a separate interrupt RPC. This improves a usable explicit-interruption baseline; it is not forced termination of template assembly.The decisive question is whether overlapping waits on one
MiningorBlockTemplateobject must be independently cancelable. Tokens still feed shared per-object flags, so request-level cancellation does not establish mining-level isolation. Define that contract and the supported-client migration policy before replacinginterrupt()andinterruptWait(), which now return upgrade errors. Treat libmultiprocess cancellation support as a prerequisite. This is a concept assessment only, not a code-correctness review.Review coverage was incomplete.
Reviewed:
4e377f98a534· Review report · Previous reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.