2020-06-23 15:41:20 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-03-17 18:52:56 +00:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
2020-06-23 15:41:20 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Flags is a struct to represent which features the client will perform on runtime.
|
|
|
|
type Flags struct {
|
|
|
|
// Configuration related flags.
|
2020-08-01 16:11:36 +00:00
|
|
|
MinimalConfig bool // MinimalConfig as defined in the spec.
|
2021-01-05 13:09:41 +00:00
|
|
|
MaxRPCPageSize int // MaxRPCPageSize is used for a cap of page sizes in RPC requests.
|
2020-06-23 15:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var sharedConfig *Flags
|
|
|
|
|
|
|
|
// Get retrieves feature config.
|
|
|
|
func Get() *Flags {
|
|
|
|
if sharedConfig == nil {
|
2020-06-29 14:17:24 +00:00
|
|
|
return &Flags{
|
|
|
|
MaxRPCPageSize: params.BeaconConfig().DefaultPageSize,
|
|
|
|
}
|
2020-06-23 15:41:20 +00:00
|
|
|
}
|
|
|
|
return sharedConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init sets the global config equal to the config that is passed in.
|
|
|
|
func Init(c *Flags) {
|
|
|
|
sharedConfig = c
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitWithReset sets the global config and returns function that is used to reset configuration.
|
|
|
|
func InitWithReset(c *Flags) func() {
|
|
|
|
resetFunc := func() {
|
2020-08-02 22:09:10 +00:00
|
|
|
Init(nil)
|
2020-06-23 15:41:20 +00:00
|
|
|
}
|
|
|
|
Init(c)
|
|
|
|
return resetFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigureBeaconChain sets the global config based
|
|
|
|
// on what flags are enabled for the beacon-chain client.
|
2022-05-20 07:16:53 +00:00
|
|
|
func ConfigureBeaconChain(ctx *cli.Context) error {
|
|
|
|
cfg, err := newConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-29 14:17:24 +00:00
|
|
|
if ctx.IsSet(RPCMaxPageSizeFlag.Name) {
|
2020-08-02 22:09:10 +00:00
|
|
|
cfg.MaxRPCPageSize = ctx.Int(RPCMaxPageSizeFlag.Name)
|
|
|
|
log.Warnf("Starting beacon chain with max RPC page size of %d", cfg.MaxRPCPageSize)
|
2020-06-29 14:17:24 +00:00
|
|
|
}
|
2020-06-23 15:41:20 +00:00
|
|
|
Init(cfg)
|
2022-05-20 07:16:53 +00:00
|
|
|
return nil
|
2020-06-23 15:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigureValidator sets the global config based
|
|
|
|
// on what flags are enabled for the validator client.
|
2022-05-20 07:16:53 +00:00
|
|
|
func ConfigureValidator(ctx *cli.Context) error {
|
|
|
|
cfg, err := newConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-23 15:41:20 +00:00
|
|
|
Init(cfg)
|
2022-05-20 07:16:53 +00:00
|
|
|
return nil
|
2020-06-23 15:41:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 07:16:53 +00:00
|
|
|
func newConfig(ctx *cli.Context) (*Flags, error) {
|
2020-08-02 22:09:10 +00:00
|
|
|
cfg := Get()
|
2020-06-23 15:41:20 +00:00
|
|
|
if ctx.Bool(MinimalConfigFlag.Name) {
|
|
|
|
log.Warn("Using minimal config")
|
|
|
|
cfg.MinimalConfig = true
|
2022-05-20 07:16:53 +00:00
|
|
|
if err := params.SetActive(params.MinimalSpecConfig().Copy()); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-23 15:41:20 +00:00
|
|
|
}
|
|
|
|
if ctx.Bool(E2EConfigFlag.Name) {
|
|
|
|
log.Warn("Using end-to-end testing config")
|
2022-02-02 19:13:52 +00:00
|
|
|
switch fieldparams.Preset {
|
|
|
|
case "mainnet":
|
2022-05-20 07:16:53 +00:00
|
|
|
if err := params.SetActive(params.E2EMainnetTestConfig().Copy()); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-02-02 19:13:52 +00:00
|
|
|
case "minimal":
|
2022-05-20 07:16:53 +00:00
|
|
|
if err := params.SetActive(params.E2ETestConfig().Copy()); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-02-02 19:13:52 +00:00
|
|
|
default:
|
|
|
|
log.Fatalf("Unrecognized preset being used: %s", fieldparams.Preset)
|
|
|
|
}
|
2020-06-23 15:41:20 +00:00
|
|
|
}
|
2022-05-20 07:16:53 +00:00
|
|
|
return cfg, nil
|
2020-06-23 15:41:20 +00:00
|
|
|
}
|