mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
a335bbbb61
* add new flag * terence's review
63 lines
1.7 KiB
Go
63 lines
1.7 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
|
|
DisableSync 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) {
|
|
log.Warn("Using Unsafe Sync flag, it is insecure to use this flag with your beacon node.")
|
|
cfg.UnsafeSync = true
|
|
}
|
|
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
|
|
}
|
|
cfg.DisableDiscv5 = ctx.Bool(DisableDiscv5.Name)
|
|
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
|
|
}
|
|
}
|