p2p: Check peer threshold is met before giving up on ctx deadline (#12446)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Preston Van Loon
2023-05-28 08:24:59 -05:00
committed by GitHub
parent 2dcef85f97
commit 1ffc92999f

View File

@@ -62,13 +62,13 @@ func (s *Service) FindPeersWithSubnet(ctx context.Context, topic string,
currNum := len(s.pubsub.ListPeers(topic))
wg := new(sync.WaitGroup)
for {
if currNum >= threshold {
break
}
if err := ctx.Err(); err != nil {
return false, errors.Errorf("unable to find requisite number of peers for topic %s - "+
"only %d out of %d peers were able to be found", topic, currNum, threshold)
}
if currNum >= threshold {
break
}
nodes := enode.ReadNodes(iterator, int(params.BeaconNetworkConfig().MinimumPeersInSubnetSearch))
for _, node := range nodes {
info, _, err := convertToAddrInfo(node)