Skip to content

Commit

Permalink
add max peer count as cli parameter (#12311)
Browse files Browse the repository at this point in the history
Co-authored-by: shota.silagadze <[email protected]>
  • Loading branch information
shotasilagadze and shotasilagadzetaal authored Oct 14, 2024
1 parent 78b895b commit 586af3d
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type CaplinConfig struct {
SentinelAddr string
SentinelPort uint64
SubscribeAllTopics bool
MaxPeerCount uint64
// Erigon Sync
LoopBlockLimit uint64
// Beacon API router configuration
Expand Down
1 change: 1 addition & 0 deletions cl/sentinel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion cl/sentinel/peers/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package peers
const (
maxBadPeers = 50000
maxPeerRecordSize = 1000
DefaultMaxPeers = 64
MaxBadResponses = 50
)

Expand Down
2 changes: 1 addition & 1 deletion cl/sentinel/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd/caplin/caplin1/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions cmd/caplin/caplincli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/caplin/caplinflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var CliFlags = []cli.Flag{
&utils.BeaconApiAllowMethodsFlag,
&utils.BeaconApiAllowOriginsFlag,
&utils.CaplinCheckpointSyncUrlFlag,
&utils.CaplinMaxPeerCount,
}

var (
Expand Down
1 change: 1 addition & 0 deletions cmd/caplin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ var DefaultFlags = []cli.Flag{
&utils.CaplinDiscoveryTCPPortFlag,
&utils.CaplinCheckpointSyncUrlFlag,
&utils.CaplinSubscribeAllTopicsFlag,
&utils.CaplinMaxPeerCount,
&utils.SentinelAddrFlag,
&utils.SentinelPortFlag,
&utils.SentinelBootnodes,
Expand Down

0 comments on commit 586af3d

Please sign in to comment.