From d69f8ebbabc77a2d79a54c23108a8f83df84c24b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 5 Dec 2024 22:29:42 +0300 Subject: [PATCH] network: optimize optimalN for small networks Consider 10-node network. FanOut is 6 for it. optimalN is 12. But it's a 10-node network, you can't have more than 9 peers there. So adjust the formula for netSize-1. Signed-off-by: Roman Khimov --- pkg/network/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index e4d25485d..995744eb4 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -482,7 +482,7 @@ func (s *Server) run() { var ( netSize = s.discovery.NetworkSize() // "Optimal" number of peers. - optimalN = s.discovery.GetFanOut() * 2 + optimalN = min(s.discovery.GetFanOut()*2, netSize-1) // Real number of peers. peerN = s.HandshakedPeersCount() // Timeout value for the next peerTimer, long one by default. @@ -494,7 +494,7 @@ func (s *Server) run() { s.discovery.RequestRemote(s.AttemptConnPeers) // Check/retry new connections soon. peerT = s.ProtoTickInterval - } else if s.MinPeers > 0 && loopCnt%s.MinPeers == 0 && optimalN > peerN && optimalN < s.MaxPeers && optimalN < netSize { + } else if s.MinPeers > 0 && loopCnt%s.MinPeers == 0 && optimalN > peerN && optimalN < s.MaxPeers { // Having some number of peers, but probably can get some more, the network is big. // It also allows to start picking up new peers proactively, before we suddenly have