Skip to content

Commit

Permalink
feat: limit incoming connections to lodestar
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Aug 8, 2023
1 parent 108b8ed commit 79708eb
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
// this is 10% of our target peers
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 79708eb

Please sign in to comment.