Skip to content

add: getnetworkinfo RPC support - #319

Merged
0xB10C merged 1 commit into
peer-observer:masterfrom
GuiSchet:rpc-extractor-getnetworkinfo
Jan 16, 2026
Merged

0xB10C merged 1 commit into
peer-observer:masterfrom
GuiSchet:rpc-extractor-getnetworkinfo

Conversation

@GuiSchet

@GuiSchet GuiSchet commented Dec 24, 2025 •

Copy link
Copy Markdown
Contributor

Implementation of getnetworkinfo RPC Extractor

This PR adds support for Bitcoin Core's getnetworkinfo RPC call to the rpc-extractor, following patterns established in previous PRs.

Main Changes

Protobuf Schema (protobuf/rpc_extractor.proto)

  • Added NetworkInfo message with all getnetworkinfo fields
  • Added NetworkInfoNetwork for per-network information (ipv4, ipv6, onion, i2p, cjdns)
  • Added NetworkInfoLocalAddress for local addresses
  • Integrated into the rpc message's oneof rpc_event

Type Conversions (shared/src/protobuf/rpc_extractor.rs)

  • Implemented From<> conversions from corepc_node::vtype::GetNetworkInfo
  • Added fmt::Display implementations for logging
  • Correct conversion of warnings field (Vec → String)

RPC Extractor (extractors/rpc/src/lib.rs)

  • Added new CLI flag --disable-getnetworkinfo
  • Implemented getnetworkinfo() function that queries and publishes events
  • Integrated into main loop and disable_all check
  • Added status logging

Prometheus Metrics (tools/metrics/src/metrics.rs and lib.rs)

  • Individual metrics for main fields (version, connections, fees, etc.)
  • Dimensional metric rpc_networkinfo_networks using IntGaugeVec with labels [network, property] (following lesson from PR rpc-extractor: add getmemoryinfo and getaddrmaninfo #309)
  • Complete handler in handle_rpc_event()

Integration Tests

  • Added test_integration_rpc_getnetworkinfo test
  • All existing tests updated with new disable_getnetworkinfo parameter

Documentation

  • README updated with new CLI flag

Privacy Analysis: getnetworkinfo RPC Extractor

Data Exposed

Network Information (Low Sensitivity)

  • version, subversion, protocol_version: Already exposed in P2P handshakes
  • connections, connections_in, connections_out: Aggregated counts, do not identify specific peers
  • network_active, networks[]: Connectivity state, not sensitive
  • relay_fee, incremental_fee: Public node configuration

Information with Privacy Considerations

  • local_addresses[]: IP/onion addresses where the node is listening
    • Already semi-public (announced to peers via addr/addrv2 messages)
    • Note: Centralized in Prometheus metrics - ensure metrics endpoint is not publicly exposed
  • warnings: May reveal problematic node states

Security Measures Implemented

  1. RPC Authentication Required: Extractor requires RPC credentials (--rpc-user/--rpc-cookie-file)
  2. No Critical Data Exposed: Does not expose private keys, wallet addresses, or user transaction data
  3. Data Equivalent to P2P: Information is similar to what any P2P peer can obtain

@0xB10C
0xB10C force-pushed the rpc-extractor-getnetworkinfo branch from 8a0bb84 to bb8e789 Compare January 5, 2026 15:53
@0xB10C

0xB10C commented Jan 5, 2026

Copy link
Copy Markdown
Collaborator

Rebased to resolve conflicts against master. Haven't looked at the code closely yet.

@GuiSchet

GuiSchet commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

ey @0xB10C, I can help resolve the merge conflicts if you'd like. Just let me know and I'll take care of it.

@0xB10C

0xB10C commented Jan 6, 2026

Copy link
Copy Markdown
Collaborator

Feel free to rebase now. I think current master isn't going to change much anymore for the next days.

Comment thread shared/src/protobuf/rpc_extractor.rs Outdated
Comment on lines +9 to +12
use corepc_node::vtype::{
GetNetworkInfo as RPCGetNetworkInfo, GetNetworkInfoAddress as RPCGetNetworkInfoAddress,
GetNetworkInfoNetwork as RPCGetNetworkInfoNetwork,
};

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.

Should we be using corepc_client here?

e.g.

use corepc_client::types::v28::{
    GetNetworkInfo as RPCGetNetworkInfo,
    GetNetworkInfoAddress as RPCGetNetworkInfoAddress, 
    GetNetworkInfoNetwork as RPCGetNetworkInfoNetwork,
};

Note that corepc-node is actually "Utility to run a regtest bitcoind process, useful in integration testing environments", see: https://github.com/rust-bitcoin/corepc/blob/master/node/Cargo.toml

I think that v28 is the correct version but please verify this @GuiSchet!

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.

right, it should be e.g. corepc_types::model::GetNetworkInfo (and not the version specific corepc_client::types::v28::GetNetworkInfo)

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.

Even better!

@0xB10C
0xB10C force-pushed the rpc-extractor-getnetworkinfo branch 2 times, most recently from 2cd5da7 to 005c44b Compare January 9, 2026 16:52
@0xB10C

0xB10C commented Jan 9, 2026

Copy link
Copy Markdown
Collaborator

I went ahead and rebased this to start reviewing it!

Comment thread protobuf/rpc_extractor.proto Outdated
required double relay_fee = 13; // Minimum relay fee for transactions in BTC/kB
required double incremental_fee = 14; // Minimum fee rate increment for mempool limiting in BTC/kB
repeated NetworkInfoLocalAddress local_addresses = 15; // List of local addresses
required string warnings = 16; // Any network and blockchain warnings

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.

warnings is a list of strings

"warnings" : [                                     (json array) any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)
    "str",                                           (string) warning
    ...
  ]

Comment thread shared/src/protobuf/rpc_extractor.rs Outdated
relay_fee: info.relay_fee,
incremental_fee: info.incremental_fee,
local_addresses: info.local_addresses.into_iter().map(|a| a.into()).collect(),
warnings: info.warnings.join("; "),

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.

probably best to leave it as a list of warnings!

@GuiSchet

Copy link
Copy Markdown
Contributor Author

Fixed both review observations:

1. Import correction

  • Added corepc-types dependency to shared/Cargo.toml
  • Changed imports from corepc_node::vtype to corepc_node::mtype (model types)
  • Added From trait implementations for both mtype and vtype to support version-agnostic types

2. Warnings field as array

  • Changed warnings field in protobuf/rpc_extractor.proto from required string to repeated string
  • Removed .join("; ") in the conversion code to preserve the array structure
  • Updated Display trait to format warnings array correctly

@0xB10C
0xB10C force-pushed the rpc-extractor-getnetworkinfo branch from 9af6317 to f4aab7c Compare January 16, 2026 13:49
@0xB10C

0xB10C commented Jan 16, 2026

Copy link
Copy Markdown
Collaborator

I fixed up some minor details. This looks good now. Thank you again @GuiSchet!

@0xB10C
0xB10C merged commit 01aa6fd into peer-observer:master Jan 16, 2026
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.

3 participants