Skip to content

Add IPC extractor - #379

Merged
0xB10C merged 12 commits into
peer-observer:masterfrom
nullfail:ipc-extractor
May 20, 2026
Merged

0xB10C merged 12 commits into
peer-observer:masterfrom
nullfail:ipc-extractor

Conversation

@nullfail

@nullfail nullfail commented Mar 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR introduces an experimental IPC extractor, designed to interface with a Core v31.0 bitcoin-node process 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 bitcoind into 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-node keeps 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

  • Add new binary crate ipc-extractor.
  • Add new Github Action for verifying and installing bitcoin-node (for Ubuntu tests).
  • Vendor .capnp files from Bitcoin Core v31.0.
  • Add new dependencies to integrate Cap 'n Proto (capnpc, capnp-rpc and capnp).
  • Add Protocol Buffer schema and NATS subject for IPC events.
  • Update tools to enable inspecting IPC events.
  • Update README.md with documentation for the new extractor.

How to use

  1. Download and compile the code at https://github.com/bitcoin/bitcoin/tree/v31.0
  2. Launch a bitcoin-node process: ./build/bin/bitcoin-node -regtest -ipcbind=unix OR ./build/bin/bitcoin -m node -regtest -ipcbind=unix
  3. Start the NATS server: nats-server
  4. Run the logger tool: cargo run --bin logger -- --ipc
  5. Run the extractor: cargo run --bin ipc-extractor -- --ipc-socket-path="path/to/node.sock"
  6. Observe BlockTip(height=404, hash=...) events being published to NATS.
image

Closes #370

@nullfail

Copy link
Copy Markdown
Collaborator Author

@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:

  1. I'm thinking about adding more signaling about this extractor being "experimental", by renaming the crate and further references to experimental-ipc-extractor or something similar, what are your thoughts on it?
  2. What other IPC calls/events would you love to see on this extractor to consider it ready?

Thanks!

@0xB10C 0xB10C left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-extractor in 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

Comment thread extractors/ipc/src/lib.rs Resolved
Comment on lines +1 to +22
# 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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread extractors/ipc/capnp/chain.capnp Outdated
Comment on lines +72 to +80
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) -> ();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

being able to subscribe to some of these would be very cool!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in the patch version? Just removed it because it's not currently available at v30

Comment thread extractors/ipc/src/lib.rs Resolved
Comment thread extractors/ipc/Cargo.toml Resolved
@0xB10C

0xB10C commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator
  1. I'm thinking about adding more signaling about this extractor being "experimental", by renaming the crate and further references to experimental-ipc-extractor or something similar, what are your thoughts on it?

I think mentioning it's experiment in the READMEs is fine for now. No need to rename it to experimental-ipc-extractor.

  1. What other IPC calls/events would you love to see on this extractor to consider it ready?

I think a good way forward would be:

  • have a very basic PoC for an IPC extractor that works against the released Bitcoin Core v30 (or upcoming v31) IPC mining interface. Maybe fetch one or two things periodically or have it subscribe to a notification from the mining interface. This is something we can merge, test in CI, and run on the demo and production peer-observer nodes. This also means implementing IPC support in the infrastructure https://github.com/peer-observer/infra-library at some point.
  • then, maintain a patchset (possibly in a WIP PR) that implements some functionallity for the chain interface as proposed in ipc: Expose Chain interface to IPC clients bitcoin/bitcoin#29409 and use it to test that manually. We can't really test this in CI yet, I think, as we don't have a good way of running custom Bitcoin Core binaries in CI (yet). Also, the demo and production peer-observer nodes won't all be running ipc: Expose Chain interface to IPC clients bitcoin/bitcoin#29409 until it's merged
  • use the Chain interface one to play around an implement a few cool demos or PoCs, and give feedback on the Bitcoin Core PR
  • possibly in paralell, experiment with a custom IPC Tracing interface in Bitcoin Core, see how much performance we can get out of it, if we can improve the performance, and evaluate if it would be an option

@nullfail

nullfail commented Mar 13, 2026 •

Copy link
Copy Markdown
Collaborator Author
  • if we want to merge the ipc-extractor in 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

Yeah sure, for me should be replacing current Chain::getHeight with mining's Mining::getTip and obtain the block height from there. Regarding the .capnp schemas these should mirror v30's ones instead of bitcoin/bitcoin#29409

  • 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

