feat(api): add runtime direct peer management endpoints#8853
feat(api): add runtime direct peer management endpoints#8853nflaig merged 14 commits intoChainSafe:unstablefrom
Conversation
Add HTTP API endpoints to manage GossipSub direct peers at runtime:
- POST /eth/v1/lodestar/direct_peer?peer=<multiaddr|enr>
Adds a direct peer. Accepts multiaddr with peer ID or ENR string.
Returns {peerId: string | null}
- DELETE /eth/v1/lodestar/direct_peer?peerId=<peer_id>
Removes a direct peer by peer ID.
Returns {removed: boolean}
- GET /eth/v1/lodestar/direct_peers
Lists current direct peer IDs.
Returns string[]
Direct peers maintain permanent mesh connections without GRAFT/PRUNE
negotiation, making them useful for trusted peer relationships that
should persist regardless of scoring.
This enables operators to dynamically add/remove direct peers without
requiring a node restart, which is particularly useful for:
- Adding trusted peers discovered during operation
- Removing misbehaving peers from the direct list
- Temporary mesh connections for debugging/testing
Summary of ChangesHello @lodekeeper, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the operational flexibility of the Lodestar beacon node by providing HTTP API endpoints for runtime management of GossipSub direct peers. Previously, direct peers could only be configured at startup, limiting dynamic adjustments. With these changes, operators can now add, remove, and list trusted peers on the fly, which is crucial for adapting to changing network conditions, debugging, and improving overall network resilience without service interruptions. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature for managing direct peers at runtime through new API endpoints. The implementation is well-integrated across the API, network, and gossip layers, following existing patterns in the codebase. I have one suggestion to improve the robustness of the addDirectPeer implementation by properly handling an asynchronous operation, which will prevent potential race conditions.
Address review feedback - ensure addresses are stored before adding peer to direct set to avoid potential race conditions.
|
Addressed review feedback in 9e45760:
|
|
Simplified JSDoc comments in 9a7b843 👍 |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces new HTTP API endpoints for managing GossipSub direct peers at runtime, which is a great feature for operators. The implementation is well-structured, propagating the changes from the API layer down to the network core. My review focuses on improving API consistency and ensuring the new logic is well-tested. I've suggested using plural endpoint names for consistency and adding unit tests for the new peer management functions in Eth2Gossipsub.
This reverts commit 3e93224.
Consistent with REST conventions - all operations on the direct_peers resource now use the plural form.
- Reject addDirectPeer if no addresses provided (cannot connect without them) - Add DirectPeerInput type alias to clarify that parameter accepts multiaddr or ENR
Added DirectPeerInput type to @lodestar/api routes.lodestar for API consumers. Type is still defined in beacon-node for internal use until api package exports are updated to allow direct imports from routes modules.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature for runtime management of direct peers. The implementation is well-structured, following the existing layered architecture of the network stack and reusing existing parsing logic. The new API endpoints are RESTful and their server-side implementations are clean. I have one suggestion to add a sanity check to prevent a node from adding itself as a direct peer.
eaa6791 to
47a5e4f
Compare
nflaig
left a comment
There was a problem hiding this comment.
LGTM - we can simplify changes in Lodestar later on if we decide to upstream the direct peer management ChainSafe/js-libp2p-gossipsub#541
packages/beacon-node/test/e2e/network/onWorker/dataSerialization.test.ts
Outdated
Show resolved
Hide resolved
packages/beacon-node/test/e2e/network/onWorker/dataSerialization.test.ts
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #8853 +/- ##
=========================================
Coverage 52.36% 52.36%
=========================================
Files 848 848
Lines 63532 63532
Branches 4710 4710
=========================================
Hits 33268 33268
Misses 30195 30195
Partials 69 69 🚀 New features to boost your workflow:
|
|
🎉 This PR is included in v1.40.0 🎉 |
Description
Add HTTP API endpoints to manage GossipSub direct peers at runtime, allowing operators to dynamically add/remove trusted peers without requiring a node restart.
New Endpoints
/eth/v1/lodestar/direct_peers?peer=<multiaddr|enr>/eth/v1/lodestar/direct_peers?peerId=<peer_id>/eth/v1/lodestar/direct_peersMotivation
Direct peers maintain permanent mesh connections without GRAFT/PRUNE negotiation. Currently, they can only be configured via the
--directPeersCLI flag at startup.This PR enables runtime management which is useful for:
Implementation
addDirectPeer,removeDirectPeer,getDirectPeersmethods toEth2GossipsubclassparseDirectPeers()function for multiaddr/ENR parsingApiError(400)on invalid peer input (instead of returning null)Error Handling
ApiError(400)with descriptive messageApiError(400)ApiError(400)Testing
directPeers.test.tscovers the parsing logic (11 tests passing)Closes #7559
This PR was authored with AI assistance (Lodekeeper 🌟)