Skip to content

Commit

Permalink
feat: limit incoming connections to lodestar (#5860)
Browse files Browse the repository at this point in the history
* feat: limit incoming connections to lodestar

* chore: revise comment
  • Loading branch information
twoeths authored Aug 12, 2023
1 parent 3c7b815 commit f1a2291
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/beacon-node/src/network/libp2p/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export async function createNodeJsLibp2p(
transports: [
tcp({
maxConnections: networkOpts.maxPeers,
// socket option: the maximum length of the queue of pending connections
// https://nodejs.org/dist/latest-v18.x/docs/api/net.html#serverlisten
// it's not safe if we increase this number
backlog: 5,
closeServerOnMaxConnections: {
closeAbove: networkOpts.maxPeers ?? Infinity,
listenBelow: networkOpts.maxPeers ?? Infinity,
Expand All @@ -101,6 +105,9 @@ export async function createNodeJsLibp2p(
//maxConnections: options.maxConnections,
// DOCS: There is no way to turn off autodial other than setting minConnections to 0
minConnections: 0,
// the maximum number of pending connections libp2p will accept before it starts rejecting incoming connections.
// make it the same to backlog option above
maxIncomingPendingConnections: 5,
},
datastore,
services: {
Expand Down

0 comments on commit f1a2291

Please sign in to comment.