From e380ee4bdde066c4fe3ca2621dbaeaed0fcf557b Mon Sep 17 00:00:00 2001 From: Enrique Jose Avila Asapche Date: Sun, 11 Jun 2023 18:34:33 +0100 Subject: [PATCH] [Caplin] added configurations for beacon api (#7699) Now you can configure: Read timeout (default: 5s) Write timeout (default: 5s) On/off (default: ON) Port (default:5555) Address (default:localhost) Protocol (default: tcp) #7684 --- cmd/caplin-phase1/main.go | 18 ++++++---- cmd/sentinel/cli/cliSettings.go | 49 +++++++++++++++----------- cmd/sentinel/cli/flags/defaultFlags.go | 3 ++ cmd/sentinel/cli/flags/flags.go | 19 +++++++++- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/cmd/caplin-phase1/main.go b/cmd/caplin-phase1/main.go index 88be1c4f3..ce45304c4 100644 --- a/cmd/caplin-phase1/main.go +++ b/cmd/caplin-phase1/main.go @@ -115,13 +115,17 @@ func runCaplinNode(cliCtx *cli.Context) error { engine = execution_client.NewExecutionEnginePhase1FromClient(ctx, remote.NewETHBACKENDClient(cc)) } - apiHandler := handler.NewApiHandler(cfg.GenesisCfg, cfg.BeaconCfg) - go beacon.ListenAndServe(apiHandler, &beacon.RouterConfiguration{ - Protocol: cfg.BeaconProtocol, - Address: cfg.BeaconAddr, - // TODO(enriavil1): Make timeouts configurable via flags - }) - log.Info("Beacon API started", "addr", cfg.BeaconAddr) + if !cfg.NoBeaconApi { + apiHandler := handler.NewApiHandler(cfg.GenesisCfg, cfg.BeaconCfg) + go beacon.ListenAndServe(apiHandler, &beacon.RouterConfiguration{ + Protocol: cfg.BeaconProtocol, + Address: cfg.BeaconAddr, + ReadTimeTimeout: cfg.BeaconApiReadTimeout, + WriteTimeout: cfg.BeaconApiWriteTimeout, + IdleTimeout: cfg.BeaconApiWriteTimeout, + }) + log.Info("Beacon API started", "addr", cfg.BeaconAddr) + } var caplinFreezer freezer.Freezer if cfg.RecordMode { diff --git a/cmd/sentinel/cli/cliSettings.go b/cmd/sentinel/cli/cliSettings.go index 5763008f3..4aeff652e 100644 --- a/cmd/sentinel/cli/cliSettings.go +++ b/cmd/sentinel/cli/cliSettings.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "time" "github.com/ledgerwatch/erigon/cl/phase1/core/rawdb" "github.com/ledgerwatch/erigon/cl/phase1/core/state" @@ -17,27 +18,30 @@ import ( ) type ConsensusClientCliCfg struct { - GenesisCfg *clparams.GenesisConfig `json:"genesisCfg"` - BeaconCfg *clparams.BeaconChainConfig `json:"beaconCfg"` - NetworkCfg *clparams.NetworkConfig `json:"networkCfg"` - BeaconDataCfg *rawdb.BeaconDataConfig `json:"beaconDataConfig"` - Port uint `json:"port"` - Addr string `json:"address"` - ServerAddr string `json:"serverAddr"` - ServerProtocol string `json:"serverProtocol"` - ServerTcpPort uint `json:"serverTcpPort"` - LogLvl uint `json:"logLevel"` - NoDiscovery bool `json:"noDiscovery"` - CheckpointUri string `json:"checkpointUri"` - Chaindata string `json:"chaindata"` - ErigonPrivateApi string `json:"erigonPrivateApi"` - TransitionChain bool `json:"transitionChain"` - NetworkType clparams.NetworkType `json:"networkType"` - InitialSync bool `json:"initialSync"` - BeaconAddr string `json:"beaconAddr"` - BeaconProtocol string `json:"beaconProtocol"` - RecordMode bool `json:"recordMode"` - RecordDir string `json:"recordDir"` + GenesisCfg *clparams.GenesisConfig `json:"genesisCfg"` + BeaconCfg *clparams.BeaconChainConfig `json:"beaconCfg"` + NetworkCfg *clparams.NetworkConfig `json:"networkCfg"` + BeaconDataCfg *rawdb.BeaconDataConfig `json:"beaconDataConfig"` + Port uint `json:"port"` + Addr string `json:"address"` + ServerAddr string `json:"serverAddr"` + ServerProtocol string `json:"serverProtocol"` + ServerTcpPort uint `json:"serverTcpPort"` + LogLvl uint `json:"logLevel"` + NoDiscovery bool `json:"noDiscovery"` + CheckpointUri string `json:"checkpointUri"` + Chaindata string `json:"chaindata"` + ErigonPrivateApi string `json:"erigonPrivateApi"` + TransitionChain bool `json:"transitionChain"` + NetworkType clparams.NetworkType `json:"networkType"` + InitialSync bool `json:"initialSync"` + NoBeaconApi bool `json:"noBeaconApi"` + BeaconApiReadTimeout time.Duration `json:"beaconApiReadTimeout"` + BeaconApiWriteTimeout time.Duration `json:"beaconApiWriteTimeout"` + BeaconAddr string `json:"beaconAddr"` + BeaconProtocol string `json:"beaconProtocol"` + RecordMode bool `json:"recordMode"` + RecordDir string `json:"recordDir"` InitalState *state.BeaconState } @@ -75,6 +79,9 @@ func SetupConsensusClientCfg(ctx *cli.Context) (*ConsensusClientCliCfg, error) { cfg.ServerAddr = fmt.Sprintf("%s:%d", ctx.String(flags.SentinelServerAddr.Name), ctx.Int(flags.SentinelServerPort.Name)) cfg.ServerProtocol = "tcp" + cfg.NoBeaconApi = ctx.Bool(flags.NoBeaconApi.Name) + cfg.BeaconApiReadTimeout = time.Duration(ctx.Uint64(flags.BeaconApiReadTimeout.Name)) * time.Second + cfg.BeaconApiWriteTimeout = time.Duration(ctx.Uint(flags.BeaconApiWriteTimeout.Name)) * time.Second cfg.BeaconAddr = fmt.Sprintf("%s:%d", ctx.String(flags.BeaconApiAddr.Name), ctx.Int(flags.BeaconApiPort.Name)) cfg.BeaconProtocol = "tcp" cfg.RecordMode = ctx.Bool(flags.RecordModeFlag.Name) diff --git a/cmd/sentinel/cli/flags/defaultFlags.go b/cmd/sentinel/cli/flags/defaultFlags.go index 47bd69075..d9e8831b3 100644 --- a/cmd/sentinel/cli/flags/defaultFlags.go +++ b/cmd/sentinel/cli/flags/defaultFlags.go @@ -7,6 +7,9 @@ var CLDefaultFlags = []cli.Flag{ &SentinelDiscoveryAddr, &SentinelServerPort, &SentinelServerAddr, + &NoBeaconApi, + &BeaconApiReadTimeout, + &BeaconApiWriteTimeout, &BeaconApiPort, &BeaconApiAddr, &Chain, diff --git a/cmd/sentinel/cli/flags/flags.go b/cmd/sentinel/cli/flags/flags.go index d8ac288f1..a71663d61 100644 --- a/cmd/sentinel/cli/flags/flags.go +++ b/cmd/sentinel/cli/flags/flags.go @@ -1,6 +1,8 @@ package flags -import "github.com/urfave/cli/v2" +import ( + "github.com/urfave/cli/v2" +) var ( SentinelDiscoveryPort = cli.IntFlag{ @@ -28,6 +30,21 @@ var ( Usage: "sets the lightclient server host addr", Value: "localhost", } + NoBeaconApi = cli.BoolFlag{ + Name: "no-beacon-api", + Usage: "turn off the beacon api", + Value: false, + } + BeaconApiReadTimeout = cli.Uint64Flag{ + Name: "beacon.api.read.timeout", + Usage: "Sets the seconds for a read time out in the beacon api", + Value: 5, + } + BeaconApiWriteTimeout = cli.Uint64Flag{ + Name: "beacon.api.write.timeout", + Usage: "Sets the seconds for a write time out in the beacon api", + Value: 5, + } BeaconApiAddr = cli.StringFlag{ Name: "beacon.api.addr", Usage: "sets the host to listen for beacon api requests",