Repository navigation
Add IPC extractor - #379
Conversation
|
@0xB10C This is just a minimal version of the ipc extractor, there's no testing yet, I'm opening just to gather feedback on current code and discuss a few points:
Thanks! |
0xB10C
left a comment
There was a problem hiding this comment.
Thank you, that's awesome!
I haven't run this yet, but I'm planning to play around a bit (soon ™️ )! A few thoughts:
- if we want to merge the
ipc-extractorin the short-term, I think having it support the mining interface (which is merged and released in v30 and v31) and one or two IPC calls from there would be good - then, we can maintain a patch for the chain interface and use it for futher testing
- and even have a patch for a WIP IPC tracing interface, if we decide to work on this
- Since I expect the captn' proto files to change from time to time (i think it's still far from final), it would be good to think about how to best support multiple Bitcoin Core releases / versions. Maybe we can supply them during build step. However, breaking API changes in captn' proto will probably cause a few headaches for us, so best to treat the ipc-extractor as experimental for a while
| # Copyright (c) The Bitcoin Core developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| @0xcc316e3f71a040fb; | ||
|
|
||
| using Cxx = import "/capnp/c++.capnp"; | ||
| $Cxx.namespace("mp"); | ||
|
|
||
| annotation include(file): Text; | ||
| annotation includeTypes(file): Text; | ||
| # Extra include paths to add to generated files. | ||
|
|
||
| annotation wrap(interface, struct): Text; | ||
| # Wrap capnp interface generating ProxyClient / ProxyServer C++ classes that | ||
| # forward calls to a C++ interface with same methods and parameters. Text | ||
| # string should be the name of the C++ interface. | ||
| # If applied to struct rather than an interface, this will generate a ProxyType | ||
| # struct with get methods for introspection and copying fields between C++ and | ||
| # capnp structs. | ||
|
|
||
| annotation count(param, struct, interface): Int32; |
There was a problem hiding this comment.
I'm not 100% sure if I'm correct here, but my understanding is that this is for the https://github.com/bitcoin-core/libmultiprocess library, which is for communication between C++ code bases. So we might not need it here. But I would have to check in detail.
There was a problem hiding this comment.
Not having this file in here would cause the other .capnp files to break at build time because all of them (i.e mining.capnp) import the proxy. I'm not sure if there's another way to fix this (since importing missing c++.capnp or .h files won't break) but I'd prefer to have these schemas as untouched as possible, it's a mirror to me after all.
| interface ChainNotifications $Proxy.wrap("interfaces::Chain::Notifications") { | ||
| destroy @0 (context :Proxy.Context) -> (); | ||
| transactionAddedToMempool @1 (context :Proxy.Context, tx :Data) -> (); | ||
| transactionRemovedFromMempool @2 (context :Proxy.Context, tx :Data, reason :Int32) -> (); | ||
| blockConnected @3 (context :Proxy.Context, role: ChainstateRole, block :BlockInfo) -> (); | ||
| blockDisconnected @4 (context :Proxy.Context, block :BlockInfo) -> (); | ||
| updatedBlockTip @5 (context :Proxy.Context) -> (); | ||
| chainStateFlushed @6 (context :Proxy.Context, role: ChainstateRole, locator :Data) -> (); | ||
| } |
There was a problem hiding this comment.
being able to subscribe to some of these would be very cool!
There was a problem hiding this comment.
Maybe in the patch version? Just removed it because it's not currently available at v30
I think mentioning it's experiment in the READMEs is fine for now. No need to rename it to
I think a good way forward would be:
|
Yeah sure, for me should be replacing current
Agree, it would be amazing to test the tracing interface.
Great
I'm not familiar with that repository but you mean to add changes like node setup? i.e passing
That's awesome, thanks |
No worries! I can take care of that! |
5973b00 to
cb5ee24
Compare
|
Update: I was working on adding integration tests and noticed that there's no trivial way to mock/setup a |
f7510a1 to
900fbab
Compare
ipc-extractor for testing the Chain interface3b27bd0 to
8bd94fb
Compare
Yeah, I think that's correct. I also discovered something similar in making some small changes to corepec: rust-bitcoin/corepc#429 |
I think we can do that! Should not be a problem. I can have a look. |
|
I came across this: https://github.com/2140-dev/bitcoin-capnp-types/ which might be interesting, but I think we don't strictly need it as a depdency for now. |
I checked and it's seems the binary is compiled in nixpkgs master: However, the So we should add export BITCOIN_NODE_EXE=${pkgs.bitcoind}/libexec/bitcoin-nodeto Line 44 in de427d5 Does this help? |
By coincidence, lately I've been thinking about doing something very similar: a repo which exports the the generated capnproto bindings (exactly the same as what you shared) with the plus of maintaining the bindings for IPC-related PRs (i.e bitcoin/bitcoin#32898, bitcoin/bitcoin#29409 and maybe others). Thanks for sharing! |
Wow I missed this, thanks for noticing it!
Yeah it worked! Thanks to this I noticed I wasn't vendoring actual |
| - name: Install integration test dependecies | ||
| run: sudo apt-get install -y nats-server | ||
| # use separate steps for iterations here to easily see on GHA the time it took | ||
| - name: Iteration 0 |
There was a problem hiding this comment.
I think you have to give it BITCOIN_NODE_EXE here too
There was a problem hiding this comment.
Yeah just pushed it
ab409bf to
759a9c5
Compare
- Add protobuf event schema BlockTip - Extend main peer_observer_event with IPC ones - Expose generated IPC protobuf bindings - Extend runtime error handling for NATS publish and system-time errors
|
Added instructions on how to run a Working on rebasing and fixing the CI failures. |
|
Rebased with master and fixed archiver tool errors in d71b6ba |
b9c1410 to
047b300
Compare
my nodes are all v31.0 by now so I won't be albe to test and deploy this until rust-bitcoin/corepc#586 is merged 😄 I'll put that PR on my list to review. I don't think it's far from being merged. Actually, merging this without v31.0 support will break my NixOS build, so I'll hold off for now. One thing that we could thing about in a follow-up is "is it possible to support multiple versions of Bitcoin Core"? |
Mirror capnp files at [Core v31.0](https://github.com/bitcoin/bitcoin/tree/v31.0), these files will be located at `extractors/ipc/capnp`
The `--ipc-socket-path` argument was previously unused. This change implements the full IPC connection workflow by instantiating the Mining interface and performing a `getTip` query to have a simple extraction process. Key changes: - Add `build.rs` to generate Rust bindings for the multiprocess schemas in `capnp/` - Integrate bindings using `capnp::generated_code!` macro - Implemented error handling for Capnp-specific RPC failures - Updated `main.rs` to a single-threaded runtime since `capnp_rpc::RpcSystem` is `!Send` - Create `ipc.rs` which encapsulates IPC communication logic
nix-shell CI tests will be skipped because of a `bitcoin-node` version mismatch: v31.0 (resolved in nix-shell) vs v30.2 (latest version in `corepc`). Once rust-bitcoin/corepc#586 lands the IN_NIX_SHELL guard should be dropped.
|
@xyzconstant told me out-of-band that he reverted back to v31.0 types for now. I just had another look, and this seems fine at 8028a5d Thanks @xyzconstant - and sorry for the back and forth! I could have been clearer in #379 (review) that an approval and listing followups means "no-more-touching-unless-really-needed" and "I'm-going-to-merge-this-as-is"! |
Based on peer-observer#379 (review). This commit mirrors RPC metrics setup for exposing ipc_fetch_duration and ipc_fetch_errors.
Based on #379 (review). This commit mirrors RPC metrics setup for exposing ipc_fetch_duration and ipc_fetch_errors.

Description
This PR introduces an experimental IPC extractor, designed to interface with a Core v31.0
bitcoin-nodeprocess over a Unix Socket (generated by passing-ipcbind=unix) and Cap 'n Proto.Context
Bitcoin Core has an on-going Process Separation project, which aims to split
bitcoindinto smaller and manageable processes that communicate together through Unix Sockets. Within this architecture,bitcoin-node(introduced in Core 30.0) exposes multiple interfaces that external processes can consume by leveraging Cap 'n Proto RPC system.As
bitcoin-nodekeeps expanding its interfaces (e.g bitcoin/bitcoin#29409 adds a wrapper for the Chain interface), this extractor will facilitate reviewing and testing on IPC-related PRs in Core.Key changes
ipc-extractor.bitcoin-node(for Ubuntu tests)..capnpfiles from Bitcoin Core v31.0.capnpc,capnp-rpcandcapnp).README.mdwith documentation for the new extractor.How to use
bitcoin-nodeprocess:./build/bin/bitcoin-node -regtest -ipcbind=unix OR ./build/bin/bitcoin -m node -regtest -ipcbind=unixnats-servercargo run --bin logger -- --ipccargo run --bin ipc-extractor -- --ipc-socket-path="path/to/node.sock"BlockTip(height=404, hash=...)events being published to NATS.Closes #370