[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
This commit is contained in:
Enrique Jose Avila Asapche 2023-06-11 18:34:33 +01:00 committed by GitHub
parent eac9ead6fe
commit e380ee4bdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 29 deletions

View File

@ -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 {

View File

@ -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)

View File

@ -7,6 +7,9 @@ var CLDefaultFlags = []cli.Flag{
&SentinelDiscoveryAddr,
&SentinelServerPort,
&SentinelServerAddr,
&NoBeaconApi,
&BeaconApiReadTimeout,
&BeaconApiWriteTimeout,
&BeaconApiPort,
&BeaconApiAddr,
&Chain,

View File

@ -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",