diff --git a/cl/clparams/config.go b/cl/clparams/config.go index 8b6625a8a96..0916cd82d70 100644 --- a/cl/clparams/config.go +++ b/cl/clparams/config.go @@ -65,6 +65,7 @@ type CaplinConfig struct { SentinelAddr string SentinelPort uint64 SubscribeAllTopics bool + MaxPeerCount uint64 // Erigon Sync LoopBlockLimit uint64 // Beacon API router configuration diff --git a/cl/sentinel/config.go b/cl/sentinel/config.go index 0728f31ae55..22af4b5bada 100644 --- a/cl/sentinel/config.go +++ b/cl/sentinel/config.go @@ -51,6 +51,7 @@ type SentinelConfig struct { EnableBlocks bool SubscribeAllTopics bool // Capture all topics ActiveIndicies uint64 + MaxPeerCount uint64 } func convertToCryptoPrivkey(privkey *ecdsa.PrivateKey) (crypto.PrivKey, error) { diff --git a/cl/sentinel/peers/peers.go b/cl/sentinel/peers/peers.go index d28f4942907..0cb406071de 100644 --- a/cl/sentinel/peers/peers.go +++ b/cl/sentinel/peers/peers.go @@ -19,7 +19,6 @@ package peers const ( maxBadPeers = 50000 maxPeerRecordSize = 1000 - DefaultMaxPeers = 64 MaxBadResponses = 50 ) diff --git a/cl/sentinel/sentinel.go b/cl/sentinel/sentinel.go index 860621657e1..554b373e615 100644 --- a/cl/sentinel/sentinel.go +++ b/cl/sentinel/sentinel.go @@ -359,7 +359,7 @@ func (s *Sentinel) String() string { func (s *Sentinel) HasTooManyPeers() bool { active, _, _ := s.GetPeersCount() - return active >= peers.DefaultMaxPeers + return active >= int(s.cfg.MaxPeerCount) } func (s *Sentinel) isPeerUsefulForAnySubnet(node *enode.Node) bool { diff --git a/cmd/caplin/caplin1/run.go b/cmd/caplin/caplin1/run.go index 78bb58cb3db..3d02a06de1b 100644 --- a/cmd/caplin/caplin1/run.go +++ b/cmd/caplin/caplin1/run.go @@ -284,6 +284,7 @@ func RunCaplinService(ctx context.Context, engine execution_client.ExecutionEngi TmpDir: dirs.Tmp, EnableBlocks: true, ActiveIndicies: uint64(len(activeIndicies)), + MaxPeerCount: config.MaxPeerCount, }, rcsn, blobStorage, indexDB, &service.ServerConfig{ Network: "tcp", Addr: fmt.Sprintf("%s:%d", config.SentinelAddr, config.SentinelPort), diff --git a/cmd/caplin/caplincli/config.go b/cmd/caplin/caplincli/config.go index 7976b0cef0a..7f6589e17c1 100644 --- a/cmd/caplin/caplincli/config.go +++ b/cmd/caplin/caplincli/config.go @@ -51,6 +51,7 @@ type CaplinCliCfg struct { MevRelayUrl string `json:"mev_relay_url"` CustomConfig string `json:"custom_config"` CustomGenesisState string `json:"custom_genesis_state"` + MaxPeerCount uint64 `json:"max_peer_count"` JwtSecret []byte AllowedMethods []string `json:"allowed_methods"` @@ -73,6 +74,7 @@ func SetupCaplinCli(ctx *cli.Context) (cfg *CaplinCliCfg, err error) { cfg.BeaconApiReadTimeout = time.Duration(ctx.Uint64(caplinflags.BeaconApiReadTimeout.Name)) * time.Second cfg.BeaconApiWriteTimeout = time.Duration(ctx.Uint(caplinflags.BeaconApiWriteTimeout.Name)) * time.Second + cfg.MaxPeerCount = ctx.Uint64(utils.CaplinMaxPeerCount.Name) cfg.BeaconAddr = fmt.Sprintf("%s:%d", ctx.String(caplinflags.BeaconApiAddr.Name), ctx.Int(caplinflags.BeaconApiPort.Name)) cfg.AllowCredentials = ctx.Bool(utils.BeaconApiAllowCredentialsFlag.Name) cfg.AllowedMethods = ctx.StringSlice(utils.BeaconApiAllowMethodsFlag.Name) diff --git a/cmd/caplin/caplinflags/flags.go b/cmd/caplin/caplinflags/flags.go index 022f1d83004..e5c90d68bae 100644 --- a/cmd/caplin/caplinflags/flags.go +++ b/cmd/caplin/caplinflags/flags.go @@ -41,6 +41,7 @@ var CliFlags = []cli.Flag{ &utils.BeaconApiAllowMethodsFlag, &utils.BeaconApiAllowOriginsFlag, &utils.CaplinCheckpointSyncUrlFlag, + &utils.CaplinMaxPeerCount, } var ( diff --git a/cmd/caplin/main.go b/cmd/caplin/main.go index ca94f0a43e2..53316767e0a 100644 --- a/cmd/caplin/main.go +++ b/cmd/caplin/main.go @@ -117,5 +117,6 @@ func runCaplinNode(cliCtx *cli.Context) error { MevRelayUrl: cfg.MevRelayUrl, CustomConfigPath: cfg.CustomConfig, CustomGenesisStatePath: cfg.CustomGenesisState, + MaxPeerCount: cfg.MaxPeerCount, }, cfg.Dirs, nil, nil, nil, blockSnapBuildSema) } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 57eaeb76051..dc3f2e6b032 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -866,6 +866,11 @@ var ( Usage: "Enable caplin validator monitoring metrics", Value: false, } + CaplinMaxPeerCount = cli.Uint64Flag{ + Name: "caplin.max-peer-count", + Usage: "Max number of peers to connect", + Value: 128, + } SentinelAddrFlag = cli.StringFlag{ Name: "sentinel.addr", @@ -1800,6 +1805,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C cfg.CaplinConfig.CaplinDiscoveryPort = ctx.Uint64(CaplinDiscoveryPortFlag.Name) cfg.CaplinConfig.CaplinDiscoveryTCPPort = ctx.Uint64(CaplinDiscoveryTCPPortFlag.Name) cfg.CaplinConfig.SubscribeAllTopics = ctx.Bool(CaplinSubscribeAllTopicsFlag.Name) + cfg.CaplinConfig.MaxPeerCount = ctx.Uint64(CaplinMaxPeerCount.Name) cfg.CaplinConfig.SentinelAddr = ctx.String(SentinelAddrFlag.Name) cfg.CaplinConfig.SentinelPort = ctx.Uint64(SentinelPortFlag.Name) diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index 74209d0898d..5c502220019 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -183,6 +183,7 @@ var DefaultFlags = []cli.Flag{ &utils.CaplinDiscoveryTCPPortFlag, &utils.CaplinCheckpointSyncUrlFlag, &utils.CaplinSubscribeAllTopicsFlag, + &utils.CaplinMaxPeerCount, &utils.SentinelAddrFlag, &utils.SentinelPortFlag, &utils.SentinelBootnodes,