prysm-pulse/beacon-chain/flags/config.go
Preston Van Loon a279f18461
Change from int64 to int for all flags so they load properly from config file. (#6498)
* Change from int64 to int for monitoring port so that the monitoring port is correctly ready from config file.
* Merge branch 'master' into fix-monitoring-port
* Merge branch 'master' into fix-monitoring-port
* Merge branch 'master' into fix-monitoring-port
* replace all other usages of int64 flag. @nisdas feedback
* Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-monitoring-port
* Merge branch 'master' into fix-monitoring-port
* Merge branch 'master' into fix-monitoring-port
* Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-monitoring-port
* revert tools/sendDepositTx
* fix build
* Merge branch 'master' into fix-monitoring-port
* Merge branch 'master' into fix-monitoring-port
* Merge branch 'master' into fix-monitoring-port
2020-07-08 08:21:06 +00:00

59 lines
1.4 KiB
Go

package flags
import (
"github.com/prysmaticlabs/prysm/shared/cmd"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
// GlobalFlags specifies all the global flags for the
// beacon node.
type GlobalFlags struct {
UnsafeSync bool
DisableDiscv5 bool
MinimumSyncPeers int
BlockBatchLimit int
BlockBatchLimitBurstFactor int
}
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
}
// ConfigureGlobalFlags initializes the global config.
// based on the provided cli context.
func ConfigureGlobalFlags(ctx *cli.Context) {
cfg := &GlobalFlags{}
if ctx.Bool(UnsafeSync.Name) {
cfg.UnsafeSync = true
}
if ctx.Bool(DisableDiscv5.Name) {
cfg.DisableDiscv5 = true
}
cfg.BlockBatchLimit = ctx.Int(BlockBatchLimit.Name)
cfg.BlockBatchLimitBurstFactor = ctx.Int(BlockBatchLimitBurstFactor.Name)
configureMinimumPeers(ctx, cfg)
Init(cfg)
}
func configureMinimumPeers(ctx *cli.Context, cfg *GlobalFlags) {
cfg.MinimumSyncPeers = ctx.Int(MinSyncPeers.Name)
maxPeers := int(ctx.Int(cmd.P2PMaxPeers.Name))
if cfg.MinimumSyncPeers > maxPeers {
log.Warnf("Changing Minimum Sync Peers to %d", maxPeers)
cfg.MinimumSyncPeers = maxPeers
}
}