From f1a22910374e2f955641c9886b74eed189b27b97 Mon Sep 17 00:00:00 2001 From: tuyennhv Date: Sun, 13 Aug 2023 00:08:27 +0700 Subject: [PATCH] feat: limit incoming connections to lodestar (#5860) * feat: limit incoming connections to lodestar * chore: revise comment --- 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..bd96de0e6bbf 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 + // it's not safe if we increase this number + 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: {