mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
588dea83b7
* test coverage and updates to config twiddlers * LoadChainConfigFile error if SetActive conflicts * lint * wip working around test issues * more fixes, mass test updates * lint * linting * thanks deepsource! * fix undeclared vars * fixing more undefined * fix a bug, make a bug, repeat * gaz * use stock mainnet in case fork schedule matters * remove unused KnownConfigs * post-merge cleanup * eliminating OverrideBeaconConfig outside tests * more cleanup of OverrideBeaconConfig outside tests * config for interop w/ genesis gen support * improve var name * API on package instead of exported value * cleanup remainders of "registry" naming * Nishant feedback * add ropstein to configset * lint * lint #2 * ✂️ * revert accidental commented line * check if active is nil (replace called on empty) * Nishant feedback * replace OverrideBeaconConfig call * update interop instructions w/ new flag * don't let interop replace config set via cli flags Co-authored-by: kasey <kasey@users.noreply.github.com>
95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
"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.
|
|
MinimalConfig bool // MinimalConfig as defined in the spec.
|
|
E2EConfig bool // E2EConfig made specifically for testing, do not use except in E2E.
|
|
MaxRPCPageSize int // MaxRPCPageSize is used for a cap of page sizes in RPC requests.
|
|
}
|
|
|
|
var sharedConfig *Flags
|
|
|
|
// Get retrieves feature config.
|
|
func Get() *Flags {
|
|
if sharedConfig == nil {
|
|
return &Flags{
|
|
MaxRPCPageSize: params.BeaconConfig().DefaultPageSize,
|
|
}
|
|
}
|
|
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() {
|
|
Init(nil)
|
|
}
|
|
Init(c)
|
|
return resetFunc
|
|
}
|
|
|
|
// ConfigureBeaconChain sets the global config based
|
|
// on what flags are enabled for the beacon-chain client.
|
|
func ConfigureBeaconChain(ctx *cli.Context) error {
|
|
cfg, err := newConfig(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if ctx.IsSet(RPCMaxPageSizeFlag.Name) {
|
|
cfg.MaxRPCPageSize = ctx.Int(RPCMaxPageSizeFlag.Name)
|
|
log.Warnf("Starting beacon chain with max RPC page size of %d", cfg.MaxRPCPageSize)
|
|
}
|
|
Init(cfg)
|
|
return nil
|
|
}
|
|
|
|
// ConfigureValidator sets the global config based
|
|
// on what flags are enabled for the validator client.
|
|
func ConfigureValidator(ctx *cli.Context) error {
|
|
cfg, err := newConfig(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
Init(cfg)
|
|
return nil
|
|
}
|
|
|
|
func newConfig(ctx *cli.Context) (*Flags, error) {
|
|
cfg := Get()
|
|
if ctx.Bool(MinimalConfigFlag.Name) {
|
|
log.Warn("Using minimal config")
|
|
cfg.MinimalConfig = true
|
|
if err := params.SetActive(params.MinimalSpecConfig().Copy()); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
if ctx.Bool(E2EConfigFlag.Name) {
|
|
log.Warn("Using end-to-end testing config")
|
|
switch fieldparams.Preset {
|
|
case "mainnet":
|
|
if err := params.SetActive(params.E2EMainnetTestConfig().Copy()); err != nil {
|
|
return nil, err
|
|
}
|
|
case "minimal":
|
|
if err := params.SetActive(params.E2ETestConfig().Copy()); err != nil {
|
|
return nil, err
|
|
}
|
|
default:
|
|
log.Fatalf("Unrecognized preset being used: %s", fieldparams.Preset)
|
|
}
|
|
}
|
|
return cfg, nil
|
|
}
|