-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add functional test for IPC interface #33201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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/33201. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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:
No other comprehension-impacting typos were found. drahtbot_id_4_m |
🚧 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. |
Concept ACK. 27bd678 is really nice and simpler than I would have expected. In case it's useful #30437 adds an interface_ipc_mining.py test, and #32297 adds an interface_ipc_cli.py test which are similar to this test and have similar test framework updates. Code from those PRs might be useful here or vice versa. |
b4cb8f6
to
b87de46
Compare
Concept ACK So far I achieved test coverage for the Mining interface with a combination of unit tests and by having RPC methods such as CentOS CI fails with |
e6bfad6
to
f5b8da2
Compare
74fc236
to
eb482c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On macOS 15.6 with capnp 1.2.0 installed via Homebrew and Python 3.10.14 installed via PyEnv I get:
pip3 install pycapnp
...
Successfully installed pycapnp-2.0.0
cmake -B build
cmake --build build
...
% build/test/functional/interface_ipc.py
2025-08-17T07:05:49.321522Z TestFramework (INFO): PRNG seed is: 6039316184654231320
2025-08-17T07:05:49.322566Z TestFramework (INFO): Initializing test directory /var/folders/8p/qqdl2fsj7rd6q096jtmsfydc0000gn/T/bitcoin_func_test_z3jtr5u1
2025-08-17T07:05:50.595292Z TestFramework (ERROR): Unexpected exception
Traceback (most recent call last):
File "/Users/sjors/dev/bitcoin/test/functional/test_framework/test_framework.py", line 200, in main
self.run_test()
File "/Users/sjors/dev/bitcoin/build/test/functional/interface_ipc.py", line 82, in run_test
self.run_echo_test()
File "/Users/sjors/dev/bitcoin/build/test/functional/interface_ipc.py", line 63, in run_echo_test
asyncio.run(capnp.run(async_routine()))
File "/Users/sjors/.pyenv/versions/3.10.14/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Users/sjors/.pyenv/versions/3.10.14/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "capnp/lib/capnp.pyx", line 1944, in run
File "capnp/lib/capnp.pyx", line 1945, in capnp.lib.capnp.run
File "/Users/sjors/dev/bitcoin/build/test/functional/interface_ipc.py", line 57, in async_routine
init, ctx = await self.make_capnp_init_ctx()
File "/Users/sjors/dev/bitcoin/build/test/functional/interface_ipc.py", line 45, in make_capnp_init_ctx
modules = self.capnp_modules()
File "/Users/sjors/dev/bitcoin/build/test/functional/interface_ipc.py", line 38, in capnp_modules
"proxy": capnp.load(str(mp_dir / "mp" / "proxy.capnp"), imports=imports),
File "capnp/lib/capnp.pyx", line 4385, in capnp.lib.capnp.load
File "capnp/lib/capnp.pyx", line 3574, in capnp.lib.capnp.SchemaParser.load
capnp.lib.capnp.KjException: mp/proxy.capnp:6: failed: Import failed: /capnp/c++.capnp
Maybe related: capnproto/pycapnp#377 (though pycapnp-1.3.0
doesn't work at all, since it doesn't have the run
method)
Suggested test doc improvement:
diff --git a/test/README.md b/test/README.md
index 37f2c07217..3b2979cdf6 100644
--- a/test/README.md
+++ b/test/README.md
@@ -34,6 +34,9 @@ The ZMQ functional test requires a python ZMQ library. To install it:
- on Unix, run `sudo apt-get install python3-zmq`
- on mac OS, run `pip3 install pyzmq`
+The IPC functional test requires a python IPC library. To install it:
+
+- `pip3 install pycapnp`
On Windows the `PYTHONUTF8` environment variable must be set to 1:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 088dc2c (after base PR lands)
# as it is being called before knowing whether capnp is available). | ||
self.capnp_modules = self.load_capnp_modules() | ||
|
||
async def make_capnp_init_ctx(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
088dc2c: eventually I'd like to move this and load_capnp_modules
into the test framework so that it's easier to expand e.g. mining_template_verification.py
to call both getblocktemplate proposal
and checkBlock()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this for a follow-up.
Addressed a number of comments, and rebased on top of #31802. I will however not have (much) time to push this further forward until the end of this month. @Sjors or @ryanofsky, or someone else, feel free to take this over and/or integrate into other PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 088dc2c (after base #31802)
This PR adds some functional tests for the IPC interface, setups the CI to use IPC and changes build documentation to match the changes in this PR.
Current state of the PR works on nix on macOS, builds & test run without trouble.
- build ✅
- tested ✅
- code review✅
small NIT if retouched, please see the remarks of DrahtBot's LLM linter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 088dc2c. Looks great! Left some comments that you should feel free to ignore. I am shocked and amazed about how much more friendly the python async API is compared to the c++ API, but I guess coroutines can bring similar benefits to c++. It is also nice how this tests covers different scenarios with waitNext()
test/README.md
Outdated
```sh | ||
git clone https://github.com/capnproto/pycapnp.git` | ||
cd pycapnp | ||
pip install . -C force-bundled-libcapnp=True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "ci: add functional test for IPC interface" (088dc2c)
As mentioned #33201 (comment), would be curious to know if force-system-libcapnp=True works for people, since it seems wasteful to download and build a dependency that we already know must be installed (or the test would be skipped).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to use system libcapnp in the description here because it's more likely to work. I've added a comment about it being optional now.
Expose ENABLE_IPC build option to function tests so new tests can test IPC-only features.
Set new `BitcoinTestFramework.binary_paths.bitcoin_bin` property with path to the `bitcoin` wrapper binary. This allows new tests for `bitcoin-mine` in bitcoin#30437 and `bitcoin-cli` in bitcoin#32297 to find the `bitcoin` binary and call `bitcoin -m` to start nodes with IPC support. This way the new tests can run whenever the ENABLE_IPC build option is enabled, instead of only running when the `BITCOIN_CMD` environment variable is set to `bitcoin -m`
With this change, tests can specify `self.extra_init = [{ipcbind: True}]` to start a node listening on an IPC socket, instead of needing to choose which node binary to invoke and what `self.extra_args=[["-ipcbind=..."]]` value to pass to it. The eliminates boilerplate code bitcoin#30437 (interface_ipc_mining.py), bitcoin#32297 (interface_ipc_cli.py), and bitcoin#33201 (interface_ipc.py) previously needed in their test setup.
@sipa let me know if you don't have to time to rebase, in which case I'll open a fresh PR next week. |
Rebased, and addressed some of the feedback above. Note that the last commit (which enables the tests in CI) may need work after moving to be on top of #31802, so that it matches the CI configurations which have IPC enabled. |
🚧 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. |
# Add the system cap'nproto path so include/capnp/c++.capnp can be found. | ||
capnp_dir = Path(capnp_bin).parent.parent / "include" | ||
else: | ||
# If there is system cap'nproto, the pycapnp module should have it's own "bundled" includes at this location |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in test/functional/interface_ipc.py comment: “have it’s own” -> “have its own” [possessive “its,” not contraction “it’s”]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason on the macOS native job ( I checked that this test did run for native_asan. I wrote a commit that enables it for additional jobs, which I'm testing in Sjors#101:
Update: 0c88edc should be safe to cherry-pick, we can add the previous_release job later. |
This adds support to the functional test framework to run the multiprocess
bitcoin-node
binary, and then tests it in a newinterface_ipc.py
functional test through thepycapnp
module.