[cmd] move all flags to flags.go - one file

pull/3278/head
Jacky Wang 4 years ago
parent 9dabfd24ad
commit b150aed312
No known key found for this signature in database
GPG Key ID: 1085CE5F4FF5842C
  1. 52
      cmd/harmony/bls.go
  2. 285
      cmd/harmony/bls_flag.go
  3. 955
      cmd/harmony/flags.go
  4. 486
      cmd/harmony/general_flag.go
  5. 230
      cmd/harmony/network_flag.go

@ -0,0 +1,52 @@
package main
import (
"sync"
"github.com/harmony-one/harmony/multibls"
)
var (
multiBLSPriKey multibls.PrivateKeys
onceLoadBLSKey sync.Once
)
//// TODO: refactor this
//func loadBLSKeys() (multibls.PrivateKeys, error) {
// config, err := parseBLSLoadingConfig()
// if err != nil {
// return nil, err
// }
// keys, err := blsgen.LoadKeys(config)
// if err != nil {
// return nil, err
// }
// if len(keys) == 0 {
// return nil, fmt.Errorf("0 bls keys loaded")
// }
// if len(keys) >= *maxBLSKeysPerNode {
// return nil, fmt.Errorf("bls keys exceed maximum count %v", *maxBLSKeysPerNode)
// }
// return keys, err
//}
//
//func parseBLSLoadingConfig() (blsgen.Config, error) {
// var (
// config blsgen.Config
// err error
// )
// if len(*blsKeyFile) != 0 {
// config.MultiBlsKeys = strings.Split(*blsKeyFile, ",")
// }
// config.BlsDir = blsFolder
//
// config, err = parseBLSPass(config, *blsPass)
// if err != nil {
// return blsgen.Config{}, err
// }
// config, err = parseAwsConfigSrc(config, *awsConfigSource)
// if err != nil {
// return blsgen.Config{}, err
// }
// return config, nil
//}

@ -1,285 +0,0 @@
package main
import (
"strings"
"sync"
"github.com/harmony-one/harmony/internal/cli"
"github.com/harmony-one/harmony/multibls"
"github.com/spf13/cobra"
)
var (
multiBLSPriKey multibls.PrivateKeys
onceLoadBLSKey sync.Once
)
var blsFlags = []cli.Flag{
blsDirFlag,
blsKeyFilesFlag,
maxBLSKeyFilesFlag,
passEnabledFlag,
passSrcTypeFlag,
passSrcFileFlag,
passSaveFlag,
kmsEnabledFlag,
kmsConfigSrcTypeFlag,
kmsConfigFileFlag,
}
var legacyBLSFlags = []cli.Flag{
legacyBLSKeyFileFlag,
legacyBLSFolderFlag,
legacyBLSKeysPerNodeFlag,
legacyBLSPassFlag,
legacyBLSPersistPassFlag,
legacyKMSConfigSourceFlag,
}
var (
blsDirFlag = cli.StringFlag{
Name: "bls.dir",
Usage: "directory for BLS keys",
DefValue: defaultConfig.BLSKeys.KeyDir,
}
blsKeyFilesFlag = cli.StringSliceFlag{
Name: "bls.keys",
Usage: "a list of BLS key files (separated by ,)",
DefValue: defaultConfig.BLSKeys.KeyFiles,
}
// TODO: shall we move this to a hard coded parameter?
maxBLSKeyFilesFlag = cli.IntFlag{
Name: "bls.maxkeys",
Usage: "maximum number of BLS keys for a node",
DefValue: defaultConfig.BLSKeys.MaxKeys,
Hidden: true,
}
passEnabledFlag = cli.BoolFlag{
Name: "bls.pass",
Usage: "whether BLS key decryption with passphrase is enabled",
DefValue: defaultConfig.BLSKeys.PassEnabled,
}
passSrcTypeFlag = cli.StringFlag{
Name: "bls.pass.src",
Usage: "source for BLS passphrase (auto, file, prompt)",
DefValue: defaultConfig.BLSKeys.PassSrcType,
}
passSrcFileFlag = cli.StringFlag{
Name: "bls.pass.file",
Usage: "the pass file used for BLS decryption. If specified, this pass file will be used for all BLS keys",
DefValue: defaultConfig.BLSKeys.PassFile,
}
passSaveFlag = cli.BoolFlag{
Name: "bls.pass.save",
Usage: "after input the BLS passphrase from console, whether to persist the input passphrases in .pass file",
DefValue: defaultConfig.BLSKeys.SavePassphrase,
}
kmsEnabledFlag = cli.BoolFlag{
Name: "bls.kms",
Usage: "whether BLS key decryption with AWS KMS service is enabled",
DefValue: defaultConfig.BLSKeys.KMSEnabled,
}
kmsConfigSrcTypeFlag = cli.StringFlag{
Name: "bls.kms.src",
Usage: "the AWS config source (region and credentials) for KMS service (shared, prompt, file)",
DefValue: defaultConfig.BLSKeys.KMSConfigSrcType,
}
kmsConfigFileFlag = cli.StringFlag{
Name: "bls.kms.config",
Usage: "json config file for KMS service (region and credentials)",
DefValue: defaultConfig.BLSKeys.KMSConfigFile,
}
legacyBLSKeyFileFlag = cli.StringSliceFlag{
Name: "blskey_file",
Usage: "The encrypted file of bls serialized private key by passphrase.",
DefValue: defaultConfig.BLSKeys.KeyFiles,
Deprecated: "use --bls.keys",
}
legacyBLSFolderFlag = cli.StringFlag{
Name: "blsfolder",
Usage: "The folder that stores the bls keys and corresponding passphrases; e.g. <blskey>.key and <blskey>.pass; all bls keys mapped to same shard",
DefValue: defaultConfig.BLSKeys.KeyDir,
Deprecated: "use --bls.dir",
}
legacyBLSKeysPerNodeFlag = cli.IntFlag{
Name: "max_bls_keys_per_node",
Usage: "Maximum number of bls keys allowed per node",
DefValue: defaultConfig.BLSKeys.MaxKeys,
Deprecated: "use --bls.maxkeys",
}
legacyBLSPassFlag = cli.StringFlag{
Name: "blspass",
Usage: "The source for bls passphrases. (default, stdin, no-prompt, prompt, file:$PASS_FILE, none)",
DefValue: "default",
Deprecated: "use --bls.pass, --bls.pass.src, --bls.pass.file",
}
legacyBLSPersistPassFlag = cli.BoolFlag{
Name: "save-passphrase",
Usage: "Whether the prompt passphrase is saved after prompt.",
DefValue: defaultConfig.BLSKeys.SavePassphrase,
Deprecated: "use --bls.pass.save",
}
legacyKMSConfigSourceFlag = cli.StringFlag{
Name: "aws-config-source",
Usage: "The source for aws config. (default, prompt, file:$CONFIG_FILE, none)",
DefValue: "default",
Deprecated: "use --bls.kms, --bls.kms.src, --bls.kms.config",
}
)
func applyBLSFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, blsDirFlag) {
config.BLSKeys.KeyDir = cli.GetStringFlagValue(cmd, blsDirFlag)
} else if cli.IsFlagChanged(cmd, legacyBLSFolderFlag) {
config.BLSKeys.KeyDir = cli.GetStringFlagValue(cmd, legacyBLSFolderFlag)
}
if cli.IsFlagChanged(cmd, blsKeyFilesFlag) {
config.BLSKeys.KeyFiles = cli.GetStringSliceFlagValue(cmd, blsKeyFilesFlag)
} else if cli.IsFlagChanged(cmd, legacyBLSKeyFileFlag) {
config.BLSKeys.KeyFiles = cli.GetStringSliceFlagValue(cmd, legacyBLSKeyFileFlag)
}
if cli.IsFlagChanged(cmd, maxBLSKeyFilesFlag) {
config.BLSKeys.MaxKeys = cli.GetIntFlagValue(cmd, maxBLSKeyFilesFlag)
} else if cli.IsFlagChanged(cmd, legacyBLSKeysPerNodeFlag) {
config.BLSKeys.MaxKeys = cli.GetIntFlagValue(cmd, legacyBLSKeysPerNodeFlag)
}
if cli.HasFlagsChanged(cmd, blsFlags) {
applyBLSPassFlags(cmd, config)
applyKMSFlags(cmd, config)
} else if cli.HasFlagsChanged(cmd, legacyBLSFlags) {
applyLegacyBLSPassFlags(cmd, config)
applyLegacyKMSFlags(cmd, config)
}
}
func applyBLSPassFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, passEnabledFlag) {
config.BLSKeys.PassEnabled = cli.GetBoolFlagValue(cmd, passEnabledFlag)
}
if cli.IsFlagChanged(cmd, passSrcTypeFlag) {
config.BLSKeys.PassSrcType = cli.GetStringFlagValue(cmd, passSrcTypeFlag)
}
if cli.IsFlagChanged(cmd, passSrcFileFlag) {
config.BLSKeys.PassFile = cli.GetStringFlagValue(cmd, passSrcFileFlag)
}
if cli.IsFlagChanged(cmd, passSaveFlag) {
config.BLSKeys.SavePassphrase = cli.GetBoolFlagValue(cmd, passSaveFlag)
}
}
func applyKMSFlags(cmd *cobra.Command, config *hmyConfig) {
var fileSpecified bool
if cli.IsFlagChanged(cmd, kmsEnabledFlag) {
config.BLSKeys.KMSEnabled = cli.GetBoolFlagValue(cmd, kmsEnabledFlag)
}
if cli.IsFlagChanged(cmd, kmsConfigFileFlag) {
config.BLSKeys.KMSConfigFile = cli.GetStringFlagValue(cmd, kmsConfigFileFlag)
fileSpecified = true
}
if cli.IsFlagChanged(cmd, kmsConfigSrcTypeFlag) {
config.BLSKeys.KMSConfigSrcType = cli.GetStringFlagValue(cmd, kmsConfigSrcTypeFlag)
} else if fileSpecified {
config.BLSKeys.KMSConfigSrcType = blsPassTypeFile
}
}
func applyLegacyBLSPassFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, legacyBLSPassFlag) {
val := cli.GetStringFlagValue(cmd, legacyBLSPassFlag)
legacyApplyBLSPassVal(val, config)
}
if cli.IsFlagChanged(cmd, legacyBLSPersistPassFlag) {
config.BLSKeys.SavePassphrase = cli.GetBoolFlagValue(cmd, legacyBLSPersistPassFlag)
}
}
func applyLegacyKMSFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, legacyKMSConfigSourceFlag) {
val := cli.GetStringFlagValue(cmd, legacyKMSConfigSourceFlag)
legacyApplyKMSSourceVal(val, config)
}
}
func legacyApplyBLSPassVal(src string, config *hmyConfig) {
methodArgs := strings.SplitN(src, ":", 2)
method := methodArgs[0]
switch method {
case legacyBLSPassTypeDefault, legacyBLSPassTypeStdin:
config.BLSKeys.PassSrcType = blsPassTypeAuto
case legacyBLSPassTypeStatic:
config.BLSKeys.PassSrcType = blsPassTypeFile
if len(methodArgs) >= 2 {
config.BLSKeys.PassFile = methodArgs[1]
}
case legacyBLSPassTypeDynamic:
config.BLSKeys.PassSrcType = blsPassTypePrompt
case legacyBLSPassTypePrompt:
config.BLSKeys.PassSrcType = blsPassTypePrompt
case legacyBLSPassTypeNone:
config.BLSKeys.PassEnabled = false
}
}
func legacyApplyKMSSourceVal(src string, config *hmyConfig) {
methodArgs := strings.SplitN(src, ":", 2)
method := methodArgs[0]
switch method {
case legacyBLSKmsTypeDefault:
config.BLSKeys.KMSConfigSrcType = kmsConfigTypeShared
case legacyBLSKmsTypePrompt:
config.BLSKeys.KMSConfigSrcType = kmsConfigTypePrompt
case legacyBLSKmsTypeFile:
config.BLSKeys.KMSConfigSrcType = kmsConfigTypeFile
if len(methodArgs) >= 2 {
config.BLSKeys.KMSConfigFile = methodArgs[1]
}
case legacyBLSKmsTypeNone:
config.BLSKeys.KMSEnabled = false
}
}
//// TODO: refactor this
//func loadBLSKeys() (multibls.PrivateKeys, error) {
// config, err := parseBLSLoadingConfig()
// if err != nil {
// return nil, err
// }
// keys, err := blsgen.LoadKeys(config)
// if err != nil {
// return nil, err
// }
// if len(keys) == 0 {
// return nil, fmt.Errorf("0 bls keys loaded")
// }
// if len(keys) >= *maxBLSKeysPerNode {
// return nil, fmt.Errorf("bls keys exceed maximum count %v", *maxBLSKeysPerNode)
// }
// return keys, err
//}
//
//func parseBLSLoadingConfig() (blsgen.Config, error) {
// var (
// config blsgen.Config
// err error
// )
// if len(*blsKeyFile) != 0 {
// config.MultiBlsKeys = strings.Split(*blsKeyFile, ",")
// }
// config.BlsDir = blsFolder
//
// config, err = parseBLSPass(config, *blsPass)
// if err != nil {
// return blsgen.Config{}, err
// }
// config, err = parseAwsConfigSrc(config, *awsConfigSource)
// if err != nil {
// return blsgen.Config{}, err
// }
// return config, nil
//}

