This adds five new tracepoints with documentation and tests for network connections:
- established connections with
net:inbound_connection
andnet:outbound_connection
- closed connections (both closed by us or by the peer) with
net:closed_connnection
- inbound connections that we choose to evict with
net:evicted_inbound_connection
- connections that are misbehaving and punished with
net:misbehaving_connection
I’ve been using these tracepoints for a few months now to monitor connection lifetimes, re-connection frequency by IP and netgroup, misbehavior, peer discouragement, and eviction and more. Together with the two existing P2P message tracepoints they allow for a good overview of local P2P network activity. Also sort-of addresses #22006 (review).
I’ve been back and forth on which arguments to include. For example, net:evicted_connection
could also include some of the eviction metrics like e.g. last_block_time
, min_ping_time
, … but I’ve left them out for now. If wanted, this can be added here or in a follow-up. I’ve tried to minimize a potential performance impact by measuring executed instructions with gdb
where possible (method described here). I don’t think a few hundred extra instructions are too crucial, as connection opens/closes aren’t too frequent (compared to e.g. P2P messages). Note: e.g. CreateNodeFromAcceptedSocket()
usually executes between 80k and 90k instructions for each new inbound connection.
tracepoint | instructions |
---|---|
net:inbound_connection | 390 ins |
net:outbound_connection | between 700 and 1000 ins |
net:closed_connnection | 473 ins |
net:evicted_inbound_connection | not measured; likely similar to net:closed_connnection |
net:misbehaving_connection | not measured |
Also added a bpftrace (tested with v0.14.1) log_p2p_connections.bt
example script that produces output similar to:
0Attaching 6 probes...
1Logging opened, closed, misbehaving, and evicted P2P connections
2OUTBOUND conn to 127.0.0.1:15287: id=0, type=block-relay-only, network=0, total_out=1
3INBOUND conn from 127.0.0.1:45324: id=1, type=inbound, network=0, total_in=1
4MISBEHAVING conn id=1, message='getdata message size = 50001'
5CLOSED conn to 127.0.0.1:15287: id=0, type=block-relay-only, network=0, established=1231006505
6EVICTED conn to 127.0.0.1:45324: id=1, type=inbound, network=0, established=1612312312