2019-11-26 07:15:54 +00:00
|
|
|
package flags
|
|
|
|
|
|
|
|
import (
|
2021-09-21 18:11:16 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd"
|
2020-05-31 06:44:34 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-11-26 07:15:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GlobalFlags specifies all the global flags for the
|
|
|
|
// beacon node.
|
|
|
|
type GlobalFlags struct {
|
2020-10-19 20:03:31 +00:00
|
|
|
HeadSync bool
|
2020-09-17 06:11:21 +00:00
|
|
|
DisableSync bool
|
2020-07-01 17:04:06 +00:00
|
|
|
DisableDiscv5 bool
|
2020-11-17 05:25:35 +00:00
|
|
|
SubscribeToAllSubnets bool
|
2022-02-01 08:51:17 +00:00
|
|
|
MinimumSyncPeers int
|
|
|
|
MinimumPeersPerSubnet int
|
|
|
|
BlockBatchLimit int
|
|
|
|
BlockBatchLimitBurstFactor int
|
2019-11-26 07:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var globalConfig *GlobalFlags
|
|
|
|
|
|
|
|
// Get retrieves the global config.
|
|
|
|
func Get() *GlobalFlags {
|
|
|
|
if globalConfig == nil {
|
|
|
|
return &GlobalFlags{}
|
|
|
|
}
|
|
|
|
return globalConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init sets the global config equal to the config that is passed in.
|
|
|
|
func Init(c *GlobalFlags) {
|
|
|
|
globalConfig = c
|
|
|
|
}
|
|
|
|
|
2020-01-16 21:19:43 +00:00
|
|
|
// ConfigureGlobalFlags initializes the global config.
|
2019-11-26 07:15:54 +00:00
|
|
|
// based on the provided cli context.
|
|
|
|
func ConfigureGlobalFlags(ctx *cli.Context) {
|
|
|
|
cfg := &GlobalFlags{}
|
2020-10-19 20:03:31 +00:00
|
|
|
if ctx.Bool(HeadSync.Name) {
|
|
|
|
log.Warn("Using Head Sync flag, it starts syncing from last saved head.")
|
|
|
|
cfg.HeadSync = true
|
2020-02-19 08:25:07 +00:00
|
|
|
}
|
2020-09-17 06:11:21 +00:00
|
|
|
if ctx.Bool(DisableSync.Name) {
|
|
|
|
log.Warn("Using Disable Sync flag, using this flag on a live network might lead to adverse consequences.")
|
|
|
|
cfg.DisableSync = true
|
2020-03-23 14:41:47 +00:00
|
|
|
}
|
2020-11-17 05:25:35 +00:00
|
|
|
if ctx.Bool(SubscribeToAllSubnets.Name) {
|
|
|
|
log.Warn("Subscribing to All Attestation Subnets")
|
|
|
|
cfg.SubscribeToAllSubnets = true
|
|
|
|
}
|
2020-09-17 06:11:21 +00:00
|
|
|
cfg.DisableDiscv5 = ctx.Bool(DisableDiscv5.Name)
|
2022-02-01 08:51:17 +00:00
|
|
|
cfg.BlockBatchLimit = ctx.Int(BlockBatchLimit.Name)
|
|
|
|
cfg.BlockBatchLimitBurstFactor = ctx.Int(BlockBatchLimitBurstFactor.Name)
|
|
|
|
cfg.MinimumPeersPerSubnet = ctx.Int(MinPeersPerSubnet.Name)
|
2019-12-13 15:12:49 +00:00
|
|
|
configureMinimumPeers(ctx, cfg)
|
|
|
|
|
2019-11-26 07:15:54 +00:00
|
|
|
Init(cfg)
|
|
|
|
}
|
2019-12-13 15:12:49 +00:00
|
|
|
|
|
|
|
func configureMinimumPeers(ctx *cli.Context, cfg *GlobalFlags) {
|
2022-02-01 08:51:17 +00:00
|
|
|
cfg.MinimumSyncPeers = ctx.Int(MinSyncPeers.Name)
|
|
|
|
maxPeers := ctx.Int(cmd.P2PMaxPeers.Name)
|
2019-12-13 15:12:49 +00:00
|
|
|
if cfg.MinimumSyncPeers > maxPeers {
|
|
|
|
log.Warnf("Changing Minimum Sync Peers to %d", maxPeers)
|
|
|
|
cfg.MinimumSyncPeers = maxPeers
|
|
|
|
}
|
|
|
|
}
|