feat(beaconrestapi): expose peer-scoring fields on /eth/v1/node/peers#10715
Draft
barnabasbusa wants to merge 4 commits into
Draft
feat(beaconrestapi): expose peer-scoring fields on /eth/v1/node/peers#10715barnabasbusa wants to merge 4 commits into
barnabasbusa wants to merge 4 commits into
Conversation
Bring Teku's /teku/v1/nodes/peer_scores endpoint to parity with the
patches already shipped for Lighthouse, Lodestar, and Prysm so dora's
matrix can render real downscore reasons rather than just a raw gossip
score.
Per peer, the response now also includes:
- reputation_score: the internal ReputationAdjustment-driven int
- last_action: { reason, delta, seconds_ago } for the most recent
reputation-affecting event. reason is either a ReputationAdjustment
enum name or a DisconnectReason enum name when a disconnection was
the last event.
Both new fields are optional - they are omitted when no data has been
recorded yet - so existing consumers that only read peer_id and
gossip_score continue to work unchanged.
DefaultReputationManager now records the most recent adjustment (and
the most recent disconnection that carried a reason) per peer and
exposes getReputationScore / getLastAdjustment accessors. Eth2P2PNetwork
gains a getReputationManager() hook so REST handlers can reach the
manager without having to thread it through every test/mock variant.
Teku's errorprone is configured with -Werror, so the (int) cast on Math.max(0L, ...) tripped the build with: warning: [MathTargetType] Neither of the function arguments are int types but the result is treated as such. Extracts the conversion to a secondsSince() helper that clamps the long age against Integer.MAX_VALUE before narrowing, so the cast is local to a small helper that the linter accepts.
Add four optional fields to /eth/v1/node/peers and
/eth/v1/node/peers/{peer_id} per the simplified beacon-API peer scoring
proposal:
- agent_version: libp2p identify agent string (now plumbed through the
Peer interface and exposed by LibP2PPeer).
- score: ReputationManager's internal reputation score as a double.
- disconnect_reason: last DisconnectReason mapped to the spec's
PeerDisconnectReason vocabulary.
- downscore_reasons: list-wrapped reputation adjustment reason mapped
to the spec's PeerScoreReason vocabulary (currently "unknown" for
Teku's coarse penalty enum).
The Jackson Peer DTO in data:serializer gains matching nullable fields
so any consumer that deserialises it still works, while the live OpenAPI
schema is updated via a new PeerView record that wraps Eth2PeerWithEnr
together with the per-peer reputation snapshot. All four fields are
omitted when data is unavailable, so existing consumers are unaffected.
…ing 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`. Teku exposes only `connected`/`disconnected` via `Eth2Peer#isConnected()`, so suppress the field for connected 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— from libp2p identify (viaLibP2PPeer.maybeAgentString)score— fromReputationManager.getReputationScore(nodeId)disconnect_reason— fromLastAdjustment.reasonwhen it matches aDisconnectReasonenumdownscore_reasons— single-element array, currently always["unknown"]for penalty events (see Notes)Spec proposal
ethereum/beacon-APIs#606
What's in this PR
Peerinterface (networking/p2p/src/main/java/.../peer/Peer.java) — addsdefault Optional<String> getAgentVersion().LibP2PPeer.getAgentVersion()override +DelegatingPeerdelegation.provider.Peer(data/serializer/.../api/provider/Peer.java) — adds 4 nullable Jackson fields with@JsonInclude(NON_NULL)and a 5-arg backward-compat constructor.GetPeers.java,GetPeerById.java) — introduces aPeerViewrecord wrappingEth2PeerWithEnr+ reputation data; threadsReputationManagerthrough via existingNetworkDataProvider.getReputationManager().PeerScoreReasonMapper(new) — controlled-vocab translator forReputationAdjustmentandDisconnectReason.Notes
ReputationAdjustmentenum (LARGE_PENALTY/SMALL_PENALTY/LARGE_REWARD/SMALL_REWARD) carries no granular cause information.downscore_reasonsis therefore["unknown"]whenever a penalty event is recorded, ornull(omitted) when the last event was a reward / disconnect. Surfacing a finer-grained reason would require extendingReputationAdjustmentitself — happy to follow up.disconnect_reasononly populates whenLastAdjustment.reasonmatches aDisconnectReasonenum name (this is already how Teku's reputation manager records disconnects viaDefaultReputationManager.Reputation.reportDisconnection).Coordinated implementations
Part of a coordinated multi-client effort — see ethereum/beacon-APIs#606 for the other five client PRs.
Status
Draft.
:data:serializer:compileJava+:data:beaconrestapi:compileJavaclean (errorprone with-Werrorpasses). ExistingGetPeersTest/GetPeerByIdTestmay need follow-up updates since the response wrapper now nests aPeerView; production code is fine.