Skip to content

Commit

Permalink
Enable both eth/66 and eth/67 by default (#6048)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis authored Nov 15, 2022
1 parent 32629bd commit 14c0643
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,14 @@ Detailed explanation: [./docs/programmers_guide/db_faq.md](./docs/programmers_gu

| Port | Protocol | Purpose | Expose |
|:-----:|:---------:|:----------------------:|:-------:|
| 30303 | TCP & UDP | eth/66 or 67 peering | Public |
| 30303 | TCP & UDP | eth/66 peering | Public |
| 30304 | TCP & UDP | eth/67 peering | Public |
| 9090 | TCP | gRPC Connections | Private |
| 42069 | TCP & UDP | Snap sync (Bittorrent) | Public |
| 6060 | TCP | Metrics or Pprof | Private |
| 8551 | TCP | Engine API (JWT auth) | Private |

Typically, 30303 is exposed to the internet to allow incoming peering connections. 9090 is exposed only
Typically, 30303 and 30304 are exposed to the internet to allow incoming peering connections. 9090 is exposed only
internally for rpcdaemon or other connections, (e.g. rpcdaemon -> erigon).
Port 8551 (JWT authenticated) is exposed only internally for [Engine API] JSON-RPC queries from the Consensus Layer
node.
Expand Down
8 changes: 4 additions & 4 deletions cmd/sentry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
trustedPeers []string // trusted peers
discoveryDNS []string
nodiscover bool // disable sentry's discovery mechanism
protocol int
protocol uint
netRestrict string // CIDR to restrict peering to
maxPeers int
maxPendPeers int
Expand All @@ -45,7 +45,7 @@ func init() {
rootCmd.Flags().StringSliceVar(&trustedPeers, utils.TrustedPeersFlag.Name, []string{}, utils.TrustedPeersFlag.Usage)
rootCmd.Flags().StringSliceVar(&discoveryDNS, utils.DNSDiscoveryFlag.Name, []string{}, utils.DNSDiscoveryFlag.Usage)
rootCmd.Flags().BoolVar(&nodiscover, utils.NoDiscoverFlag.Name, false, utils.NoDiscoverFlag.Usage)
rootCmd.Flags().IntVar(&protocol, utils.P2pProtocolVersionFlag.Name, utils.P2pProtocolVersionFlag.Value, utils.P2pProtocolVersionFlag.Usage)
rootCmd.Flags().UintVar(&protocol, utils.P2pProtocolVersionFlag.Name, utils.P2pProtocolVersionFlag.Value.Value()[0], utils.P2pProtocolVersionFlag.Usage)
rootCmd.Flags().StringVar(&netRestrict, utils.NetrestrictFlag.Name, utils.NetrestrictFlag.Value, utils.NetrestrictFlag.Usage)
rootCmd.Flags().IntVar(&maxPeers, utils.MaxPeersFlag.Name, utils.MaxPeersFlag.Value, utils.MaxPeersFlag.Usage)
rootCmd.Flags().IntVar(&maxPendPeers, utils.MaxPendingPeersFlag.Name, utils.MaxPendingPeersFlag.Value, utils.MaxPendingPeersFlag.Usage)
Expand Down Expand Up @@ -81,14 +81,14 @@ var rootCmd = &cobra.Command{
staticPeers,
trustedPeers,
uint(port),
uint(protocol),
protocol,
)
if err != nil {
return err
}

_ = logging2.GetLoggerCmd("sentry", cmd)
return sentry.Sentry(cmd.Context(), dirs, sentryAddr, discoveryDNS, p2pConfig, uint(protocol), healthCheck)
return sentry.Sentry(cmd.Context(), dirs, sentryAddr, discoveryDNS, p2pConfig, protocol, healthCheck)
},
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,10 @@ var (
Usage: "Network listening port",
Value: 30303,
}
P2pProtocolVersionFlag = cli.IntFlag{
P2pProtocolVersionFlag = cli.UintSliceFlag{
Name: "p2p.protocol",
Usage: "Version of eth p2p protocol",
Value: int(nodecfg.DefaultConfig.P2P.ProtocolVersion),
Value: cli.NewUintSlice(nodecfg.DefaultConfig.P2P.ProtocolVersion...),
}
SentryAddrFlag = cli.StringFlag{
Name: "sentry.api.addr",
Expand Down Expand Up @@ -951,7 +951,7 @@ func setListenAddress(ctx *cli.Context, cfg *p2p.Config) {
cfg.ListenAddr = fmt.Sprintf(":%d", ctx.Int(ListenPortFlag.Name))
}
if ctx.IsSet(P2pProtocolVersionFlag.Name) {
cfg.ProtocolVersion = uint(ctx.Int(P2pProtocolVersionFlag.Name))
cfg.ProtocolVersion = ctx.UintSlice(P2pProtocolVersionFlag.Name)
}
if ctx.IsSet(SentryAddrFlag.Name) {
cfg.SentryAddr = SplitAndTrim(ctx.String(SentryAddrFlag.Name))
Expand Down
31 changes: 26 additions & 5 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -155,6 +156,16 @@ type Ethereum struct {
agg *libstate.Aggregator22
}

func splitAddrIntoHostAndPort(addr string) (host string, port int, err error) {
idx := strings.LastIndexByte(addr, ':')
if idx < 0 {
return "", 0, errors.New("invalid address format")
}
host = addr[:idx]
port, err = strconv.Atoi(addr[idx+1:])
return
}

// New creates a new Ethereum object (including the
// initialisation of the common Ethereum object)
func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethereum, error) {
Expand Down Expand Up @@ -297,12 +308,22 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
if err != nil {
return nil, err
}
cfg := stack.Config().P2P
cfg.NodeDatabase = filepath.Join(stack.Config().Dirs.Nodes, eth.ProtocolToString[cfg.ProtocolVersion])
server := sentry.NewGrpcServer(backend.sentryCtx, discovery, readNodeInfo, &cfg, cfg.ProtocolVersion)

backend.sentryServers = append(backend.sentryServers, server)
sentries = []direct.SentryClient{direct.NewSentryClientDirect(cfg.ProtocolVersion, server)}
refCfg := stack.Config().P2P
listenHost, listenPort, err := splitAddrIntoHostAndPort(refCfg.ListenAddr)
if err != nil {
return nil, err
}
for _, protocol := range refCfg.ProtocolVersion {
cfg := refCfg
cfg.NodeDatabase = filepath.Join(stack.Config().Dirs.Nodes, eth.ProtocolToString[protocol])
cfg.ListenAddr = fmt.Sprintf("%s:%d", listenHost, listenPort)
listenPort++

server := sentry.NewGrpcServer(backend.sentryCtx, discovery, readNodeInfo, &cfg, protocol)
backend.sentryServers = append(backend.sentryServers, server)
sentries = append(sentries, direct.NewSentryClientDirect(protocol, server))
}

go func() {
logEvery := time.NewTicker(120 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion node/nodecfg/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var DefaultConfig = Config{
WSModules: []string{"net", "web3"},
P2P: p2p.Config{
ListenAddr: ":30303",
ProtocolVersion: 66, // eth/66 by default
ProtocolVersion: []uint{66, 67},
MaxPeers: 100,
MaxPendingPeers: 1000,
NAT: nat.Any(),
Expand Down
2 changes: 1 addition & 1 deletion p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ type Config struct {
ListenAddr string

// eth/66, eth/67, etc
ProtocolVersion uint
ProtocolVersion []uint

SentryAddr []string

Expand Down

0 comments on commit 14c0643

Please sign in to comment.