github.com/prysmaticlabs/prysm@v1.4.4/shared/cmd/config.go (about) 1 package cmd 2 3 import ( 4 "github.com/prysmaticlabs/prysm/shared/params" 5 "github.com/urfave/cli/v2" 6 ) 7 8 // Flags is a struct to represent which features the client will perform on runtime. 9 type Flags struct { 10 // Configuration related flags. 11 MinimalConfig bool // MinimalConfig as defined in the spec. 12 E2EConfig bool // E2EConfig made specifically for testing, do not use except in E2E. 13 MaxRPCPageSize int // MaxRPCPageSize is used for a cap of page sizes in RPC requests. 14 } 15 16 var sharedConfig *Flags 17 18 // Get retrieves feature config. 19 func Get() *Flags { 20 if sharedConfig == nil { 21 return &Flags{ 22 MaxRPCPageSize: params.BeaconConfig().DefaultPageSize, 23 } 24 } 25 return sharedConfig 26 } 27 28 // Init sets the global config equal to the config that is passed in. 29 func Init(c *Flags) { 30 sharedConfig = c 31 } 32 33 // InitWithReset sets the global config and returns function that is used to reset configuration. 34 func InitWithReset(c *Flags) func() { 35 resetFunc := func() { 36 Init(nil) 37 } 38 Init(c) 39 return resetFunc 40 } 41 42 // ConfigureBeaconChain sets the global config based 43 // on what flags are enabled for the beacon-chain client. 44 func ConfigureBeaconChain(ctx *cli.Context) { 45 cfg := newConfig(ctx) 46 if ctx.IsSet(RPCMaxPageSizeFlag.Name) { 47 cfg.MaxRPCPageSize = ctx.Int(RPCMaxPageSizeFlag.Name) 48 log.Warnf("Starting beacon chain with max RPC page size of %d", cfg.MaxRPCPageSize) 49 } 50 Init(cfg) 51 } 52 53 // ConfigureSlasher sets the global config based 54 // on what flags are enabled for the slasher client. 55 func ConfigureSlasher(ctx *cli.Context) { 56 cfg := newConfig(ctx) 57 if ctx.IsSet(RPCMaxPageSizeFlag.Name) { 58 cfg.MaxRPCPageSize = ctx.Int(RPCMaxPageSizeFlag.Name) 59 log.Warnf("Starting slasher with max RPC page size of %d", cfg.MaxRPCPageSize) 60 } 61 Init(cfg) 62 } 63 64 // ConfigureValidator sets the global config based 65 // on what flags are enabled for the validator client. 66 func ConfigureValidator(ctx *cli.Context) { 67 cfg := newConfig(ctx) 68 Init(cfg) 69 } 70 71 func newConfig(ctx *cli.Context) *Flags { 72 cfg := Get() 73 if ctx.Bool(MinimalConfigFlag.Name) { 74 log.Warn("Using minimal config") 75 cfg.MinimalConfig = true 76 params.UseMinimalConfig() 77 } 78 if ctx.Bool(E2EConfigFlag.Name) { 79 log.Warn("Using end-to-end testing config") 80 cfg.MinimalConfig = true 81 params.UseE2EConfig() 82 } 83 return cfg 84 }