From 79708eb0b22cf2b38af40e5318ba618ff452a814 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 8 Aug 2023 10:32:44 +0700 Subject: [PATCH] feat: limit incoming connections to lodestar --- packages/beacon-node/src/network/libp2p/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/beacon-node/src/network/libp2p/index.ts b/packages/beacon-node/src/network/libp2p/index.ts index 4540cae67974..4bdc23d2f891 100644 --- a/packages/beacon-node/src/network/libp2p/index.ts +++ b/packages/beacon-node/src/network/libp2p/index.ts @@ -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, @@ -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: {