Skip to content

Commit

Permalink
convertToAddrInfo: Ensure len(infos) == 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Apr 4, 2024
1 parent a0c0326 commit e9d80e2
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions beacon-chain/p2p/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (s *Service) filterPeer(node *enode.Node) bool {
return false
}

if len(multiAddrs) == 0 {
if peerData == nil || len(multiAddrs) == 0 {
return false
}

Expand Down Expand Up @@ -476,12 +476,8 @@ func convertToAddrInfo(node *enode.Node) (*peer.AddrInfo, []ma.Multiaddr, error)
return nil, nil, errors.Wrapf(err, "could not convert to peer info: %v", multiAddrs)
}

if len(infos) > 1 {
return nil, nil, errors.Errorf("infos contains %v elements, expected not more than 1", len(infos))
}

if len(infos) == 0 {
return nil, multiAddrs, nil
if len(infos) != 1 {
return nil, nil, errors.Errorf("infos contains %v elements, expected exactly 1", len(infos))
}

return &infos[0], multiAddrs, nil
Expand Down

0 comments on commit e9d80e2

Please sign in to comment.