Skip to content

Commit

Permalink
Bor Mainnet dns discovery (#12506)
Browse files Browse the repository at this point in the history
Polygon have recently implemented enr based DNS discovery for bor main
net. This PR adds the discovery location to erigon's known dns networks.

It also contains a monor config update to avoid leaking code from the
p2p layer.

Background:
https://forum.polygon.technology/t/introducing-our-new-dns-discovery-for-polygon-pos-faster-smarter-more-connected/19871
  • Loading branch information
mh0lt authored Nov 2, 2024
1 parent 10677ca commit f617c43
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 53 deletions.
10 changes: 2 additions & 8 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
return res
}

discovery := func() enode.Iterator {
d, err := setupDiscovery(backend.config.EthDiscoveryURLs)
if err != nil {
panic(err)
}
return d
}
p2pConfig.DiscoveryDNS = backend.config.EthDiscoveryURLs

listenHost, listenPort, err := splitAddrIntoHostAndPort(p2pConfig.ListenAddr)
if err != nil {
Expand Down Expand Up @@ -469,7 +463,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
}

cfg.ListenAddr = fmt.Sprintf("%s:%d", listenHost, listenPort)
server := sentry.NewGrpcServer(backend.sentryCtx, discovery, readNodeInfo, &cfg, protocol, logger)
server := sentry.NewGrpcServer(backend.sentryCtx, nil, readNodeInfo, &cfg, protocol, logger)
backend.sentryServers = append(backend.sentryServers, server)
sentries = append(sentries, direct.NewSentryClientDirect(protocol, server))
}
Expand Down
35 changes: 0 additions & 35 deletions eth/discovery.go

This file was deleted.

23 changes: 13 additions & 10 deletions p2p/sentry/sentry_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,10 @@ func NewGrpcServer(ctx context.Context, dialCandidates func() enode.Iterator, re
var disc enode.Iterator
if dialCandidates != nil {
disc = dialCandidates()
} else {
disc, _ = setupDiscovery(ss.p2p.DiscoveryDNS)
}

protocols := []uint{protocol}
if protocol == direct.ETH67 {
protocols = append(protocols, direct.ETH66)
Expand Down Expand Up @@ -711,8 +714,8 @@ func Sentry(ctx context.Context, dirs datadir.Dirs, sentryAddr string, discovery
}
return d
}
cfg.DiscoveryDNS = discoveryDNS
sentryServer := NewGrpcServer(ctx, discovery, func() *eth.NodeInfo { return nil }, cfg, protocolVersion, logger)
sentryServer.discoveryDNS = discoveryDNS

grpcServer, err := grpcSentryServer(ctx, sentryAddr, sentryServer, healthCheck)
if err != nil {
Expand All @@ -729,7 +732,6 @@ type GrpcServer struct {
proto_sentry.UnimplementedSentryServer
ctx context.Context
Protocols []p2p.Protocol
discoveryDNS []string
GoodPeers sync.Map
TxSubscribed uint32 // Set to non-zero if downloader is subscribed to transaction messages
p2pServer *p2p.Server
Expand Down Expand Up @@ -1020,17 +1022,18 @@ func (ss *GrpcServer) HandShake(context.Context, *emptypb.Empty) (*proto_sentry.

func (ss *GrpcServer) startP2PServer(genesisHash libcommon.Hash) (*p2p.Server, error) {
if !ss.p2p.NoDiscovery {
if len(ss.discoveryDNS) == 0 {
if len(ss.p2p.DiscoveryDNS) == 0 {
if url := params.KnownDNSNetwork(genesisHash, "all"); url != "" {
ss.discoveryDNS = []string{url}
ss.p2p.DiscoveryDNS = []string{url}
}
}
for _, p := range ss.Protocols {
dialCandidates, err := setupDiscovery(ss.discoveryDNS)
if err != nil {
return nil, err

for _, p := range ss.Protocols {
dialCandidates, err := setupDiscovery(ss.p2p.DiscoveryDNS)
if err != nil {
return nil, err
}
p.DialCandidates = dialCandidates
}
p.DialCandidates = dialCandidates
}
}

Expand Down
2 changes: 2 additions & 0 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ type Config struct {
TmpDir string

MetricsEnabled bool

DiscoveryDNS []string
}

func (config *Config) ListenPort() int {
Expand Down
2 changes: 2 additions & 0 deletions params/bootnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func KnownDNSNetwork(genesis libcommon.Hash, protocol string) string {
net = "sepolia"
case HoleskyGenesisHash:
net = "holesky"
case BorMainnetGenesisHash:
return "enrtree://AKUEZKN7PSKVNR65FZDHECMKOJQSGPARGTPPBI7WS2VUL4EGR6XPC@pos.polygon-peers.io"
default:
return ""
}
Expand Down

0 comments on commit f617c43

Please sign in to comment.