Skip to content

Commit

Permalink
feat(direct peers): configure static peers to be direct peers in pubs…
Browse files Browse the repository at this point in the history
…ub options
  • Loading branch information
thedevbirb committed Mar 27, 2024
1 parent 97edffa commit a22b2fd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions beacon-chain/p2p/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,39 @@ func (s *Service) pubsubOptions() []pubsub.Option {
pubsub.WithGossipSubParams(pubsubGossipParam()),
pubsub.WithRawTracer(gossipTracer{host: s.host}),
}

if len(s.cfg.StaticPeers) > 0 {
s.addDirectPeersOption(&psOpts)
}

return psOpts
}

// addDirectPeersOption parses the static peers from the service configuration and adds
// the direct peers option to the pubsub options.
func (s *Service) addDirectPeersOption(psOpts *[]pubsub.Option) {
addrs, err := PeersFromStringAddrs(s.cfg.StaticPeers)

if err != nil {
log.WithError(err).Error("Could not convert static peers raw ENRs into multiaddresses")
return
}

if len(addrs) == 0 {
log.Warn("Converting static peers raw ENRs into multiaddresses resulted in an empty list. Ignoring direct peers configuration")
return
}

directAddrInfos, err := peer.AddrInfosFromP2pAddrs(addrs...)

if err != nil {
log.WithError(err).Error("Could not configure direct peers")
return
}

*psOpts = append(*psOpts, pubsub.WithDirectPeers(directAddrInfos))
}

// creates a custom gossipsub parameter set.
func pubsubGossipParam() pubsub.GossipSubParams {
gParams := pubsub.DefaultGossipSubParams()
Expand Down

0 comments on commit a22b2fd

Please sign in to comment.