mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
randomPeer: Return if the context is cancelled when waiting for peers. (#15876)
* `randomPeer`: Return if the context is cancelled when waiting for peers. * `randomPeer`: Refactor to reduce indentation.
This commit is contained in:
@@ -1122,19 +1122,21 @@ func randomPeer(
|
||||
}
|
||||
}
|
||||
|
||||
slices.Sort(nonRateLimitedPeers)
|
||||
|
||||
if len(nonRateLimitedPeers) == 0 {
|
||||
log.WithFields(logrus.Fields{
|
||||
"peerCount": peerCount,
|
||||
"delay": waitPeriod,
|
||||
}).Debug("Waiting for a peer with enough bandwidth for data column sidecars")
|
||||
time.Sleep(waitPeriod)
|
||||
continue
|
||||
if len(nonRateLimitedPeers) > 0 {
|
||||
slices.Sort(nonRateLimitedPeers)
|
||||
randomIndex := randomSource.Intn(len(nonRateLimitedPeers))
|
||||
return nonRateLimitedPeers[randomIndex], nil
|
||||
}
|
||||
|
||||
randomIndex := randomSource.Intn(len(nonRateLimitedPeers))
|
||||
return nonRateLimitedPeers[randomIndex], nil
|
||||
log.WithFields(logrus.Fields{
|
||||
"peerCount": peerCount,
|
||||
"delay": waitPeriod,
|
||||
}).Debug("Waiting for a peer with enough bandwidth for data column sidecars")
|
||||
|
||||
select {
|
||||
case <-time.After(waitPeriod):
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}
|
||||
|
||||
return "", ctx.Err()
|
||||
|
||||
2
changelog/manu-random-peer.md
Normal file
2
changelog/manu-random-peer.md
Normal file
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- `randomPeer`: Return if the context is cancelled when waiting for peers.
|
||||
Reference in New Issue
Block a user