Skip to content

Add basic RPC extractor with getpeerinfo support - #191

Merged
0xB10C merged 3 commits into
masterfrom
2025-07-rpc-extractor
Aug 1, 2025
Merged

0xB10C merged 3 commits into
masterfrom
2025-07-rpc-extractor

Conversation

@0xB10C

@0xB10C 0xB10C commented Jul 30, 2025 •

Copy link
Copy Markdown
Collaborator

This adds an RPC extractor that connects to a Bitcoin Core node and queries RPCs for data in an interval (currently 10s). The data is then send into NATS and can be consumed by tools. As a start, the getpeerinfo RPC is implemented.

It uses rust-bitcoin/corepc and their non-production, sync RPC client. A custom RPC client can be implemented in the future, if needed. It requires rust-bitcoin/corepc#310 to be merged and released. Until then, a custom branch is being used.

Basic logger, websocket, and metrics tool support has been implemented. The websocket web pages can be updated to use data the and the metric tool can be built out to allow for more metrics.

Required before merge:

To be done as followups (best tracked in their own issues)

@0xB10C

0xB10C commented Jul 30, 2025 •

Copy link
Copy Markdown
Collaborator Author

CI failure:

🔍 Checking tool: logger
Warning: Missing line in README for logger:       --rpc                          If passed, show RPC events
Error: Some help lines for 'logger' are missing in its README
📢 Have you forgotten to update the documentation for logger?
🔍 Checking tool: websocket
🔍 Checking tool: metrics
🔍 Checking tool: connectivity-check
❌ Documentation mismatch detected.

(that should be extended for extractors too!)

Comment thread extractors/rpc/src/main.rs Resolved
Comment thread protobuf/proto-types/rpc.proto Resolved
Comment thread shared/ip-lists/README.md Resolved
@0xB10C
0xB10C force-pushed the 2025-07-rpc-extractor branch from eb6aab6 to b21e152 Compare July 31, 2025 09:13
This is being used in the next commit by the metrics exporter and
allows to confirm that the RPC exporter is working. However, it
isn't nesscessary for the functionallity of the RPC exporter and
not strictly needed in this PR.

We don't maintain a text file list of the IP addresses, as LinkingLion
has 3x IPv4 /24 and 1x IPv6 /64 networks. Putting these into a text
file, especially the /64, would be wasteful. Rather, use starts_with
to reduce the functions footprint.
@0xB10C
0xB10C force-pushed the 2025-07-rpc-extractor branch 2 times, most recently from 8075bcc to 7935e44 Compare July 31, 2025 10:42
interval.tick().await;

if let Err(e) = getpeerinfo(&rpc_client, &nats_client).await {
log::error!("Could not fetch and publish 'getpeerinfo': {}", e)

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.

This looks something like

ERROR [rpc] Could not fetch and publish 'getpeerinfo': RPC error: JSON-RPC error: transport error: http (status: 401, body: )

Comment thread protobuf/proto-types/rpc.proto Resolved
Comment thread shared/Cargo.toml
lazy_static = "1.5.0"
# for the rpc exporter
# TODO: when #310 is merged and 0.9.0 is release, switch to that.
corepc-client = { git = "https://github.com/0xb10c/corepc.git", branch = "2025-07-peer-observer-rpc-extractor", features = ["client-sync"]}

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.

PR 310 is merged, but we still need to wait for version 0.9.0 to be able to use it without patches

@0xB10C
0xB10C force-pushed the 2025-07-rpc-extractor branch from 7935e44 to ea6952f Compare July 31, 2025 10:50
@0xB10C

0xB10C commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator Author

Would be cool to support bitcoin/bitcoin#31672 too - but that would be a temporary field and require a change in corepc, and running a custom Bitcoin Core node. Not something to be done here.

@0xB10C
0xB10C force-pushed the 2025-07-rpc-extractor branch from ea6952f to 19b70d6 Compare July 31, 2025 12:14
@0xB10C
0xB10C marked this pull request as ready for review July 31, 2025 12:15
@0xB10C

0xB10C commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator Author

I'm considering this PR ready feature-wise and will start testing it on some of my nodes now.

This adds an RPC extractor that connects to a Bitcoin Core node and
queries RPCs for data in an interval (currently 10s). The data is then
send into NATS and can be consumed by tools. As a start, getpeerinfo
is implemented.

It uses rust-bitcoin/corepc and their non-production, sync RPC client.
A custom RPC client can be implemented in the future, if needed. It
requires rust-bitcoin/corepc#310 to be merged
and released. Until then, a custom branch is being used.

Basic logger, websocket, and metrics tool support has been implemented.
The websocket web pages can be updated to use data the and the metric
tool can be built out to allow for more metrics.
@0xB10C
0xB10C force-pushed the 2025-07-rpc-extractor branch from 19b70d6 to 0d1b10c Compare July 31, 2025 16:24
@0xB10C

0xB10C commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator Author

renamed the binary from rpc to rpc-extractor to match the ebpf-extractor

@0xB10C

0xB10C commented Aug 1, 2025

Copy link
Copy Markdown
Collaborator Author

I've tested the logger, metrics and websocket tool with this. I think this is ready for merge. I'll open issues for the open tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants