Skip to content

feat(beacon-api): expose peer-scoring fields on /eth/v1/node/peers#9307

Draft
barnabasbusa wants to merge 4 commits into
sigp:unstablefrom
barnabasbusa:bbusa/peer-scores-last-event
Draft

feat(beacon-api): expose peer-scoring fields on /eth/v1/node/peers#9307
barnabasbusa wants to merge 4 commits into
sigp:unstablefrom
barnabasbusa:bbusa/peer-scores-last-event

Conversation

@barnabasbusa
Copy link
Copy Markdown
Contributor

Summary

Extends /eth/v1/node/peers (and /eth/v1/node/peers/{peer_id}) with four optional fields per a simplified beacon-API spec extension currently under discussion:

  • agent_version — from PeerInfo::client().agent_string
  • score — from PeerInfo::score().score()
  • disconnect_reason — from the new LastDisconnect tracker, mapped to the spec controlled vocab
  • downscore_reasons — single-element array derived from the new LastAction tracker

Spec proposal

ethereum/beacon-APIs#606

What's in this PR

  1. PeerData extension (common/eth2/src/types.rs) — adds 4 Option<...> fields with #[serde(skip_serializing_if = "Option::is_none")].
  2. LastAction + LastDisconnect (beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs) — new tracking structs persisted on PeerInfo (the /lighthouse/peers endpoint already surfaces these for richer Lighthouse-specific telemetry).
  3. Granular RPC error tags (beacon_node/lighthouse_network/src/peer_manager/mod.rs) — rpc_error_msg() replaces the catch-all "handle_rpc_error" reason with per-RPCError-variant tags. Mirrored at the handler in goodbye_reason_name().
  4. Two map_* helpers (beacon_node/http_api/src/lib.rs) translate Lighthouse-internal tags to the spec controlled vocab before serialization.

Coordinated implementations

Part of a coordinated multi-client effort — see ethereum/beacon-APIs#606 for the other five client PRs.

Status

Draft. Opening alongside the other client PRs to validate the spec proposal end-to-end. Tests in beacon_node/http_api/tests/tests.rs updated to cover the new fields; full suite not run yet pending spec convergence.

Adds two optional fields to the PeerInfo JSON returned by
/lighthouse/peers and /lighthouse/peers/connected:

- last_action: { reason, source, action, delta, seconds_ago }
  populated from PeerDB::report_peer (skipped for trusted peers
  and for the gossipsub heartbeat sync path)
- last_disconnect: { reason, code, direction, seconds_ago }
  populated from PeerManager::goodbye_peer (direction=sent) and
  the inbound goodbye handler in service.rs (direction=received)

Both fields use #[serde(skip_serializing_if = "Option::is_none")]
so they only appear after the first relevant event, leaving the
existing JSON shape backwards-compatible.

Lets external tooling display per-peer downscore reasons across
clients without scraping logs or Prometheus.
handle_rpc_error previously wrote a single "handle_rpc_error" msg for
every RPCError variant, collapsing rate-limits, ssz decode failures,
unsupported protocols, timeouts and everything else into one tag.
External tooling that consumes /lighthouse/peers can't tell why a peer
was downscored without parsing logs.

Adds rpc_error_msg() which maps each RPCError variant (and the inner
RpcErrorResponse code where applicable) to a stable static string:
rpc_incomplete_stream, rpc_invalid_data, rpc_ssz_decode_error,
rpc_io_error, rpc_negotiation_timeout, rpc_stream_timeout,
rpc_unsupported_protocol, rpc_unknown_status, rpc_resource_unavailable,
rpc_server_error, rpc_invalid_request, rpc_rate_limited,
rpc_blobs_not_found.
Add four optional fields to PeerData on the standard
/eth/v1/node/peers and /eth/v1/node/peers/{peer_id} endpoints per
the simplified beacon-API peer-scoring proposal:

- agent_version: libp2p identify agent string
- score: current numeric peer score
- disconnect_reason: last goodbye reason, mapped into the spec
  PeerDisconnectReason vocab
- downscore_reasons: most recent downscoring tag, mapped into the
  spec PeerScoreReason vocab

Translation between Lighthouse's internal '&'static str' tags and
the spec vocabularies is handled by map_disconnect_reason and
map_downscore_reason at the top of beacon_node/http_api/src/lib.rs.
… state

Per the proposed beacon-API spec
(ethereum/beacon-APIs#606), `disconnect_reason`
MUST only be populated when the peer's `state` is `disconnected` or
`disconnecting`. Wrap the existing `last_disconnect()` lookup in both
the single-peer and list handlers so the field is omitted (None) for
connected/connecting peers.
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.

1 participant