@ -0,0 +1,955 @@
package main
import (
"fmt"
"strings"
"github.com/harmony-one/harmony/internal/cli"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/spf13/cobra"
)
var (
generalFlags = []cli.Flag{
nodeTypeFlag,
isStakingFlag,
shardIDFlag,
isArchiveFlag,
dataDirFlag,
legacyNodeTypeFlag,
legacyIsStakingFlag,
legacyShardIDFlag,
legacyIsArchiveFlag,
legacyDataDirFlag,
}
networkFlags = []cli.Flag{
networkTypeFlag,
bootNodeFlag,
dnsZoneFlag,
dnsPortFlag,
legacyDNSZoneFlag,
legacyDNSPortFlag,
legacyDNSFlag,
legacyNetworkTypeFlag,
}
p2pFlags = []cli.Flag{
p2pPortFlag,
p2pKeyFileFlag,
legacyKeyFileFlag,
}
rpcFlags = []cli.Flag{
rpcEnabledFlag,
rpcIPFlag,
rpcPortFlag,
legacyRPCIPFlag,
legacyPublicRPCFlag,
}
blsFlags = append(newBLSFlags, legacyBLSFlags...)
newBLSFlags = []cli.Flag{
blsDirFlag,
blsKeyFilesFlag,
maxBLSKeyFilesFlag,
passEnabledFlag,
passSrcTypeFlag,
passSrcFileFlag,
passSaveFlag,
kmsEnabledFlag,
kmsConfigSrcTypeFlag,
kmsConfigFileFlag,
}
legacyBLSFlags = []cli.Flag{
legacyBLSKeyFileFlag,
legacyBLSFolderFlag,
legacyBLSKeysPerNodeFlag,
legacyBLSPassFlag,
legacyBLSPersistPassFlag,
legacyKMSConfigSourceFlag,
}
consensusFlags = []cli.Flag{
consensusDelayCommitFlag,
consensusBlockTimeFlag,
legacyDelayCommitFlag,
legacyBlockTimeFlag,
}
txPoolFlags = []cli.Flag{
tpBlacklistFileFlag,
tpBroadcastInvalidTxFlag,
legacyTPBlacklistFileFlag,
legacyTPBroadcastInvalidTxFlag,
}
pprofFlags = []cli.Flag{
pprofEnabledFlag,
pprofListenAddrFlag,
}
logFlags = []cli.Flag{
logFolderFlag,
logRotateSizeFlag,
legacyLogFolderFlag,
legacyLogRotateSizeFlag,
}
devnetFlags = append(newDevnetFlags, legacyDevnetFlags...)
newDevnetFlags = []cli.Flag{
devnetNumShardsFlag,
devnetShardSizeFlag,
devnetHmyNodeSizeFlag,
}
legacyDevnetFlags = []cli.Flag{
legacyDevnetNumShardsFlag,
legacyDevnetShardSizeFlag,
legacyDevnetHmyNodeSizeFlag,
}
revertFlags = append(newRevertFlags, legacyRevertFlags...)
newRevertFlags = []cli.Flag{
revertBeaconFlag,
revertToFlag,
revertBeforeFlag,
}
legacyRevertFlags = []cli.Flag{
legacyRevertBeaconFlag,
legacyRevertBeforeFlag,
legacyRevertToFlag,
}
// legacyMiscFlags are legacy flags that cannot be categorized to a single category.
legacyMiscFlags = []cli.Flag{
legacyPortFlag,
legacyFreshDB,
}
)
var (
nodeTypeFlag = cli.StringFlag{
Name: "run",
Usage: "run node type (validator, explorer)",
DefValue: defaultConfig.General.NodeType,
}
isStakingFlag = cli.BoolFlag{
Name: "run.staking",
Usage: "whether to run node in staking mode",
DefValue: defaultConfig.General.IsStaking,
}
shardIDFlag = cli.IntFlag{
Name: "run.shard",
Usage: "run node on the given shard ID (-1 automatically configured by BLS keys)",
DefValue: defaultConfig.General.ShardID,
}
isArchiveFlag = cli.BoolFlag{
Name: "run.archive",
Usage: "run node in archive mode",
DefValue: defaultConfig.General.IsArchival,
}
dataDirFlag = cli.StringFlag{
Name: "datadir",
Usage: "directory of chain database",
DefValue: defaultConfig.General.DataDir,
}
legacyNodeTypeFlag = cli.StringFlag{
Name: "node_type",
Usage: "run node type (validator, explorer)",
DefValue: defaultConfig.General.NodeType,
Deprecated: "use --run",
}
legacyIsStakingFlag = cli.BoolFlag{
Name: "staking",
Usage: "whether to run node in staking mode",
DefValue: defaultConfig.General.IsStaking,
Deprecated: "use --run.staking",
}
legacyShardIDFlag = cli.IntFlag{
Name: "shard_id",
Usage: "the shard ID of this node",
DefValue: defaultConfig.General.ShardID,
Deprecated: "use --run.shard",
}
legacyIsArchiveFlag = cli.BoolFlag{
Name: "is_archival",
Usage: "false will enable cached state pruning",
DefValue: defaultConfig.General.IsArchival,
Deprecated: "use --run.archive",
}
legacyDataDirFlag = cli.StringFlag{
Name: "db_dir",
Usage: "blockchain database directory",
DefValue: defaultConfig.General.DataDir,
Deprecated: "use --datadir",
}
)
func applyGeneralFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, nodeTypeFlag) {
config.General.NodeType = cli.GetStringFlagValue(cmd, nodeTypeFlag)
} else if cli.IsFlagChanged(cmd, legacyNodeTypeFlag) {
config.General.NodeType = cli.GetStringFlagValue(cmd, legacyNodeTypeFlag)
}
if cli.IsFlagChanged(cmd, shardIDFlag) {
config.General.ShardID = cli.GetIntFlagValue(cmd, shardIDFlag)
} else if cli.IsFlagChanged(cmd, legacyShardIDFlag) {
config.General.ShardID = cli.GetIntFlagValue(cmd, legacyShardIDFlag)
}
if cli.IsFlagChanged(cmd, isStakingFlag) {
config.General.IsStaking = cli.GetBoolFlagValue(cmd, isStakingFlag)
} else if cli.IsFlagChanged(cmd, legacyIsStakingFlag) {
config.General.IsStaking = cli.GetBoolFlagValue(cmd, legacyIsStakingFlag)
}
if cli.IsFlagChanged(cmd, isArchiveFlag) {
config.General.IsArchival = cli.GetBoolFlagValue(cmd, isArchiveFlag)
} else if cli.IsFlagChanged(cmd, legacyIsArchiveFlag) {
config.General.IsArchival = cli.GetBoolFlagValue(cmd, legacyIsArchiveFlag)
}
if cli.IsFlagChanged(cmd, dataDirFlag) {
config.General.DataDir = cli.GetStringFlagValue(cmd, dataDirFlag)
} else if cli.IsFlagChanged(cmd, legacyDataDirFlag) {
config.General.DataDir = cli.GetStringFlagValue(cmd, legacyDataDirFlag)
}
}
// network flags
var (
networkTypeFlag = cli.StringFlag{
Name: "network",
Shorthand: "n",
DefValue: "mainnet",
Usage: "network to join (mainnet, testnet, pangaea, localnet, partner, stressnet, devnet)",
}
bootNodeFlag = cli.StringSliceFlag{
Name: "bootnodes",
Usage: "a list of bootnode multiaddress (delimited by ,)",
}
dnsZoneFlag = cli.StringFlag{
Name: "dns.zone",
Usage: "use customized peers from the zone for state syncing",
}
// TODO: 9500 as default
dnsPortFlag = cli.IntFlag{
Name: "dns.port",
DefValue: nodeconfig.DefaultDNSPort,
Usage: "port of customized dns node",
}
legacyDNSZoneFlag = cli.StringFlag{
Name: "dns_zone",
Usage: "use peers from the zone for state syncing",
Deprecated: "use --dns.zone",
}
legacyDNSPortFlag = cli.IntFlag{
Name: "dns_port",
Usage: "port of dns node",
Deprecated: "use --dns.zone",
}
legacyDNSFlag = cli.BoolFlag{
Name: "dns",
DefValue: true,
Usage: "use dns for syncing",
Deprecated: "set to false only to use self discovery peers for syncing",
}
legacyNetworkTypeFlag = cli.StringFlag{
Name: "network_type",
Usage: "network to join (mainnet, testnet, pangaea, localnet, partner, stressnet, devnet)",
Deprecated: "use --network",
}
)
func getNetworkType(cmd *cobra.Command) nodeconfig.NetworkType {
var raw string
if cli.IsFlagChanged(cmd, networkTypeFlag) {
raw = cli.GetStringFlagValue(cmd, legacyNetworkTypeFlag)
} else if cli.IsFlagChanged(cmd, legacyNetworkTypeFlag) {
raw = cli.GetStringFlagValue(cmd, networkTypeFlag)
}
nt := parseNetworkType(raw)
return nt
}
func applyNetworkFlags(cmd *cobra.Command, cfg *hmyConfig) {
if cli.IsFlagChanged(cmd, bootNodeFlag) {
cfg.Network.BootNodes = cli.GetStringSliceFlagValue(cmd, bootNodeFlag)
}
if cli.IsFlagChanged(cmd, dnsZoneFlag) {
cfg.Network.DNSZone = cli.GetStringFlagValue(cmd, dnsZoneFlag)
} else if cli.IsFlagChanged(cmd, legacyDNSZoneFlag) {
cfg.Network.DNSZone = cli.GetStringFlagValue(cmd, legacyDNSZoneFlag)
} else if cli.IsFlagChanged(cmd, legacyDNSFlag) {
val := cli.GetBoolFlagValue(cmd, legacyDNSFlag)
if val {
cfg.Network.DNSZone = mainnetDnsZone
} else {
cfg.Network.LegacySyncing = true
}
}
if cli.IsFlagChanged(cmd, dnsPortFlag) {
cfg.Network.DNSPort = cli.GetIntFlagValue(cmd, dnsPortFlag)
} else if cli.IsFlagChanged(cmd, legacyDNSPortFlag) {
cfg.Network.DNSPort = cli.GetIntFlagValue(cmd, legacyDNSPortFlag)
}
}
func parseNetworkType(nt string) nodeconfig.NetworkType {
switch nt {
case "mainnet":
return nodeconfig.Mainnet
case "testnet":
return nodeconfig.Testnet
case "pangaea", "staking", "stk":
return nodeconfig.Pangaea
case "partner":
return nodeconfig.Partner
case "stressnet", "stress", "stn":
return nodeconfig.Stressnet
case "localnet":
return nodeconfig.Localnet
case "devnet", "dev":
return nodeconfig.Devnet
default:
return ""
}
}
func getDefaultNetworkConfig(nt nodeconfig.NetworkType) networkConfig {
bn := nodeconfig.GetDefaultBootNodes(nt)
zone := nodeconfig.GetDefaultDNSZone(nt)
port := nodeconfig.GetDefaultDNSPort(nt)
return networkConfig{
NetworkType: string(nt),
BootNodes: bn,
LegacySyncing: false,
DNSZone: zone,
DNSPort: port,
}
}
// p2p flags
var (
p2pPortFlag = cli.IntFlag{
Name: "p2p.port",
Usage: "port to listen for p2p communication",
DefValue: defaultConfig.P2P.Port,
}
p2pKeyFileFlag = cli.StringFlag{
Name: "p2p.keyfile",
Usage: "the p2p key file of the harmony node",
DefValue: defaultConfig.P2P.KeyFile,
}
legacyKeyFileFlag = cli.StringFlag{
Name: "key",
Usage: "the p2p key file of the harmony node",
DefValue: defaultConfig.P2P.KeyFile,
Deprecated: "use --p2p.keyfile",
}
)
func applyP2PFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, p2pPortFlag) {
config.P2P.Port = cli.GetIntFlagValue(cmd, p2pPortFlag)
}
if cli.IsFlagChanged(cmd, p2pKeyFileFlag) {
config.P2P.KeyFile = cli.GetStringFlagValue(cmd, p2pKeyFileFlag)
} else if cli.IsFlagChanged(cmd, legacyKeyFileFlag) {
config.P2P.KeyFile = cli.GetStringFlagValue(cmd, legacyKeyFileFlag)
}
}
// rpc flags
var (
rpcEnabledFlag = cli.BoolFlag{
Name: "http",
Usage: "enable HTTP / RPC requests",
DefValue: defaultConfig.RPC.Enabled,
}
rpcIPFlag = cli.StringFlag{
Name: "http.ip",
Usage: "ip address to listen for RPC calls",
DefValue: defaultConfig.RPC.IP,
}
rpcPortFlag = cli.IntFlag{
Name: "http.port",
Usage: "rpc port to listen for RPC calls",
DefValue: defaultConfig.RPC.Port,
}
legacyRPCIPFlag = cli.StringFlag{
Name: "ip",
Usage: "ip of the node",
DefValue: defaultConfig.RPC.IP,
Deprecated: "use --http.ip",
}
legacyPublicRPCFlag = cli.BoolFlag{
Name: "public_rpc",
Usage: "Enable Public RPC Access (default: false)",
DefValue: defaultConfig.RPC.Enabled,
Deprecated: "please use --http.ip to specify the ip address to listen",
}
)
func applyRPCFlags(cmd *cobra.Command, config *hmyConfig) {
var isRPCSpecified bool
if cli.IsFlagChanged(cmd, rpcIPFlag) {
config.RPC.IP = cli.GetStringFlagValue(cmd, rpcIPFlag)
isRPCSpecified = true
} else if cli.IsFlagChanged(cmd, legacyRPCIPFlag) {
config.RPC.IP = cli.GetStringFlagValue(cmd, legacyRPCIPFlag)
isRPCSpecified = true
}
if cli.IsFlagChanged(cmd, rpcPortFlag) {
config.RPC.Port = cli.GetIntFlagValue(cmd, rpcPortFlag)
isRPCSpecified = true
}
if cli.IsFlagChanged(cmd, rpcEnabledFlag) {
config.RPC.Enabled = cli.GetBoolFlagValue(cmd, rpcEnabledFlag)
} else if isRPCSpecified {
config.RPC.Enabled = true
}
}
// bls flags
var (
blsDirFlag = cli.StringFlag{
Name: "bls.dir",
Usage: "directory for BLS keys",
DefValue: defaultConfig.BLSKeys.KeyDir,
}
blsKeyFilesFlag = cli.StringSliceFlag{
Name: "bls.keys",
Usage: "a list of BLS key files (separated by ,)",
DefValue: defaultConfig.BLSKeys.KeyFiles,
}
// TODO: shall we move this to a hard coded parameter?
maxBLSKeyFilesFlag = cli.IntFlag{
Name: "bls.maxkeys",
Usage: "maximum number of BLS keys for a node",
DefValue: defaultConfig.BLSKeys.MaxKeys,
Hidden: true,
}
passEnabledFlag = cli.BoolFlag{
Name: "bls.pass",
Usage: "whether BLS key decryption with passphrase is enabled",
DefValue: defaultConfig.BLSKeys.PassEnabled,
}
passSrcTypeFlag = cli.StringFlag{
Name: "bls.pass.src",
Usage: "source for BLS passphrase (auto, file, prompt)",
DefValue: defaultConfig.BLSKeys.PassSrcType,
}
passSrcFileFlag = cli.StringFlag{
Name: "bls.pass.file",
Usage: "the pass file used for BLS decryption. If specified, this pass file will be used for all BLS keys",
DefValue: defaultConfig.BLSKeys.PassFile,
}
passSaveFlag = cli.BoolFlag{
Name: "bls.pass.save",
Usage: "after input the BLS passphrase from console, whether to persist the input passphrases in .pass file",
DefValue: defaultConfig.BLSKeys.SavePassphrase,
}
kmsEnabledFlag = cli.BoolFlag{
Name: "bls.kms",
Usage: "whether BLS key decryption with AWS KMS service is enabled",
DefValue: defaultConfig.BLSKeys.KMSEnabled,
}
kmsConfigSrcTypeFlag = cli.StringFlag{
Name: "bls.kms.src",
Usage: "the AWS config source (region and credentials) for KMS service (shared, prompt, file)",
DefValue: defaultConfig.BLSKeys.KMSConfigSrcType,
}
kmsConfigFileFlag = cli.StringFlag{
Name: "bls.kms.config",
Usage: "json config file for KMS service (region and credentials)",
DefValue: defaultConfig.BLSKeys.KMSConfigFile,
}
legacyBLSKeyFileFlag = cli.StringSliceFlag{
Name: "blskey_file",
Usage: "The encrypted file of bls serialized private key by passphrase.",
DefValue: defaultConfig.BLSKeys.KeyFiles,
Deprecated: "use --bls.keys",
}
legacyBLSFolderFlag = cli.StringFlag{
Name: "blsfolder",
Usage: "The folder that stores the bls keys and corresponding passphrases; e.g. <blskey>.key and <blskey>.pass; all bls keys mapped to same shard",
DefValue: defaultConfig.BLSKeys.KeyDir,
Deprecated: "use --bls.dir",
}
legacyBLSKeysPerNodeFlag = cli.IntFlag{
Name: "max_bls_keys_per_node",
Usage: "Maximum number of bls keys allowed per node",
DefValue: defaultConfig.BLSKeys.MaxKeys,
Deprecated: "use --bls.maxkeys",
}
legacyBLSPassFlag = cli.StringFlag{
Name: "blspass",
Usage: "The source for bls passphrases. (default, stdin, no-prompt, prompt, file:$PASS_FILE, none)",
DefValue: "default",
Deprecated: "use --bls.pass, --bls.pass.src, --bls.pass.file",
}
legacyBLSPersistPassFlag = cli.BoolFlag{
Name: "save-passphrase",
Usage: "Whether the prompt passphrase is saved after prompt.",
DefValue: defaultConfig.BLSKeys.SavePassphrase,
Deprecated: "use --bls.pass.save",
}
legacyKMSConfigSourceFlag = cli.StringFlag{
Name: "aws-config-source",
Usage: "The source for aws config. (default, prompt, file:$CONFIG_FILE, none)",
DefValue: "default",
Deprecated: "use --bls.kms, --bls.kms.src, --bls.kms.config",
}
)
func applyBLSFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, blsDirFlag) {
config.BLSKeys.KeyDir = cli.GetStringFlagValue(cmd, blsDirFlag)
} else if cli.IsFlagChanged(cmd, legacyBLSFolderFlag) {
config.BLSKeys.KeyDir = cli.GetStringFlagValue(cmd, legacyBLSFolderFlag)
}
if cli.IsFlagChanged(cmd, blsKeyFilesFlag) {
config.BLSKeys.KeyFiles = cli.GetStringSliceFlagValue(cmd, blsKeyFilesFlag)
} else if cli.IsFlagChanged(cmd, legacyBLSKeyFileFlag) {
config.BLSKeys.KeyFiles = cli.GetStringSliceFlagValue(cmd, legacyBLSKeyFileFlag)
}
if cli.IsFlagChanged(cmd, maxBLSKeyFilesFlag) {
config.BLSKeys.MaxKeys = cli.GetIntFlagValue(cmd, maxBLSKeyFilesFlag)
} else if cli.IsFlagChanged(cmd, legacyBLSKeysPerNodeFlag) {
config.BLSKeys.MaxKeys = cli.GetIntFlagValue(cmd, legacyBLSKeysPerNodeFlag)
}
if cli.HasFlagsChanged(cmd, newBLSFlags) {
applyBLSPassFlags(cmd, config)
applyKMSFlags(cmd, config)
} else if cli.HasFlagsChanged(cmd, legacyBLSFlags) {
applyLegacyBLSPassFlags(cmd, config)
applyLegacyKMSFlags(cmd, config)
}
}
func applyBLSPassFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, passEnabledFlag) {
config.BLSKeys.PassEnabled = cli.GetBoolFlagValue(cmd, passEnabledFlag)
}
if cli.IsFlagChanged(cmd, passSrcTypeFlag) {
config.BLSKeys.PassSrcType = cli.GetStringFlagValue(cmd, passSrcTypeFlag)
}
if cli.IsFlagChanged(cmd, passSrcFileFlag) {
config.BLSKeys.PassFile = cli.GetStringFlagValue(cmd, passSrcFileFlag)
}
if cli.IsFlagChanged(cmd, passSaveFlag) {
config.BLSKeys.SavePassphrase = cli.GetBoolFlagValue(cmd, passSaveFlag)
}
}
func applyKMSFlags(cmd *cobra.Command, config *hmyConfig) {
var fileSpecified bool
if cli.IsFlagChanged(cmd, kmsEnabledFlag) {
config.BLSKeys.KMSEnabled = cli.GetBoolFlagValue(cmd, kmsEnabledFlag)
}
if cli.IsFlagChanged(cmd, kmsConfigFileFlag) {
config.BLSKeys.KMSConfigFile = cli.GetStringFlagValue(cmd, kmsConfigFileFlag)
fileSpecified = true
}
if cli.IsFlagChanged(cmd, kmsConfigSrcTypeFlag) {
config.BLSKeys.KMSConfigSrcType = cli.GetStringFlagValue(cmd, kmsConfigSrcTypeFlag)
} else if fileSpecified {
config.BLSKeys.KMSConfigSrcType = blsPassTypeFile
}
}
func applyLegacyBLSPassFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, legacyBLSPassFlag) {
val := cli.GetStringFlagValue(cmd, legacyBLSPassFlag)
legacyApplyBLSPassVal(val, config)
}
if cli.IsFlagChanged(cmd, legacyBLSPersistPassFlag) {
config.BLSKeys.SavePassphrase = cli.GetBoolFlagValue(cmd, legacyBLSPersistPassFlag)
}
}
func applyLegacyKMSFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, legacyKMSConfigSourceFlag) {
val := cli.GetStringFlagValue(cmd, legacyKMSConfigSourceFlag)
legacyApplyKMSSourceVal(val, config)
}
}
func legacyApplyBLSPassVal(src string, config *hmyConfig) {
methodArgs := strings.SplitN(src, ":", 2)
method := methodArgs[0]
switch method {
case legacyBLSPassTypeDefault, legacyBLSPassTypeStdin:
config.BLSKeys.PassSrcType = blsPassTypeAuto
case legacyBLSPassTypeStatic:
config.BLSKeys.PassSrcType = blsPassTypeFile
if len(methodArgs) >= 2 {
config.BLSKeys.PassFile = methodArgs[1]
}
case legacyBLSPassTypeDynamic:
config.BLSKeys.PassSrcType = blsPassTypePrompt
case legacyBLSPassTypePrompt:
config.BLSKeys.PassSrcType = blsPassTypePrompt
case legacyBLSPassTypeNone:
config.BLSKeys.PassEnabled = false
}
}
func legacyApplyKMSSourceVal(src string, config *hmyConfig) {
methodArgs := strings.SplitN(src, ":", 2)
method := methodArgs[0]
switch method {
case legacyBLSKmsTypeDefault:
config.BLSKeys.KMSConfigSrcType = kmsConfigTypeShared
case legacyBLSKmsTypePrompt:
config.BLSKeys.KMSConfigSrcType = kmsConfigTypePrompt
case legacyBLSKmsTypeFile:
config.BLSKeys.KMSConfigSrcType = kmsConfigTypeFile
if len(methodArgs) >= 2 {
config.BLSKeys.KMSConfigFile = methodArgs[1]
}
case legacyBLSKmsTypeNone:
config.BLSKeys.KMSEnabled = false
}
}
// consensus flags
var (
// TODO: hard code value?
consensusDelayCommitFlag = cli.StringFlag{
Name: "consensus.delay-commit",
Usage: "how long to delay sending commit messages in consensus, e.g: 500ms, 1s",
DefValue: defaultConfig.Consensus.DelayCommit,
Hidden: true,
}
// TODO: hard code value?
consensusBlockTimeFlag = cli.StringFlag{
Name: "consensus.block-time",
Usage: "block interval time, e.g: 8s",
DefValue: defaultConfig.Consensus.BlockTime,
Hidden: true,
}
legacyDelayCommitFlag = cli.StringFlag{
Name: "delay_commit",
Usage: "how long to delay sending commit messages in consensus, ex: 500ms, 1s",
DefValue: defaultConfig.Consensus.DelayCommit,
Deprecated: "use --consensus.delay-commit",
}
legacyBlockTimeFlag = cli.IntFlag{
Name: "block_period",
Usage: "how long in second the leader waits to propose a new block",
DefValue: 8,
Deprecated: "use --consensus.block-time",
}
)
func applyConsensusFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, consensusDelayCommitFlag) {
config.Consensus.DelayCommit = cli.GetStringFlagValue(cmd, consensusDelayCommitFlag)
} else if cli.IsFlagChanged(cmd, legacyDelayCommitFlag) {
config.Consensus.DelayCommit = cli.GetStringFlagValue(cmd, legacyDelayCommitFlag)
}
if cli.IsFlagChanged(cmd, consensusBlockTimeFlag) {
config.Consensus.BlockTime = cli.GetStringFlagValue(cmd, consensusBlockTimeFlag)
} else if cli.IsFlagChanged(cmd, legacyBlockTimeFlag) {
sec := cli.GetIntFlagValue(cmd, legacyBlockTimeFlag)
config.Consensus.BlockTime = fmt.Sprintf("%ds", sec)
}
}
// transaction pool flags
var (
tpBlacklistFileFlag = cli.StringFlag{
Name: "txpool.blacklist",
Usage: "file of blacklisted wallet addresses",
DefValue: defaultConfig.TxPool.BlacklistFile,
}
// TODO: mark hard code?
tpBroadcastInvalidTxFlag = cli.BoolFlag{
Name: "txpool.broadcast-invalid-tx",
Usage: "whether to broadcast invalid transactions",
DefValue: defaultConfig.TxPool.BroadcastInvalidTx,
Hidden: true,
}
legacyTPBlacklistFileFlag = cli.StringFlag{
Name: "blacklist",
Usage: "Path to newline delimited file of blacklisted wallet addresses",
DefValue: defaultConfig.TxPool.BlacklistFile,
Deprecated: "use --txpool.blacklist",
}
legacyTPBroadcastInvalidTxFlag = cli.BoolFlag{
Name: "broadcast_invalid_tx",
Usage: "broadcast invalid transactions to sync pool state",
DefValue: defaultConfig.TxPool.BroadcastInvalidTx,
Deprecated: "use --txpool.broadcast-invalid-tx",
}
)
func applyTxPoolFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, tpBlacklistFileFlag) {
config.TxPool.BlacklistFile = cli.GetStringFlagValue(cmd, tpBlacklistFileFlag)
} else if cli.IsFlagChanged(cmd, legacyTPBlacklistFileFlag) {
config.TxPool.BlacklistFile = cli.GetStringFlagValue(cmd, legacyTPBlacklistFileFlag)
}
if cli.IsFlagChanged(cmd, tpBroadcastInvalidTxFlag) {
config.TxPool.BroadcastInvalidTx = cli.GetBoolFlagValue(cmd, tpBroadcastInvalidTxFlag)
} else if cli.IsFlagChanged(cmd, legacyTPBroadcastInvalidTxFlag) {
config.TxPool.BroadcastInvalidTx = cli.GetBoolFlagValue(cmd, legacyTPBroadcastInvalidTxFlag)
}
}
// pprof flags
var (
pprofEnabledFlag = cli.BoolFlag{
Name: "pprof",
Usage: "enable pprof profiling",
DefValue: defaultConfig.Pprof.Enabled,
}
pprofListenAddrFlag = cli.StringFlag{
Name: "pprof.addr",
Usage: "listen address for pprof",
DefValue: defaultConfig.Pprof.ListenAddr,
}
)
func applyPprofFlags(cmd *cobra.Command, config *hmyConfig) {
var pprofSet bool
if cli.IsFlagChanged(cmd, pprofListenAddrFlag) {
config.Pprof.ListenAddr = cli.GetStringFlagValue(cmd, pprofListenAddrFlag)
pprofSet = true
}
if cli.IsFlagChanged(cmd, pprofEnabledFlag) {
config.Pprof.Enabled = cli.GetBoolFlagValue(cmd, pprofEnabledFlag)
} else if pprofSet {
config.Pprof.Enabled = true
}
}
// log flags
var (
logFolderFlag = cli.StringFlag{
Name: "log.path",
Usage: "directory path to put rotation logs",
DefValue: defaultConfig.Log.LogFolder,
}
logRotateSizeFlag = cli.IntFlag{
Name: "log.max-size",
Usage: "rotation log size in megabytes",
DefValue: defaultConfig.Log.LogRotateSize,
}
legacyLogFolderFlag = cli.StringFlag{
Name: "log_folder",
Usage: "the folder collecting the logs of this execution",
DefValue: defaultConfig.Log.LogFolder,
Deprecated: "use --log.path",
}
legacyLogRotateSizeFlag = cli.IntFlag{
Name: "log_max_size",
Usage: "the max size in megabytes of the log file before it gets rotated",
DefValue: defaultConfig.Log.LogRotateSize,
Deprecated: "use --log.max-size",
}
)
func applyLogFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, logFolderFlag) {
config.Log.LogFolder = cli.GetStringFlagValue(cmd, logFolderFlag)
} else if cli.IsFlagChanged(cmd, legacyLogFolderFlag) {
config.Log.LogFolder = cli.GetStringFlagValue(cmd, legacyLogFolderFlag)
}
if cli.IsFlagChanged(cmd, logRotateSizeFlag) {
config.Log.LogRotateSize = cli.GetIntFlagValue(cmd, logRotateSizeFlag)
} else if cli.IsFlagChanged(cmd, legacyLogRotateSizeFlag) {
config.Log.LogRotateSize = cli.GetIntFlagValue(cmd, legacyLogRotateSizeFlag)
}
}
var (
devnetNumShardsFlag = cli.IntFlag{
Name: "devnet.num-shard",
Usage: "number of shards for devnet",
DefValue: defaultDevnetConfig.NumShards,
}
devnetShardSizeFlag = cli.IntFlag{
Name: "devnet.shard-size",
Usage: "number of nodes per shard for devnet",
DefValue: defaultDevnetConfig.ShardSize,
}
devnetHmyNodeSizeFlag = cli.IntFlag{
Name: "devnet.hmy-node-size",
Usage: "number of Harmony-operated nodes per shard for devnet (negative means equal to --devnet.shard-size)",
DefValue: defaultDevnetConfig.HmyNodeSize,
}
legacyDevnetNumShardsFlag = cli.IntFlag{
Name: "dn_num_shards",
Usage: "number of shards for -network_type=devnet",
DefValue: defaultDevnetConfig.NumShards,
Deprecated: "use --devnet.num-shard",
}
legacyDevnetShardSizeFlag = cli.IntFlag{
Name: "dn_shard_size",
Usage: "number of nodes per shard for -network_type=devnet",
DefValue: defaultDevnetConfig.ShardSize,
Deprecated: "use --devnet.shard-size",
}
legacyDevnetHmyNodeSizeFlag = cli.IntFlag{
Name: "dn_hmy_size",
Usage: "number of Harmony-operated nodes per shard for -network_type=devnet; negative means equal to -dn_shard_size",
DefValue: defaultDevnetConfig.HmyNodeSize,
Deprecated: "use --devnet.hmy-node-size",
}
)
func applyDevnetFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.HasFlagsChanged(cmd, devnetFlags) && config.Devnet != nil {
devnet := getDefaultDevnetConfigCopy()
config.Devnet = &devnet
}
if cli.HasFlagsChanged(cmd, newDevnetFlags) {
if cli.IsFlagChanged(cmd, devnetNumShardsFlag) {
config.Devnet.NumShards = cli.GetIntFlagValue(cmd, devnetNumShardsFlag)
}
if cli.IsFlagChanged(cmd, devnetShardSizeFlag) {
config.Devnet.ShardSize = cli.GetIntFlagValue(cmd, devnetShardSizeFlag)
}
if cli.IsFlagChanged(cmd, devnetHmyNodeSizeFlag) {
config.Devnet.HmyNodeSize = cli.GetIntFlagValue(cmd, devnetHmyNodeSizeFlag)
}
}
if cli.HasFlagsChanged(cmd, legacyDevnetFlags) {
if cli.IsFlagChanged(cmd, legacyDevnetNumShardsFlag) {
config.Devnet.NumShards = cli.GetIntFlagValue(cmd, legacyDevnetNumShardsFlag)
}
if cli.IsFlagChanged(cmd, legacyDevnetShardSizeFlag) {
config.Devnet.ShardSize = cli.GetIntFlagValue(cmd, legacyDevnetShardSizeFlag)
}
if cli.IsFlagChanged(cmd, legacyDevnetHmyNodeSizeFlag) {
config.Devnet.HmyNodeSize = cli.GetIntFlagValue(cmd, legacyDevnetHmyNodeSizeFlag)
}
}
}
var (
revertBeaconFlag = cli.BoolFlag{
Name: "revert.beacon",
Usage: "revert the beacon chain",
DefValue: defaultRevertConfig.RevertBeacon,
Hidden: true,
}
revertToFlag = cli.IntFlag{
Name: "revert.to",
Usage: "rollback all blocks until and including block number revert_to",
DefValue: defaultRevertConfig.RevertTo,
Hidden: true,
}
revertBeforeFlag = cli.IntFlag{
Name: "revert.do-before",
Usage: "if the current block is less than do_revert_before, revert all blocks until (including) revert_to block",
DefValue: defaultRevertConfig.RevertBefore,
Hidden: true,
}
legacyRevertBeaconFlag = cli.BoolFlag{
Name: "revert_beacon",
Usage: "whether to revert beacon chain or the chain this node is assigned to",
DefValue: defaultRevertConfig.RevertBeacon,
Deprecated: "use --revert.beacon",
}
legacyRevertBeforeFlag = cli.IntFlag{
Name: "do_revert_before",
Usage: "If the current block is less than do_revert_before, revert all blocks until (including) revert_to block",
DefValue: defaultRevertConfig.RevertBefore,
Deprecated: "use --revert.do-before",
}
legacyRevertToFlag = cli.IntFlag{
Name: "revert_to",
Usage: "The revert will rollback all blocks until and including block number revert_to",
DefValue: defaultRevertConfig.RevertTo,
Deprecated: "use --revert.to",
}
)
func applyRevertFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.HasFlagsChanged(cmd, revertFlags) {
revert := getDefaultRevertConfigCopy()
config.Revert = &revert
}
if cli.HasFlagsChanged(cmd, newRevertFlags) {
if cli.IsFlagChanged(cmd, revertBeaconFlag) {
config.Revert.RevertBeacon = cli.GetBoolFlagValue(cmd, revertBeaconFlag)
}
if cli.IsFlagChanged(cmd, revertBeforeFlag) {
config.Revert.RevertBefore = cli.GetIntFlagValue(cmd, revertBeforeFlag)
}
if cli.IsFlagChanged(cmd, revertToFlag) {
config.Revert.RevertTo = cli.GetIntFlagValue(cmd, revertToFlag)
}
}
if cli.HasFlagsChanged(cmd, legacyRevertFlags) {
if cli.IsFlagChanged(cmd, legacyRevertBeaconFlag) {
config.Revert.RevertBeacon = cli.GetBoolFlagValue(cmd, legacyRevertBeaconFlag)
}
if cli.IsFlagChanged(cmd, legacyRevertBeforeFlag) {
config.Revert.RevertBefore = cli.GetIntFlagValue(cmd, legacyRevertBeforeFlag)
}
if cli.IsFlagChanged(cmd, legacyRevertToFlag) {
config.Revert.RevertTo = cli.GetIntFlagValue(cmd, legacyRevertToFlag)
}
}
}
var (
legacyPortFlag = cli.IntFlag{
Name: "port",
Usage: "port of the node",
DefValue: defaultConfig.P2P.Port,
Deprecated: "Use --p2p.port, --http.port instead",
}
// This flag is very special: it is out of the scope of the hmyConfig. Need to
// execute remove db in prepare.
legacyFreshDB = cli.BoolFlag{
Name: "fresh_db",
Usage: "true means the existing disk based db will be removed",
DefValue: false,
Deprecated: "will be removed in future version",
}
)
// Note: this function need to be called before parse other flags
func applyMiscFlags(cmd *cobra.Command, config *hmyConfig) {
// TODO: move all port manipulation +500 -3000 logic here
if cli.IsFlagChanged(cmd, legacyPortFlag) {
legacyPort := cli.GetIntFlagValue(cmd, legacyPortFlag)
config.P2P.Port = legacyPort
config.RPC.Port = legacyPort
}
}

