feat(rest): expose peer score and disconnect reason on /eth/v1/node/peers - #8449
Draft
barnabasbusa wants to merge 3 commits into
Draft
feat(rest): expose peer score and disconnect reason on /eth/v1/node/peers#8449barnabasbusa wants to merge 3 commits into
barnabasbusa wants to merge 3 commits into
Conversation
Adds an optional `score` field to the `RestNodePeer` payload returned by
`GET /eth/v1/node/peers` and `GET /eth/v1/node/peers/{peer_id}`, populated
from `Peer.score` (Nimbus's internal application-level peer score).
This field is not part of the beacon-API specification and is emitted
alongside the existing `agent`/`proto` extensions. It is marked
`Opt[int]` so JSON output remains backwards-compatible (omitted when not
set), in line with `omitOptionalFields = true` for `RestJson`.
Extends the `RestNodePeer` payload returned by `GET /eth/v1/node/peers`
and `GET /eth/v1/node/peers/{peer_id}` with an optional
`disconnect_reason` field. Population is driven by two new fields on
the `Peer` object - `lastDisconnectReason` and `lastDisconnectAt` -
that are written inside `Peer.disconnect()`. Centralising the write at
the disconnect choke point captures every existing call site (~20)
without per-site edits.
`mapDisconnectReason` translates Nimbus's internal `DisconnectionReason`
enum into a small controlled vocabulary aimed at cross-client
consumption:
ClientShutDown -> client_shutdown
IrrelevantNetwork -> irrelevant_network
FaultOrError -> io_error
PeerScoreLow -> bad_score
The field is `Opt[string]` so JSON output stays backwards compatible
(omitted while never set) under `omitOptionalFields = true` for
`RestJson`.
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`. Gate the `peer.lastDisconnectReason` lookup in both the list and single-peer handlers on `peer.connectionState` so the field is omitted (Opt.none) for connected/connecting peers.
tersec
reviewed
Jun 19, 2026
| of PeerType.Outgoing: | ||
| "outbound" | ||
|
|
||
| proc mapDisconnectReason(reason: DisconnectionReason): string = |
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 two optional fields per a simplified beacon-API spec extension currently under discussion:score— fromPeer.score: int(Nimbus's application-level reputation score, [0, 1000] with default 300)disconnect_reason— from a newlastDisconnectReasonfield onPeer, mapped to the spec controlled vocabagent_versionis already exposed in Nimbus's current response (under field nameagent).downscore_reasonsis deliberately omitted — Nimbus doesn't currently track per-event reason history. Adding it would require instrumenting the ~30 call sites that adjustPeer.score. Happy to follow up if there's interest.Spec proposal
ethereum/beacon-APIs#606
What's in this PR
Commit 1: expose
scorebeacon_chain/spec/eth2_apis/rest_types.nim— addscore*: Opt[int]toRestNodePeer.beacon_chain/rpc/rest_node_api.nim— populate frompeer.scorein both the list and single-peer handlers.Commit 2: expose
disconnect_reasonbeacon_chain/networking/eth2_network.nim— addlastDisconnectReason*: Opt[DisconnectionReason]+lastDisconnectAt*: Opt[chronos.Moment]to thePeerobject. Instrumentproc disconnect*at the top, so all ~20 disconnect call sites are caught at the single choke point.beacon_chain/spec/eth2_apis/rest_types.nim— adddisconnect_reason*: Opt[string]toRestNodePeer.beacon_chain/rpc/rest_node_api.nim— addmapDisconnectReason()translating Nimbus's 4-valueDisconnectionReasonenum to the spec controlled vocab (ClientShutDown → client_shutdown,IrrelevantNetwork → irrelevant_network,FaultOrError → io_error,PeerScoreLow → bad_score).Coordinated implementations
Part of a coordinated multi-client effort — see ethereum/beacon-APIs#606 for the other five client PRs.
Status
Draft.
nim checkon all three patched files: identical error counts vs. pre-patch baseline (only pre-existing version.nim / forks.nim issues, none introduced by this patch).