Review report

core: PR #29418

2 minor findings · 4 suggestions

Findings

Link

[minor] · Sent counts include messages that were not fully written

A failed send can leave getnettotals.detailed hiding a counted message or reporting it as sent, contrary to the help text; each failed connection contributes at most one such message, and production frequency is unknown.

Location: src/net.cpp:1640 (head).

Details and suggested fix

SocketSendData() increments the sent count when SetMessageToSend() accepts a message, before checking node.m_sock or calling Send(). If the socket is closed, or a non-retryable send error disconnects the node, the message remains counted with zero bytes. A short write followed by a disconnect leaves it counted with only some bytes. Received messages are counted only after the transport reports a complete message. The RPC skips entries when either bytes or count is zero, so a bucket containing only an unwritten message disappears despite the help saying unlisted entries are zero. In buckets with other bytes, the unwritten message is included in the count. The transport holds one message at a time, and PushMessage() stops optimistic sends while bytes are pending, so each failed connection adds at most one such message. Production frequency was not measured. Skip an entry only when both counters are zero, and clarify in the help that sent messages are counted when handed to the transport.


Link

[minor] · Fragmented-ping test can race with the peer's automatic pong

The test may intermittently fail if the peer answers the RPC-triggered ping while the test builds and sends its own fragmented ping; the outcome depends on thread scheduling.

Location: test/functional/rpc_net.py:343 (head).

Details and suggested fix

The test waits for node0 to write its RPC-triggered ping, but not for node2 to answer it. P2PInterface.on_ping() schedules the pong from the network thread through send_without_ping(), which builds and schedules it under _send_lock. The test builds ping_msg and sends its two fragments from the main thread without that lock. If the pong is scheduled between the fragments, node0 parses a corrupted v1 header and may never reach the expected ping count. With --v2transport, build_message() advances the BIP324 send cipher in v2_enc_packet(). A pong built after ping_msg but written before it reaches node0 out of order, fails authentication, and disconnects the peer. Call node2.sync_with_ping() before building ping_msg to drain the exchange; the peer processes node0's ping before receiving the pong for the sync ping. No failure rate is established.


Optional improvements

Link

[suggestion] · Type-check bypass leaves detailed unchecked and undocumented in OpenRPC

The output matches the documented shape, but skip_type_check disables validation and leaves detailed with an empty OpenRPC schema.

Location: src/rpc/net.cpp:652 (head).

Details and suggested fix

RPCResult::MatchesType() returns true immediately when skip_type_check is set. Functional-test nodes run with rpcdoccheck=1, but the flag on the outer detailed entry prevents that subtree from being compared with its documentation. Without the flag, the existing check walks each OBJ_DYN level through m_inner[0] and verifies that every leaf is an object with numeric bytes and count, matching the RPC output. For a skip-checked OBJ_DYN, OpenRPCResultSchema() also returns an empty {} schema, so getopenrpcinfo describes nothing about detailed. Remove the skip_type_check options from the detailed documentation at lines 637–652 to restore both the runtime check and the schema.


Link

[suggestion] · Every call builds maps for all 3,626 cells and emits keys in unspecified order

Most map entries built on each call are discarded, and JSON keys appear in hash-bucket order that can vary between standard libraries.

Location: src/rpc/net.cpp:696 (head).

Details and suggested fix

NetStats::ForEach() visits all 3,626 cells: 2 directions × 7 networks × 7 connection types × 37 message buckets. For each cell, the callback builds three strings and inserts it into four levels of nested std::unordered_map. The serialization loop later drops entries with a zero counter, so on an idle or freshly started node most of this work produces no output. Unordered maps also emit keys in hash-bucket order, which can differ between standard libraries. The example orders recv before sent, and networks as i2p, onion, ipv6, ipv4. The per-message maps in getpeerinfo use std::map and emit sorted keys. Filter zero-counter entries in the callback before insertion and use std::map for the nested maps to avoid work on entries that are never emitted and keep the same JSON content in stable order. Runtime cost was not measured.


Link

[suggestion] · Partial-message assertion can run before the prefix arrives

The assertion can pass before node0 receives any of the first fragment, so it may not test the partial-message state it describes.

Location: test/functional/rpc_net.py:348 (head).

Details and suggested fix

send_raw_message() schedules a write on the framework event loop through call_soon_threadsafe(). The getnettotals call can therefore run before node0 reads the first 7 bytes, and both fragments may arrive together. Record the peer's bytesrecv from getpeerinfo and wait for it to grow by cut_pos before asserting; CNode::ReceiveMsgBytes() updates that counter when bytes arrive, before parsing. The 7-byte cut is still inside the v1 message-type field, so even a synchronized check covers only the state before the message type is known. Cutting inside the payload would also detect a regression that records the message as soon as its header is complete.


Link

[suggestion] · The new getnettotals field has no release note

Downstream users and operators are not told that getnettotals now returns a potentially large detailed breakdown.

Location: src/rpc/net.cpp:731 (head).

Details and suggested fix

This adds detailed to the user-visible getnettotals response, but the patch has no doc/release-notes-29418.md. doc/developer-notes.md asks for a PR-specific release note for API changes and other changes visible to end users. Add a short note describing the new breakdown and pointing to the RPC help for its layout.


Coverage details