Skip to content

Commit

Permalink
Address Nishant's comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Sep 12, 2024
1 parent 330d07f commit 7f70bec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions beacon-chain/p2p/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -208,6 +210,7 @@ func (s *Service) listenForNewNodes() {
}

searchInProgress := false
var lastLogTime time.Time

iterator := s.dv5Listener.RandomNodes()
defer iterator.Close()
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion beacon-chain/p2p/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7f70bec

Please sign in to comment.