feat(beacon-api): expose peer-scoring fields on /eth/v1/node/peers#9307
Draft
barnabasbusa wants to merge 4 commits into
Draft
feat(beacon-api): expose peer-scoring fields on /eth/v1/node/peers#9307barnabasbusa wants to merge 4 commits into
barnabasbusa wants to merge 4 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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— fromPeerInfo::client().agent_stringscore— fromPeerInfo::score().score()disconnect_reason— from the newLastDisconnecttracker, mapped to the spec controlled vocabdownscore_reasons— single-element array derived from the newLastActiontrackerSpec proposal
ethereum/beacon-APIs#606
What's in this PR
PeerDataextension (common/eth2/src/types.rs) — adds 4Option<...>fields with#[serde(skip_serializing_if = "Option::is_none")].LastAction+LastDisconnect(beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs) — new tracking structs persisted onPeerInfo(the/lighthouse/peersendpoint already surfaces these for richer Lighthouse-specific telemetry).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 ingoodbye_reason_name().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.rsupdated to cover the new fields; full suite not run yet pending spec convergence.