diff --git a/beacon-chain/p2p/discovery.go b/beacon-chain/p2p/discovery.go index 703778339334..f784575e04b7 100644 --- a/beacon-chain/p2p/discovery.go +++ b/beacon-chain/p2p/discovery.go @@ -192,6 +192,8 @@ func (s *Service) RefreshPersistentSubnets() { // listen for new nodes watches for new nodes in the network and adds them to the peerstore. func (s *Service) listenForNewNodes() { + const minLogInterval = 1 * time.Minute + peersSummary := func(threshold uint) (uint, uint) { // Retrieve how many active peers we have. activePeers := s.Peers().Active() @@ -208,6 +210,7 @@ func (s *Service) listenForNewNodes() { } searchInProgress := false + var lastLogTime time.Time iterator := s.dv5Listener.RandomNodes() defer iterator.Close() @@ -248,13 +251,16 @@ func (s *Service) listenForNewNodes() { continue } - if searchInProgress { + if searchInProgress && time.Since(lastLogTime) > minLogInterval { + lastLogTime = time.Now() log.WithFields(fields).Debug("Searching for new active peers - continue") - } else { - log.WithFields(fields).Debug("Searching for new active peers - start") } - searchInProgress = true + if !searchInProgress { + searchInProgress = true + lastLogTime = time.Now() + log.WithFields(fields).Debug("Searching for new active peers - start") + } // Restrict dials if limit is applied. if flags.MaxDialIsActive() { diff --git a/beacon-chain/p2p/service.go b/beacon-chain/p2p/service.go index ed37079a1eaa..428482218fb8 100644 --- a/beacon-chain/p2p/service.go +++ b/beacon-chain/p2p/service.go @@ -45,7 +45,7 @@ var pollingPeriod = 6 * time.Second // When looking for new nodes, if not enough nodes are found, // we stop after this amount of iterations. -var batchSize = 40_000 +var batchSize = 2_000 // Refresh rate of ENR set at twice per slot. var refreshRate = slots.DivideSlotBy(2) diff --git a/beacon-chain/p2p/subnets.go b/beacon-chain/p2p/subnets.go index 9ece3ee7d60a..8537d2e6474e 100644 --- a/beacon-chain/p2p/subnets.go +++ b/beacon-chain/p2p/subnets.go @@ -141,6 +141,8 @@ func (s *Service) FindPeersWithSubnet( index uint64, threshold int, ) (bool, error) { + const minLogInterval = 1 * time.Minute + ctx, span := trace.StartSpan(ctx, "p2p.FindPeersWithSubnet") defer span.End() @@ -185,6 +187,8 @@ func (s *Service) FindPeersWithSubnet( log.WithField("currentPeerCount", peerCountForTopic).Debug("Searching for new peers for a subnet - start") + lastLogTime := time.Now() + wg := new(sync.WaitGroup) for { // If the context is done, we can exit the loop. This is the unhappy path. @@ -222,7 +226,10 @@ func (s *Service) FindPeersWithSubnet( break } - log.WithField("currentPeerCount", peerCountForTopic).Debug("Searching for new peers for a subnet - continue") + if time.Since(lastLogTime) > minLogInterval { + lastLogTime = time.Now() + log.WithField("currentPeerCount", peerCountForTopic).Debug("Searching for new peers for a subnet - continue") + } } log.WithField("currentPeerCount", threshold).Debug("Searching for new peers for a subnet - success")