@ -1,486 +0,0 @@
package main
import (
"fmt"
"github.com/harmony-one/harmony/internal/cli"
"github.com/spf13/cobra"
)
var generalFlags = []cli.Flag{
nodeTypeFlag,
isStakingFlag,
shardIDFlag,
isArchiveFlag,
dataDirFlag,
legacyNodeTypeFlag,
legacyIsStakingFlag,
legacyShardIDFlag,
legacyIsArchiveFlag,
legacyDataDirFlag,
}
var (
nodeTypeFlag = cli.StringFlag{
Name: "run",
Usage: "run node type (validator, explorer)",
DefValue: defaultConfig.General.NodeType,
}
isStakingFlag = cli.BoolFlag{
Name: "run.staking",
Usage: "whether to run node in staking mode",
DefValue: defaultConfig.General.IsStaking,
}
shardIDFlag = cli.IntFlag{
Name: "run.shard",
Usage: "run node on the given shard ID (-1 automatically configured by BLS keys)",
DefValue: defaultConfig.General.ShardID,
}
isArchiveFlag = cli.BoolFlag{
Name: "run.archive",
Usage: "run node in archive mode",
DefValue: defaultConfig.General.IsArchival,
}
dataDirFlag = cli.StringFlag{
Name: "datadir",
Usage: "directory of chain database",
DefValue: defaultConfig.General.DataDir,
}
legacyNodeTypeFlag = cli.StringFlag{
Name: "node_type",
Usage: "run node type (validator, explorer)",
DefValue: defaultConfig.General.NodeType,
Deprecated: "use --run",
}
legacyIsStakingFlag = cli.BoolFlag{
Name: "staking",
Usage: "whether to run node in staking mode",
DefValue: defaultConfig.General.IsStaking,
Deprecated: "use --run.staking",
}
legacyShardIDFlag = cli.IntFlag{
Name: "shard_id",
Usage: "the shard ID of this node",
DefValue: defaultConfig.General.ShardID,
Deprecated: "use --run.shard",
}
legacyIsArchiveFlag = cli.BoolFlag{
Name: "is_archival",
Usage: "false will enable cached state pruning",
DefValue: defaultConfig.General.IsArchival,
Deprecated: "use --run.archive",
}
legacyDataDirFlag = cli.StringFlag{
Name: "db_dir",
Usage: "blockchain database directory",
DefValue: defaultConfig.General.DataDir,
Deprecated: "use --datadir",
}
)
func applyGeneralFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, nodeTypeFlag) {
config.General.NodeType = cli.GetStringFlagValue(cmd, nodeTypeFlag)
} else if cli.IsFlagChanged(cmd, legacyNodeTypeFlag) {
config.General.NodeType = cli.GetStringFlagValue(cmd, legacyNodeTypeFlag)
}
if cli.IsFlagChanged(cmd, shardIDFlag) {
config.General.ShardID = cli.GetIntFlagValue(cmd, shardIDFlag)
} else if cli.IsFlagChanged(cmd, legacyShardIDFlag) {
config.General.ShardID = cli.GetIntFlagValue(cmd, legacyShardIDFlag)
}
if cli.IsFlagChanged(cmd, isStakingFlag) {
config.General.IsStaking = cli.GetBoolFlagValue(cmd, isStakingFlag)
} else if cli.IsFlagChanged(cmd, legacyIsStakingFlag) {
config.General.IsStaking = cli.GetBoolFlagValue(cmd, legacyIsStakingFlag)
}
if cli.IsFlagChanged(cmd, isArchiveFlag) {
config.General.IsArchival = cli.GetBoolFlagValue(cmd, isArchiveFlag)
} else if cli.IsFlagChanged(cmd, legacyIsArchiveFlag) {
config.General.IsArchival = cli.GetBoolFlagValue(cmd, legacyIsArchiveFlag)
}
if cli.IsFlagChanged(cmd, dataDirFlag) {
config.General.DataDir = cli.GetStringFlagValue(cmd, dataDirFlag)
} else if cli.IsFlagChanged(cmd, legacyDataDirFlag) {
config.General.DataDir = cli.GetStringFlagValue(cmd, legacyDataDirFlag)
}
}
var consensusFlags = []cli.Flag{
consensusDelayCommitFlag,
consensusBlockTimeFlag,
legacyDelayCommitFlag,
legacyBlockTimeFlag,
}
var (
// TODO: hard code value?
consensusDelayCommitFlag = cli.StringFlag{
Name: "consensus.delay-commit",
Usage: "how long to delay sending commit messages in consensus, e.g: 500ms, 1s",
DefValue: defaultConfig.Consensus.DelayCommit,
Hidden: true,
}
// TODO: hard code value?
consensusBlockTimeFlag = cli.StringFlag{
Name: "consensus.block-time",
Usage: "block interval time, e.g: 8s",
DefValue: defaultConfig.Consensus.BlockTime,
Hidden: true,
}
legacyDelayCommitFlag = cli.StringFlag{
Name: "delay_commit",
Usage: "how long to delay sending commit messages in consensus, ex: 500ms, 1s",
DefValue: defaultConfig.Consensus.DelayCommit,
Deprecated: "use --consensus.delay-commit",
}
legacyBlockTimeFlag = cli.IntFlag{
Name: "block_period",
Usage: "how long in second the leader waits to propose a new block",
DefValue: 8,
Deprecated: "use --consensus.block-time",
}
)
func applyConsensusFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, consensusDelayCommitFlag) {
config.Consensus.DelayCommit = cli.GetStringFlagValue(cmd, consensusDelayCommitFlag)
} else if cli.IsFlagChanged(cmd, legacyDelayCommitFlag) {
config.Consensus.DelayCommit = cli.GetStringFlagValue(cmd, legacyDelayCommitFlag)
}
if cli.IsFlagChanged(cmd, consensusBlockTimeFlag) {
config.Consensus.BlockTime = cli.GetStringFlagValue(cmd, consensusBlockTimeFlag)
} else if cli.IsFlagChanged(cmd, legacyBlockTimeFlag) {
sec := cli.GetIntFlagValue(cmd, legacyBlockTimeFlag)
config.Consensus.BlockTime = fmt.Sprintf("%ds", sec)
}
}
var txPoolFlags = []cli.Flag{
tpBlacklistFileFlag,
tpBroadcastInvalidTxFlag,
legacyTPBlacklistFileFlag,
legacyTPBroadcastInvalidTxFlag,
}
var (
tpBlacklistFileFlag = cli.StringFlag{
Name: "txpool.blacklist",
Usage: "file of blacklisted wallet addresses",
DefValue: defaultConfig.TxPool.BlacklistFile,
}
// TODO: mark hard code?
tpBroadcastInvalidTxFlag = cli.BoolFlag{
Name: "txpool.broadcast-invalid-tx",
Usage: "whether to broadcast invalid transactions",
DefValue: defaultConfig.TxPool.BroadcastInvalidTx,
Hidden: true,
}
legacyTPBlacklistFileFlag = cli.StringFlag{
Name: "blacklist",
Usage: "Path to newline delimited file of blacklisted wallet addresses",
DefValue: defaultConfig.TxPool.BlacklistFile,
Deprecated: "use --txpool.blacklist",
}
legacyTPBroadcastInvalidTxFlag = cli.BoolFlag{
Name: "broadcast_invalid_tx",
Usage: "broadcast invalid transactions to sync pool state",
DefValue: defaultConfig.TxPool.BroadcastInvalidTx,
Deprecated: "use --txpool.broadcast-invalid-tx",
}
)
func applyTxPoolFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, tpBlacklistFileFlag) {
config.TxPool.BlacklistFile = cli.GetStringFlagValue(cmd, tpBlacklistFileFlag)
} else if cli.IsFlagChanged(cmd, legacyTPBlacklistFileFlag) {
config.TxPool.BlacklistFile = cli.GetStringFlagValue(cmd, legacyTPBlacklistFileFlag)
}
if cli.IsFlagChanged(cmd, tpBroadcastInvalidTxFlag) {
config.TxPool.BroadcastInvalidTx = cli.GetBoolFlagValue(cmd, tpBroadcastInvalidTxFlag)
} else if cli.IsFlagChanged(cmd, legacyTPBroadcastInvalidTxFlag) {
config.TxPool.BroadcastInvalidTx = cli.GetBoolFlagValue(cmd, legacyTPBroadcastInvalidTxFlag)
}
}
var pprofFlags = []cli.Flag{
pprofEnabledFlag,
pprofListenAddrFlag,
}
var (
pprofEnabledFlag = cli.BoolFlag{
Name: "pprof",
Usage: "enable pprof profiling",
DefValue: defaultConfig.Pprof.Enabled,
}
pprofListenAddrFlag = cli.StringFlag{
Name: "pprof.addr",
Usage: "listen address for pprof",
DefValue: defaultConfig.Pprof.ListenAddr,
}
)
func applyPprofFlags(cmd *cobra.Command, config *hmyConfig) {
var pprofSet bool
if cli.IsFlagChanged(cmd, pprofListenAddrFlag) {
config.Pprof.ListenAddr = cli.GetStringFlagValue(cmd, pprofListenAddrFlag)
pprofSet = true
}
if cli.IsFlagChanged(cmd, pprofEnabledFlag) {
config.Pprof.Enabled = cli.GetBoolFlagValue(cmd, pprofEnabledFlag)
} else if pprofSet {
config.Pprof.Enabled = true
}
}
var logFlags = []cli.Flag{
logFolderFlag,
logRotateSizeFlag,
legacyLogFolderFlag,
legacyLogRotateSizeFlag,
}
var (
logFolderFlag = cli.StringFlag{
Name: "log.path",
Usage: "directory path to put rotation logs",
DefValue: defaultConfig.Log.LogFolder,
}
logRotateSizeFlag = cli.IntFlag{
Name: "log.max-size",
Usage: "rotation log size in megabytes",
DefValue: defaultConfig.Log.LogRotateSize,
}
legacyLogFolderFlag = cli.StringFlag{
Name: "log_folder",
Usage: "the folder collecting the logs of this execution",
DefValue: defaultConfig.Log.LogFolder,
Deprecated: "use --log.path",
}
legacyLogRotateSizeFlag = cli.IntFlag{
Name: "log_max_size",
Usage: "the max size in megabytes of the log file before it gets rotated",
DefValue: defaultConfig.Log.LogRotateSize,
Deprecated: "use --log.max-size",
}
)
func applyLogFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, logFolderFlag) {
config.Log.LogFolder = cli.GetStringFlagValue(cmd, logFolderFlag)
} else if cli.IsFlagChanged(cmd, legacyLogFolderFlag) {
config.Log.LogFolder = cli.GetStringFlagValue(cmd, legacyLogFolderFlag)
}
if cli.IsFlagChanged(cmd, logRotateSizeFlag) {
config.Log.LogRotateSize = cli.GetIntFlagValue(cmd, logRotateSizeFlag)
} else if cli.IsFlagChanged(cmd, legacyLogRotateSizeFlag) {
config.Log.LogRotateSize = cli.GetIntFlagValue(cmd, legacyLogRotateSizeFlag)
}
}
var newDevnetFlags = []cli.Flag{
devnetNumShardsFlag,
devnetShardSizeFlag,
devnetHmyNodeSizeFlag,
}
var legacyDevnetFlags = []cli.Flag{
legacyDevnetNumShardsFlag,
legacyDevnetShardSizeFlag,
legacyDevnetHmyNodeSizeFlag,
}
var devnetFlags = append(newDevnetFlags, legacyDevnetFlags...)
var (
devnetNumShardsFlag = cli.IntFlag{
Name: "devnet.num-shard",
Usage: "number of shards for devnet",
DefValue: defaultDevnetConfig.NumShards,
}
devnetShardSizeFlag = cli.IntFlag{
Name: "devnet.shard-size",
Usage: "number of nodes per shard for devnet",
DefValue: defaultDevnetConfig.ShardSize,
}
devnetHmyNodeSizeFlag = cli.IntFlag{
Name: "devnet.hmy-node-size",
Usage: "number of Harmony-operated nodes per shard for devnet (negative means equal to --devnet.shard-size)",
DefValue: defaultDevnetConfig.HmyNodeSize,
}
legacyDevnetNumShardsFlag = cli.IntFlag{
Name: "dn_num_shards",
Usage: "number of shards for -network_type=devnet",
DefValue: defaultDevnetConfig.NumShards,
Deprecated: "use --devnet.num-shard",
}
legacyDevnetShardSizeFlag = cli.IntFlag{
Name: "dn_shard_size",
Usage: "number of nodes per shard for -network_type=devnet",
DefValue: defaultDevnetConfig.ShardSize,
Deprecated: "use --devnet.shard-size",
}
legacyDevnetHmyNodeSizeFlag = cli.IntFlag{
Name: "dn_hmy_size",
Usage: "number of Harmony-operated nodes per shard for -network_type=devnet; negative means equal to -dn_shard_size",
DefValue: defaultDevnetConfig.HmyNodeSize,
Deprecated: "use --devnet.hmy-node-size",
}
)
func applyDevnetFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.HasFlagsChanged(cmd, devnetFlags) && config.Devnet != nil {
devnet := getDefaultDevnetConfigCopy()
config.Devnet = &devnet
}
if cli.HasFlagsChanged(cmd, newDevnetFlags) {
if cli.IsFlagChanged(cmd, devnetNumShardsFlag) {
config.Devnet.NumShards = cli.GetIntFlagValue(cmd, devnetNumShardsFlag)
}
if cli.IsFlagChanged(cmd, devnetShardSizeFlag) {
config.Devnet.ShardSize = cli.GetIntFlagValue(cmd, devnetShardSizeFlag)
}
if cli.IsFlagChanged(cmd, devnetHmyNodeSizeFlag) {
config.Devnet.HmyNodeSize = cli.GetIntFlagValue(cmd, devnetHmyNodeSizeFlag)
}
}
if cli.HasFlagsChanged(cmd, legacyDevnetFlags) {
if cli.IsFlagChanged(cmd, legacyDevnetNumShardsFlag) {
config.Devnet.NumShards = cli.GetIntFlagValue(cmd, legacyDevnetNumShardsFlag)
}
if cli.IsFlagChanged(cmd, legacyDevnetShardSizeFlag) {
config.Devnet.ShardSize = cli.GetIntFlagValue(cmd, legacyDevnetShardSizeFlag)
}
if cli.IsFlagChanged(cmd, legacyDevnetHmyNodeSizeFlag) {
config.Devnet.HmyNodeSize = cli.GetIntFlagValue(cmd, legacyDevnetHmyNodeSizeFlag)
}
}
}
var revertFlags = append(newRevertFlags, legacyRevertFlags...)
var newRevertFlags = []cli.Flag{
revertBeaconFlag,
revertToFlag,
revertBeforeFlag,
}
var legacyRevertFlags = []cli.Flag{
legacyRevertBeaconFlag,
legacyRevertBeforeFlag,
legacyRevertToFlag,
}
var (
revertBeaconFlag = cli.BoolFlag{
Name: "revert.beacon",
Usage: "revert the beacon chain",
DefValue: defaultRevertConfig.RevertBeacon,
Hidden: true,
}
revertToFlag = cli.IntFlag{
Name: "revert.to",
Usage: "rollback all blocks until and including block number revert_to",
DefValue: defaultRevertConfig.RevertTo,
Hidden: true,
}
revertBeforeFlag = cli.IntFlag{
Name: "revert.do-before",
Usage: "if the current block is less than do_revert_before, revert all blocks until (including) revert_to block",
DefValue: defaultRevertConfig.RevertBefore,
Hidden: true,
}
legacyRevertBeaconFlag = cli.BoolFlag{
Name: "revert_beacon",
Usage: "whether to revert beacon chain or the chain this node is assigned to",
DefValue: defaultRevertConfig.RevertBeacon,
Deprecated: "use --revert.beacon",
}
legacyRevertBeforeFlag = cli.IntFlag{
Name: "do_revert_before",
Usage: "If the current block is less than do_revert_before, revert all blocks until (including) revert_to block",
DefValue: defaultRevertConfig.RevertBefore,
Deprecated: "use --revert.do-before",
}
legacyRevertToFlag = cli.IntFlag{
Name: "revert_to",
Usage: "The revert will rollback all blocks until and including block number revert_to",
DefValue: defaultRevertConfig.RevertTo,
Deprecated: "use --revert.to",
}
)
func applyRevertFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.HasFlagsChanged(cmd, revertFlags) {
revert := getDefaultRevertConfigCopy()
config.Revert = &revert
}
if cli.HasFlagsChanged(cmd, newRevertFlags) {
if cli.IsFlagChanged(cmd, revertBeaconFlag) {
config.Revert.RevertBeacon = cli.GetBoolFlagValue(cmd, revertBeaconFlag)
}
if cli.IsFlagChanged(cmd, revertBeforeFlag) {
config.Revert.RevertBefore = cli.GetIntFlagValue(cmd, revertBeforeFlag)
}
if cli.IsFlagChanged(cmd, revertToFlag) {
config.Revert.RevertTo = cli.GetIntFlagValue(cmd, revertToFlag)
}
}
if cli.HasFlagsChanged(cmd, legacyRevertFlags) {
if cli.IsFlagChanged(cmd, legacyRevertBeaconFlag) {
config.Revert.RevertBeacon = cli.GetBoolFlagValue(cmd, legacyRevertBeaconFlag)
}
if cli.IsFlagChanged(cmd, legacyRevertBeforeFlag) {
config.Revert.RevertBefore = cli.GetIntFlagValue(cmd, legacyRevertBeforeFlag)
}
if cli.IsFlagChanged(cmd, legacyRevertToFlag) {
config.Revert.RevertTo = cli.GetIntFlagValue(cmd, legacyRevertToFlag)
}
}
}
// legacyMiscFlags are legacy flags that cannot be categorized to a single category.
var legacyMiscFlags = []cli.Flag{
legacyPortFlag,
legacyFreshDB,
}
var (
legacyPortFlag = cli.IntFlag{
Name: "port",
Usage: "port of the node",
DefValue: defaultConfig.P2P.Port,
Deprecated: "Use --p2p.port, --http.port instead",
}
legacyFreshDB = cli.BoolFlag{
Name: "fresh_db",
Usage: "true means the existing disk based db will be removed",
DefValue: false,
Deprecated: "will be removed in future version",
}
)
// Note: this function need to be called before parse other flags
func applyMiscFlags(cmd *cobra.Command, config *hmyConfig) {
// TODO: move all port manipulation +500 -3000 logic here
if cli.IsFlagChanged(cmd, legacyPortFlag) {
legacyPort := cli.GetIntFlagValue(cmd, legacyPortFlag)
config.P2P.Port = legacyPort
config.RPC.Port = legacyPort
}
}