Agree, it would be amazing to test the tracing interface.

I think mentioning it's experiment in the READMEs is fine for now. No need to rename it to experimental-ipc-extractor.

Great

This also means implementing IPC support in the infrastructure https://github.com/peer-observer/infra-library at some point.

I'm not familiar with that repository but you mean to add changes like node setup? i.e passing ipcbind=unix or is it more about build stuff for the extractor? anyways I'll gave it a look later, but I might say I'm not familiar with Nix neither, I tested the extractor locally without a container.

  • then, maintain a patchset (possibly in a WIP PR) that implements some functionallity for the chain interface as proposed in multiprocess: Add capnp wrapper for Chain interface bitcoin/bitcoin#29409 and use it to test that manually. We can't really test this in CI yet, I think, as we don't have a good way of running custom Bitcoin Core binaries in CI (yet). Also, the demo and production peer-observer nodes won't all be running multiprocess: Add capnp wrapper for Chain interface bitcoin/bitcoin#29409 until it's merged
  • use the Chain interface one to play around an implement a few cool demos or PoCs, and give feedback on the Bitcoin Core PR
  • possibly in paralell, experiment with a custom IPC Tracing interface in Bitcoin Core, see how much performance we can get out of it, if we can improve the performance, and evaluate if it would be an option

That's awesome, thanks

@0xB10C

0xB10C commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator

I'm not familiar with that repository but you mean to add changes like node setup? i.e passing ipcbind=unix or is it more about build stuff for the extractor? anyways I'll gave it a look later, but I might say I'm not familiar with Nix neither, I tested the extractor locally without a container.

No worries! I can take care of that!

@nullfail
nullfail force-pushed the ipc-extractor branch 4 times, most recently from 5973b00 to cb5ee24 Compare March 14, 2026 03:46
@nullfail

Copy link
Copy Markdown
Collaborator Author

Update:

I was working on adding integration tests and noticed that there's no trivial way to mock/setup a bitcoin-node process with corepc-node, haven't gone deep but at first glance it looks like https://github.com/0xb10c/corepc needs some update for this.

@nullfail
nullfail marked this pull request as ready for review March 15, 2026 21:08
@nullfail
nullfail force-pushed the ipc-extractor branch 2 times, most recently from f7510a1 to 900fbab Compare March 16, 2026 15:35
@nullfail nullfail changed the title [WIP] Add ipc-extractor for testing the Chain interface Add IPC extractor Mar 16, 2026
@nullfail

nullfail commented Mar 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Ok I think I found a workaround for spinning up a bitcoin-node instance with corepc-node: we just need to disable the wallet via conf.wallet = None;.

But the new challenge is to get to build bitcoin-node binary in bitcoind's nix repository.
image

@nullfail
nullfail force-pushed the ipc-extractor branch 3 times, most recently from 3b27bd0 to 8bd94fb Compare March 17, 2026 18:23
@deadmanoz

deadmanoz commented Mar 19, 2026 •

Copy link
Copy Markdown
Collaborator

Ok I think I found a workaround for spinning up a bitcoin-node instance with corepc-node: we just need to disable the wallet via conf.wallet = None;.

Yeah, I think that's correct. I also discovered something similar in making some small changes to corepec: rust-bitcoin/corepc#429

@0xB10C

0xB10C commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

But the new challenge is to get to build bitcoin-node binary in bitcoind's nix repository.

I think we can do that! Should not be a problem. I can have a look.

@0xB10C

0xB10C commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

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.

@0xB10C

0xB10C commented Mar 23, 2026 •

Copy link
Copy Markdown
Collaborator

But the new challenge is to get to build bitcoin-node binary in bitcoind's nix repository.

I think we can do that! Should not be a problem. I can have a look.

I checked and it's seems the binary is compiled in nixpkgs master:

