erigon-pulse/cmd/sentinel/cli/cliSettings.go

103 lines
4.1 KiB
Go
Raw Normal View History

2022-10-16 17:54:12 +00:00
package cli
import (
"fmt"
2023-05-15 18:07:27 +00:00
"github.com/ledgerwatch/erigon/cl/phase1/core/rawdb"
2023-05-15 18:07:27 +00:00
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
2022-10-16 17:54:12 +00:00
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/urfave/cli/v2"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cmd/sentinel/cli/flags"
2023-05-05 11:16:50 +00:00
"github.com/ledgerwatch/erigon/turbo/logging"
"github.com/ledgerwatch/log/v3"
2022-10-16 17:54:12 +00:00
)
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"`
2023-05-15 18:07:27 +00:00
NetworkType clparams.NetworkType `json:"networkType"`
InitialSync bool `json:"initialSync"`
InitalState *state.BeaconState
2022-10-16 17:54:12 +00:00
}
func SetupConsensusClientCfg(ctx *cli.Context) (*ConsensusClientCliCfg, error) {
cfg := &ConsensusClientCliCfg{}
chainName := ctx.String(flags.Chain.Name)
var err error
cfg.GenesisCfg, cfg.NetworkCfg, cfg.BeaconCfg, cfg.NetworkType, err = clparams.GetConfigsByNetworkName(chainName)
if err != nil {
return nil, err
}
cfg.ErigonPrivateApi = ctx.String(flags.ErigonPrivateApiFlag.Name)
if ctx.String(flags.BeaconConfigFlag.Name) != "" {
cfg.BeaconCfg = new(clparams.BeaconChainConfig)
if *cfg.BeaconCfg, err = clparams.CustomConfig(ctx.String(flags.BeaconConfigFlag.Name)); err != nil {
return nil, err
}
if ctx.String(flags.GenesisSSZFlag.Name) == "" {
return nil, fmt.Errorf("no genesis file provided")
}
cfg.GenesisCfg = new(clparams.GenesisConfig)
2023-05-15 18:07:27 +00:00
var stateByte []byte
// Now parse genesis time and genesis fork
2023-05-15 18:07:27 +00:00
if *cfg.GenesisCfg, stateByte, err = clparams.ParseGenesisSSZToGenesisConfig(
ctx.String(flags.GenesisSSZFlag.Name),
cfg.BeaconCfg.GetCurrentStateVersion(0)); err != nil {
return nil, err
}
cfg.InitalState = state.New(cfg.BeaconCfg)
if cfg.InitalState.DecodeSSZ(stateByte, int(cfg.BeaconCfg.GetCurrentStateVersion(0))); err != nil {
return nil, err
}
}
cfg.ServerAddr = fmt.Sprintf("%s:%d", ctx.String(flags.SentinelServerAddr.Name), ctx.Int(flags.SentinelServerPort.Name))
cfg.ServerProtocol = "tcp"
2022-10-16 17:54:12 +00:00
cfg.Port = uint(ctx.Int(flags.SentinelDiscoveryPort.Name))
cfg.Addr = ctx.String(flags.SentinelDiscoveryAddr.Name)
2022-10-16 17:54:12 +00:00
2023-05-05 11:16:50 +00:00
cfg.LogLvl = ctx.Uint(logging.LogVerbosityFlag.Name)
fmt.Println(cfg.LogLvl)
if cfg.LogLvl == uint(log.LvlInfo) || cfg.LogLvl == 0 {
cfg.LogLvl = uint(log.LvlDebug)
}
cfg.NoDiscovery = ctx.Bool(flags.NoDiscovery.Name)
if ctx.String(flags.CheckpointSyncUrlFlag.Name) != "" {
cfg.CheckpointUri = ctx.String(flags.CheckpointSyncUrlFlag.Name)
} else {
cfg.CheckpointUri = clparams.GetCheckpointSyncEndpoint(cfg.NetworkType)
fmt.Println(cfg.CheckpointUri)
}
2022-11-16 15:19:40 +00:00
cfg.Chaindata = ctx.String(flags.ChaindataFlag.Name)
2023-01-04 02:02:24 +00:00
cfg.BeaconDataCfg = rawdb.BeaconDataConfigurations[ctx.String(flags.BeaconDBModeFlag.Name)]
// Process bootnodes
if ctx.String(flags.BootnodesFlag.Name) != "" {
cfg.NetworkCfg.BootNodes = utils.SplitAndTrim(ctx.String(flags.BootnodesFlag.Name))
}
2023-02-15 17:56:10 +00:00
if ctx.String(flags.SentinelStaticPeersFlag.Name) != "" {
cfg.NetworkCfg.StaticPeers = utils.SplitAndTrim(ctx.String(flags.SentinelStaticPeersFlag.Name))
2023-05-15 18:07:27 +00:00
fmt.Println(cfg.NetworkCfg.StaticPeers)
2023-02-15 17:56:10 +00:00
}
cfg.TransitionChain = ctx.Bool(flags.TransitionChainFlag.Name)
2023-05-15 18:07:27 +00:00
cfg.InitialSync = ctx.Bool(flags.InitSyncFlag.Name)
return cfg, nil
2022-10-16 17:54:12 +00:00
}