@ -1,230 +0,0 @@
package main
import (
"github.com/harmony-one/harmony/internal/cli"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/spf13/cobra"
)
var networkFlags = []cli.Flag{
networkTypeFlag,
bootNodeFlag,
dnsZoneFlag,
dnsPortFlag,
legacyDNSZoneFlag,
legacyDNSPortFlag,
legacyDNSFlag,
legacyNetworkTypeFlag,
}
var (
networkTypeFlag = cli.StringFlag{
Name: "network",
Shorthand: "n",
DefValue: "mainnet",
Usage: "network to join (mainnet, testnet, pangaea, localnet, partner, stressnet, devnet)",
}
bootNodeFlag = cli.StringSliceFlag{
Name: "bootnodes",
Usage: "a list of bootnode multiaddress (delimited by ,)",
}
dnsZoneFlag = cli.StringFlag{
Name: "dns.zone",
Usage: "use customized peers from the zone for state syncing",
}
// TODO: 9500 as default
dnsPortFlag = cli.IntFlag{
Name: "dns.port",
DefValue: nodeconfig.DefaultDNSPort,
Usage: "port of customized dns node",
}
legacyDNSZoneFlag = cli.StringFlag{
Name: "dns_zone",
Usage: "use peers from the zone for state syncing",
Deprecated: "use --dns.zone",
}
legacyDNSPortFlag = cli.IntFlag{
Name: "dns_port",
Usage: "port of dns node",
Deprecated: "use --dns.zone",
}
legacyDNSFlag = cli.BoolFlag{
Name: "dns",
DefValue: true,
Usage: "use dns for syncing",
Deprecated: "set to false only to use self discovery peers for syncing",
}
legacyNetworkTypeFlag = cli.StringFlag{
Name: "network_type",
Usage: "network to join (mainnet, testnet, pangaea, localnet, partner, stressnet, devnet)",
Deprecated: "use --network",
}
)
func getNetworkType(cmd *cobra.Command) nodeconfig.NetworkType {
var raw string
if cli.IsFlagChanged(cmd, networkTypeFlag) {
raw = cli.GetStringFlagValue(cmd, legacyNetworkTypeFlag)
} else if cli.IsFlagChanged(cmd, legacyNetworkTypeFlag) {
raw = cli.GetStringFlagValue(cmd, networkTypeFlag)
}
nt := parseNetworkType(raw)
return nt
}
func applyNetworkFlags(cmd *cobra.Command, cfg *hmyConfig) {
if cli.IsFlagChanged(cmd, bootNodeFlag) {
cfg.Network.BootNodes = cli.GetStringSliceFlagValue(cmd, bootNodeFlag)
}
if cli.IsFlagChanged(cmd, dnsZoneFlag) {
cfg.Network.DNSZone = cli.GetStringFlagValue(cmd, dnsZoneFlag)
} else if cli.IsFlagChanged(cmd, legacyDNSZoneFlag) {
cfg.Network.DNSZone = cli.GetStringFlagValue(cmd, legacyDNSZoneFlag)
} else if cli.IsFlagChanged(cmd, legacyDNSFlag) {
val := cli.GetBoolFlagValue(cmd, legacyDNSFlag)
if val {
cfg.Network.DNSZone = mainnetDnsZone
} else {
cfg.Network.LegacySyncing = true
}
}
if cli.IsFlagChanged(cmd, dnsPortFlag) {
cfg.Network.DNSPort = cli.GetIntFlagValue(cmd, dnsPortFlag)
} else if cli.IsFlagChanged(cmd, legacyDNSPortFlag) {
cfg.Network.DNSPort = cli.GetIntFlagValue(cmd, legacyDNSPortFlag)
}
}
func parseNetworkType(nt string) nodeconfig.NetworkType {
switch nt {
case "mainnet":
return nodeconfig.Mainnet
case "testnet":
return nodeconfig.Testnet
case "pangaea", "staking", "stk":
return nodeconfig.Pangaea
case "partner":
return nodeconfig.Partner
case "stressnet", "stress", "stn":
return nodeconfig.Stressnet
case "localnet":
return nodeconfig.Localnet
case "devnet", "dev":
return nodeconfig.Devnet
default:
return ""
}
}
func getDefaultNetworkConfig(nt nodeconfig.NetworkType) networkConfig {
bn := nodeconfig.GetDefaultBootNodes(nt)
zone := nodeconfig.GetDefaultDNSZone(nt)
port := nodeconfig.GetDefaultDNSPort(nt)
return networkConfig{
NetworkType: string(nt),
BootNodes: bn,
LegacySyncing: false,
DNSZone: zone,
DNSPort: port,
}
}
var p2pFlags = []cli.Flag{
p2pPortFlag,
p2pKeyFileFlag,
legacyKeyFileFlag,
}
var (
p2pPortFlag = cli.IntFlag{
Name: "p2p.port",
Usage: "port to listen for p2p communication",
DefValue: defaultConfig.P2P.Port,
}
p2pKeyFileFlag = cli.StringFlag{
Name: "p2p.keyfile",
Usage: "the p2p key file of the harmony node",
DefValue: defaultConfig.P2P.KeyFile,
}
legacyKeyFileFlag = cli.StringFlag{
Name: "key",
Usage: "the p2p key file of the harmony node",
DefValue: defaultConfig.P2P.KeyFile,
Deprecated: "use --p2p.keyfile",
}
)
func applyP2PFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.IsFlagChanged(cmd, p2pPortFlag) {
config.P2P.Port = cli.GetIntFlagValue(cmd, p2pPortFlag)
}
if cli.IsFlagChanged(cmd, p2pKeyFileFlag) {
config.P2P.KeyFile = cli.GetStringFlagValue(cmd, p2pKeyFileFlag)
} else if cli.IsFlagChanged(cmd, legacyKeyFileFlag) {
config.P2P.KeyFile = cli.GetStringFlagValue(cmd, legacyKeyFileFlag)
}
}
var rpcFlags = []cli.Flag{
rpcEnabledFlag,
rpcIPFlag,
rpcPortFlag,
legacyRPCIPFlag,
legacyPublicRPCFlag,
}
var (
rpcEnabledFlag = cli.BoolFlag{
Name: "http",
Usage: "enable HTTP / RPC requests",
DefValue: defaultConfig.RPC.Enabled,
}
rpcIPFlag = cli.StringFlag{
Name: "http.ip",
Usage: "ip address to listen for RPC calls",
DefValue: defaultConfig.RPC.IP,
}
rpcPortFlag = cli.IntFlag{
Name: "http.port",
Usage: "rpc port to listen for RPC calls",
DefValue: defaultConfig.RPC.Port,
}
legacyRPCIPFlag = cli.StringFlag{
Name: "ip",
Usage: "ip of the node",
DefValue: defaultConfig.RPC.IP,
Deprecated: "use --http.ip",
}
legacyPublicRPCFlag = cli.BoolFlag{
Name: "public_rpc",
Usage: "Enable Public RPC Access (default: false)",
DefValue: defaultConfig.RPC.Enabled,
Deprecated: "please use --http.ip to specify the ip address to listen",
}
)
func applyRPCFlags(cmd *cobra.Command, config *hmyConfig) {
var isRPCSpecified bool
if cli.IsFlagChanged(cmd, rpcIPFlag) {
config.RPC.IP = cli.GetStringFlagValue(cmd, rpcIPFlag)
isRPCSpecified = true
} else if cli.IsFlagChanged(cmd, legacyRPCIPFlag) {
config.RPC.IP = cli.GetStringFlagValue(cmd, legacyRPCIPFlag)
isRPCSpecified = true
}
if cli.IsFlagChanged(cmd, rpcPortFlag) {
config.RPC.Port = cli.GetIntFlagValue(cmd, rpcPortFlag)
isRPCSpecified = true
}
if cli.IsFlagChanged(cmd, rpcEnabledFlag) {
config.RPC.Enabled = cli.GetBoolFlagValue(cmd, rpcEnabledFlag)
} else if isRPCSpecified {
config.RPC.Enabled = true
}
}
Loading…
Cancel
Save