$ nix build .#bitcoind --print-build-logs --rebuild
bitcoind> Configure summary
bitcoind> =================
bitcoind> Executables:
bitcoind>   bitcoin ............................. ON
bitcoind>   bitcoind ............................ ON
bitcoind>   bitcoin-node (multiprocess) ......... ON
bitcoind>   bitcoin-qt (GUI) .................... OFF
bitcoind>   bitcoin-gui (GUI, multiprocess) ..... OFF
bitcoind>   bitcoin-cli ......................... ON
bitcoind>   bitcoin-tx .......................... ON
bitcoind>   bitcoin-util ........................ ON
bitcoind>   bitcoin-wallet ...................... ON
bitcoind>   bitcoin-chainstate (experimental) ... OFF
bitcoind>   libbitcoinkernel (experimental) ..... OFF
bitcoind> Optional features:
bitcoind>   wallet support ...................... ON
bitcoind>   external signer ..................... ON
bitcoind>   ZeroMQ .............................. TRUE
bitcoind>   IPC ................................. ON
bitcoind>   USDT tracing ........................ TRUE
bitcoind>   QR code (GUI) ....................... OFF
bitcoind>   DBus (GUI) .......................... OFF
bitcoind> Tests:
bitcoind>   test_bitcoin ........................ ON
bitcoind>   test_bitcoin-qt ..................... OFF
bitcoind>   bench_bitcoin ....................... FALSE
bitcoind>   fuzz binary ......................... OFF
...

However, the bitcoin-node binary isn't listed in the nixpkgs docs, as it's not in bin. It's in libexec (see https://bitcoincore.org/en/releases/30.0/#install-changes)

So we should add

export BITCOIN_NODE_EXE=${pkgs.bitcoind}/libexec/bitcoin-node

to

export BITCOIND_EXE=${pkgs.bitcoind}/bin/bitcoind

Does this help?

@nullfail

Copy link
Copy Markdown
Collaborator Author

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.

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!

@nullfail

Copy link
Copy Markdown
Collaborator Author

However, the bitcoin-node binary isn't listed in the nixpkgs docs, as it's not in bin. It's in libexec (see https://bitcoincore.org/en/releases/30.0/#install-changes)

Wow I missed this, thanks for noticing it!

So we should add

export BITCOIN_NODE_EXE=${pkgs.bitcoind}/libexec/bitcoin-node

to

export BITCOIND_EXE=${pkgs.bitcoind}/bin/bitcoind

Does this help?

Yeah it worked! Thanks to this I noticed I wasn't vendoring actual capnp schemas at v30.2 so I had to revert those and now the whole is working properly for v30.2. Thanks!

Comment thread .github/workflows/ci.yml
- 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to give it BITCOIN_NODE_EXE here too

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah just pushed it

@nullfail
nullfail force-pushed the ipc-extractor branch 2 times, most recently from ab409bf to 759a9c5 Compare March 23, 2026 22:49
- 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
@nullfail

nullfail commented May 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Added instructions on how to run a bitcoin-node instance to extractors/ipc/README.md.

Working on rebasing and fixing the CI failures.

@nullfail

Copy link
Copy Markdown
Collaborator Author

Rebased with master and fixed archiver tool errors in d71b6ba

@nullfail
nullfail force-pushed the ipc-extractor branch 2 times, most recently from b9c1410 to 047b300 Compare May 19, 2026 19:01
@nullfail

nullfail commented May 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Update:

nix-shell will resolve bitcoind to v31.0 which breaks our v30.2 capnp schemas, added an IN_NIX_SHELL guard to skip nix-shell IPC test until we bump support for v31.0.

b9c1410 -> 047b300 (compare)

@0xB10C

0xB10C commented May 19, 2026

Copy link
Copy Markdown
Collaborator

downgraded capnp schemas to v30.2

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"?

nullfail added 10 commits May 20, 2026 01:17
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.
@0xB10C

0xB10C commented May 20, 2026 •

Copy link
Copy Markdown
Collaborator

@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"!

@0xB10C
0xB10C merged commit dc0af92 into peer-observer:master May 20, 2026
12 checks passed
0xB10C added a commit that referenced this pull request May 21, 2026
Both the p2p-extractor and the ipc-extractor have a dependency on
tokio-util. We can combine these in `shared` and re-export from there.

This is a followup to #379 and tracked in #436.
nullfail added a commit to nullfail/peer-observer that referenced this pull request May 28, 2026
Based on peer-observer#379 (review).
This commit mirrors RPC metrics setup for exposing ipc_fetch_duration and ipc_fetch_errors.
0xB10C pushed a commit that referenced this pull request Jun 3, 2026
Based on #379 (review).
This commit mirrors RPC metrics setup for exposing ipc_fetch_duration and ipc_fetch_errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement an experimental ipc-extractor against the Bitcoin Core chain IPC interface (proposed in #29409)

5 participants