#29418 rpc: provide per message stats for global traffic via new RPC 'getnetmsgstats'
https://github.com/bitcoin/bitcoin/pull/29418 · · +540/-14 in 9 files, 3 commits · labels: RPC/REST/ZMQ, Needs rebase
Goal
- Track cumulative network traffic by message and connection type for node operators and monitoring tools
- Keep long-term traffic statistics from being lost whenever peers disconnect
Adds a new RPC command `getnetmsgstats` that exposes cumulative network traffic statistics (message count and byte totals). The stats are collected globally in `CConnman` broken down by direction, network, connection type, and message type, preventing data loss when peers disconnect.
Problem: Previously, message-level traffic counters were kept only per peer in `CNode` and were lost whenever a peer disconnected. Node operators and monitoring tools could not track long-term network usage by message or connection type without constantly polling tracepoints or `getpeerinfo`.
Category: P2P (#42 of 65)
P3 · new feature
- P3 because tracking traffic across networks improves P2P observability for operators
- Helps operators analyze monthly bandwidth distribution without altering relay or consensus behavior
P3 because tracking message traffic across networks and connection types improves P2P observability for operators without altering relay or consensus behavior. 0xB10C and waketraindev noted its value for understanding monthly bandwidth distribution.
Membership: Modifies CConnman and CNode to track traffic counts and bytes across networks and connection types.
Factors: security/stability 0, bug 0, performance 0, user value 2, leverage 0
Category: RPC / REST / ZMQ (#14 of 52)
P3 · new feature
- P3 because it provides persistent network traffic breakdowns that external dashboards can consume
- Adds a dedicated RPC endpoint without altering existing RPC compatibility or core invariants
P3 because it fulfills feature request #26337 by providing persistent network traffic breakdowns that external dashboards can consume. It does not alter existing RPC compatibility or core invariants.
Membership: Implements the new `getnetmsgstats` RPC in `src/rpc/net.cpp`.
Factors: security/stability 0, bug 0, performance 0, user value 2, leverage 0
Reviewability: Stale: Needs rebase
- Needs rebase due to merge conflicts with master
- Author has been inactive since June 2026
The PR has merge conflicts with master and open PRs, and the author has not updated it since June 2026.
Author status: silent since 2026-06-12
Resolved concerns:
- stickies-v opposed an earlier commit allowing client-side aggregation filters in the RPC; vasild removed the aggregation feature in June 2026.
- Reviewers raised minor formatting and RPC argument naming style issues, which the author resolved.
Agreement: Positive
- Broad support for exposing global traffic metrics to node operators
- Verified by testing with node monitoring dashboards (waketraindev)
- Concept approval and implementation review (danielabrozzoni, epiccurious)
- Resolved objection: dropped server-side aggregation options in response to feedback (stickies-v)
Positive; multiple concept ACKs and verified usage in node monitoring, with the server-side aggregation objection resolved.
Reviewers broadly supported providing global traffic metrics for node operators. An approach concern from stickies-v regarding server-side aggregation was addressed by dropping the feature.
- epiccurious gave Concept ACK.
- waketraindev ACKed and confirmed testing with node monitoring dashboards.
- danielabrozzoni gave Concept ACK and reviewed the implementation.
- stickies-v opposed RPC aggregation options; vasild removed them in response.
Review verdicts (DrahtBot): 0 (+1)
- Stale ACK: waketraindev
- Concept ACK: epiccurious, danielabrozzoni, stickies-v
Files
157 lines under test/bench/ci.
- src/net.cpp +177/-3
- test/functional/rpc_net.py +143/-0
- src/rpc/net.cpp +119/-0
- src/net.h +85/-2
- src/node/connection_types.h +8/-3
- src/test/util/net.cpp +3/-3
- src/test/util/net.h +2/-2
- src/test/fuzz/net.cpp +2/-1
- src/test/fuzz/rpc.cpp +1/-0
Card
This PR adds the `getnetmsgstats` RPC to report global byte and message counts categorized by direction, network, connection type, and message type. It addresses issue #26337 for node operators whose traffic statistics were previously wiped whenever peers disconnected. Several contributors supported the concept, and earlier concerns regarding server-side aggregation parameters were resolved by removing that feature. The PR is currently in conflict with master and waiting on the author for a rebase.