mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -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 {
|
||||||
|
slices.Sort(nonRateLimitedPeers)
|
||||||
if len(nonRateLimitedPeers) == 0 {
|
randomIndex := randomSource.Intn(len(nonRateLimitedPeers))
|
||||||
log.WithFields(logrus.Fields{
|
return nonRateLimitedPeers[randomIndex], nil
|
||||||
"peerCount": peerCount,
|
|
||||||
"delay": waitPeriod,
|
|
||||||
}).Debug("Waiting for a peer with enough bandwidth for data column sidecars")
|
|
||||||
time.Sleep(waitPeriod)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
randomIndex := randomSource.Intn(len(nonRateLimitedPeers))
|
log.WithFields(logrus.Fields{
|
||||||
return nonRateLimitedPeers[randomIndex], nil
|
"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()
|
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