[cmd] add --verbose-prints=config flag

pull/3734/head
Peter Chung 4 years ago
parent ba08520b28
commit de603b3b94
  1. 11
      cmd/harmony/bls.go
  2. 184
      cmd/harmony/config.go
  3. 13
      cmd/harmony/config_migrations.go
  4. 4
      cmd/harmony/config_migrations_test.go
  5. 8
      cmd/harmony/config_test.go
  6. 59
      cmd/harmony/default.go
  7. 67
      cmd/harmony/flags.go
  8. 47
      cmd/harmony/flags_test.go
  9. 50
      cmd/harmony/main.go
  10. 163
      internal/configs/harmony/harmony.go
  11. 4
      internal/configs/node/config.go
  12. 7
      rpc/common/types.go

@ -2,6 +2,7 @@ package main
import (
"fmt"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"os"
"sync"
@ -16,7 +17,7 @@ var (
)
// setupConsensusKeys load bls keys and set the keys to nodeConfig. Return the loaded public keys.
func setupConsensusKeys(hc harmonyConfig, config *nodeconfig.ConfigType) multibls.PublicKeys {
func setupConsensusKeys(hc harmonyconfig.HarmonyConfig, config *nodeconfig.ConfigType) multibls.PublicKeys {
onceLoadBLSKey.Do(func() {
var err error
multiBLSPriKey, err = loadBLSKeys(hc.BLSKeys)
@ -30,7 +31,7 @@ func setupConsensusKeys(hc harmonyConfig, config *nodeconfig.ConfigType) multibl
return multiBLSPriKey.GetPublicKeys()
}
func loadBLSKeys(raw blsConfig) (multibls.PrivateKeys, error) {
func loadBLSKeys(raw harmonyconfig.BlsConfig) (multibls.PrivateKeys, error) {
config, err := parseBLSLoadingConfig(raw)
if err != nil {
return nil, err
@ -48,7 +49,7 @@ func loadBLSKeys(raw blsConfig) (multibls.PrivateKeys, error) {
return keys.Dedup(), err
}
func parseBLSLoadingConfig(raw blsConfig) (blsgen.Config, error) {
func parseBLSLoadingConfig(raw harmonyconfig.BlsConfig) (blsgen.Config, error) {
var (
config blsgen.Config
err error
@ -69,7 +70,7 @@ func parseBLSLoadingConfig(raw blsConfig) (blsgen.Config, error) {
return config, nil
}
func parseBLSPassConfig(cfg blsgen.Config, raw blsConfig) (blsgen.Config, error) {
func parseBLSPassConfig(cfg blsgen.Config, raw harmonyconfig.BlsConfig) (blsgen.Config, error) {
if !raw.PassEnabled {
cfg.PassSrcType = blsgen.PassSrcNil
return blsgen.Config{}, nil
@ -90,7 +91,7 @@ func parseBLSPassConfig(cfg blsgen.Config, raw blsConfig) (blsgen.Config, error)
return cfg, nil
}
func parseBLSKmsConfig(cfg blsgen.Config, raw blsConfig) (blsgen.Config, error) {
func parseBLSKmsConfig(cfg blsgen.Config, raw harmonyconfig.BlsConfig) (blsgen.Config, error) {
if !raw.KMSEnabled {
cfg.AwsCfgSrcType = blsgen.AwsCfgSrcNil
return cfg, nil

@ -9,174 +9,14 @@ import (
"time"
"github.com/harmony-one/harmony/internal/cli"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/pelletier/go-toml"
"github.com/spf13/cobra"
)
// harmonyConfig contains all the configs user can set for running harmony binary. Served as the bridge
// from user set flags to internal node configs. Also user can persist this structure to a toml file
// to avoid inputting all arguments.
type harmonyConfig struct {
Version string
General generalConfig
Network networkConfig
P2P p2pConfig
HTTP httpConfig
WS wsConfig
RPCOpt rpcOptConfig
BLSKeys blsConfig
TxPool txPoolConfig
Pprof pprofConfig
Log logConfig
Sync syncConfig
Sys *sysConfig `toml:",omitempty"`
Consensus *consensusConfig `toml:",omitempty"`
Devnet *devnetConfig `toml:",omitempty"`
Revert *revertConfig `toml:",omitempty"`
Legacy *legacyConfig `toml:",omitempty"`
Prometheus *prometheusConfig `toml:",omitempty"`
DNSSync dnsSync
}
type dnsSync struct {
Port int // replaces: Network.DNSSyncPort
Zone string // replaces: Network.DNSZone
LegacySyncing bool // replaces: Network.LegacySyncing
Client bool // replaces: Sync.LegacyClient
Server bool // replaces: Sync.LegacyServer
ServerPort int
}
type networkConfig struct {
NetworkType string
BootNodes []string
}
type p2pConfig struct {
Port int
IP string
KeyFile string
DHTDataStore *string `toml:",omitempty"`
}
type generalConfig struct {
NodeType string
NoStaking bool
ShardID int
IsArchival bool
IsBeaconArchival bool
IsOffline bool
DataDir string
}
type consensusConfig struct {
MinPeers int
AggregateSig bool
}
type blsConfig struct {
KeyDir string
KeyFiles []string
MaxKeys int
PassEnabled bool
PassSrcType string
PassFile string
SavePassphrase bool
KMSEnabled bool
KMSConfigSrcType string
KMSConfigFile string
}
type txPoolConfig struct {
BlacklistFile string
}
type pprofConfig struct {
Enabled bool
ListenAddr string
}
type logConfig struct {
Folder string
FileName string
RotateSize int
Verbosity int
Context *logContext `toml:",omitempty"`
}
type logContext struct {
IP string
Port int
}
type sysConfig struct {
NtpServer string
}
type httpConfig struct {
Enabled bool
IP string
Port int
RosettaEnabled bool
RosettaPort int
}
type wsConfig struct {
Enabled bool
IP string
Port int
}
type rpcOptConfig struct {
DebugEnabled bool // Enables PrivateDebugService APIs, including the EVM tracer
RateLimterEnabled bool // Enable Rate limiter for RPC
RequestsPerSecond int // for RPC rate limiter
}
type devnetConfig struct {
NumShards int
ShardSize int
HmyNodeSize int
}
// TODO: make `revert` to a separate command
type revertConfig struct {
RevertBeacon bool
RevertTo int
RevertBefore int
}
type legacyConfig struct {
WebHookConfig *string `toml:",omitempty"`
TPBroadcastInvalidTxn *bool `toml:",omitempty"`
}
type prometheusConfig struct {
Enabled bool
IP string
Port int
EnablePush bool
Gateway string
}
type syncConfig struct {
// TODO: Remove this bool after stream sync is fully up.
Enabled bool // enable the stream sync protocol
Downloader bool // start the sync downloader client
Concurrency int // concurrency used for stream sync protocol
MinPeers int // minimum streams to start a sync task.
InitStreams int // minimum streams in bootstrap to start sync loop.
DiscSoftLowCap int // when number of streams is below this value, spin discover during check
DiscHardLowCap int // when removing stream, num is below this value, spin discovery immediately
DiscHighCap int // upper limit of streams in one sync protocol
DiscBatch int // size of each discovery
}
// TODO: use specific type wise validation instead of general string types assertion.
func validateHarmonyConfig(config harmonyConfig) error {
func validateHarmonyConfig(config harmonyconfig.HarmonyConfig) error {
var accepts []string
nodeType := config.General.NodeType
@ -219,7 +59,7 @@ func validateHarmonyConfig(config harmonyConfig) error {
return nil
}
func sanityFixHarmonyConfig(hc *harmonyConfig) {
func sanityFixHarmonyConfig(hc *harmonyconfig.HarmonyConfig) {
// When running sync downloader, set sync.Enabled to true
if hc.Sync.Downloader && !hc.Sync.Enabled {
fmt.Println("Set Sync.Enabled to true when running stream downloader")
@ -237,10 +77,10 @@ func checkStringAccepted(flag string, val string, accepts []string) error {
return fmt.Errorf("unknown arg for %s: %s (%v)", flag, val, acceptsStr)
}
func getDefaultDNSSyncConfig(nt nodeconfig.NetworkType) dnsSync {
func getDefaultDNSSyncConfig(nt nodeconfig.NetworkType) harmonyconfig.DnsSync {
zone := nodeconfig.GetDefaultDNSZone(nt)
port := nodeconfig.GetDefaultDNSPort(nt)
dnsSync := dnsSync{
dnsSync := harmonyconfig.DnsSync{
Port: port,
Zone: zone,
LegacySyncing: false,
@ -263,9 +103,9 @@ func getDefaultDNSSyncConfig(nt nodeconfig.NetworkType) dnsSync {
return dnsSync
}
func getDefaultNetworkConfig(nt nodeconfig.NetworkType) networkConfig {
func getDefaultNetworkConfig(nt nodeconfig.NetworkType) harmonyconfig.NetworkConfig {
bn := nodeconfig.GetDefaultBootNodes(nt)
return networkConfig{
return harmonyconfig.NetworkConfig{
NetworkType: string(nt),
BootNodes: bn,
}
@ -292,7 +132,7 @@ func parseNetworkType(nt string) nodeconfig.NetworkType {
}
}
func getDefaultSyncConfig(nt nodeconfig.NetworkType) syncConfig {
func getDefaultSyncConfig(nt nodeconfig.NetworkType) harmonyconfig.SyncConfig {
switch nt {
case nodeconfig.Mainnet:
return defaultMainnetSyncConfig
@ -380,14 +220,14 @@ func promptConfigUpdate() bool {
}
}
func loadHarmonyConfig(file string) (harmonyConfig, string, error) {
func loadHarmonyConfig(file string) (harmonyconfig.HarmonyConfig, string, error) {
b, err := ioutil.ReadFile(file)
if err != nil {
return harmonyConfig{}, "", err
return harmonyconfig.HarmonyConfig{}, "", err
}
config, migratedVer, err := migrateConf(b)
if err != nil {
return harmonyConfig{}, "", err
return harmonyconfig.HarmonyConfig{}, "", err
}
return config, migratedVer, nil
@ -414,7 +254,7 @@ func updateConfigFile(file string) error {
return nil
}
func writeHarmonyConfigToFile(config harmonyConfig, file string) error {
func writeHarmonyConfigToFile(config harmonyconfig.HarmonyConfig, file string) error {
b, err := toml.Marshal(config)
if err != nil {
return err

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/harmony-one/harmony/api/service/legacysync"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
goversion "github.com/hashicorp/go-version"
"github.com/pelletier/go-toml"
@ -38,31 +39,31 @@ func doMigrations(confVersion string, confTree *toml.Tree) error {
return nil
}
func migrateConf(confBytes []byte) (harmonyConfig, string, error) {
func migrateConf(confBytes []byte) (harmonyconfig.HarmonyConfig, string, error) {
var (
migratedFrom string
)
confTree, err := toml.LoadBytes(confBytes)
if err != nil {
return harmonyConfig{}, "", fmt.Errorf("config file parse error - %s", err.Error())
return harmonyconfig.HarmonyConfig{}, "", fmt.Errorf("config file parse error - %s", err.Error())
}
confVersion, found := confTree.Get("Version").(string)
if !found {
return harmonyConfig{}, "", errors.New("config file invalid - no version entry found")
return harmonyconfig.HarmonyConfig{}, "", errors.New("config file invalid - no version entry found")
}
migratedFrom = confVersion
if confVersion != tomlConfigVersion {
err = doMigrations(confVersion, confTree)
if err != nil {
return harmonyConfig{}, "", err
return harmonyconfig.HarmonyConfig{}, "", err
}
}
// At this point we must be at current config version so
// we can safely unmarshal it
var config harmonyConfig
var config harmonyconfig.HarmonyConfig
if err := confTree.Unmarshal(&config); err != nil {
return harmonyConfig{}, "", err
return harmonyconfig.HarmonyConfig{}, "", err
}
return config, migratedFrom, nil
}

@ -308,7 +308,7 @@ func Test_migrateConf(t *testing.T) {
tests := []struct {
name string
args args
want harmonyConfig
want HarmonyConfig
wantErr bool
}{
{
@ -340,7 +340,7 @@ func Test_migrateConf(t *testing.T) {
args: args{
confBytes: V1_0_4ConfigDownloaderOn,
},
want: func() harmonyConfig {
want: func() HarmonyConfig {
hc := defConf
hc.Sync.Downloader = true
hc.Sync.Enabled = true

@ -11,9 +11,9 @@ import (
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
)
type testCfgOpt func(config *harmonyConfig)
type testCfgOpt func(config *HarmonyConfig)
func makeTestConfig(nt nodeconfig.NetworkType, opt testCfgOpt) harmonyConfig {
func makeTestConfig(nt nodeconfig.NetworkType, opt testCfgOpt) HarmonyConfig {
cfg := getDefaultHmyConfigCopy(nt)
if opt != nil {
opt(&cfg)
@ -133,7 +133,7 @@ func TestPersistConfig(t *testing.T) {
os.MkdirAll(testDir, 0777)
tests := []struct {
config harmonyConfig
config HarmonyConfig
}{
{
config: makeTestConfig("mainnet", nil),
@ -142,7 +142,7 @@ func TestPersistConfig(t *testing.T) {
config: makeTestConfig("devnet", nil),
},
{
config: makeTestConfig("mainnet", func(cfg *harmonyConfig) {
config: makeTestConfig("mainnet", func(cfg *HarmonyConfig) {
consensus := getDefaultConsensusConfigCopy()
cfg.Consensus = &consensus

@ -1,6 +1,9 @@
package main
import nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
import (
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
)
const tomlConfigVersion = "2.0.0"
@ -8,9 +11,9 @@ const (
defNetworkType = nodeconfig.Mainnet
)
var defaultConfig = harmonyConfig{
var defaultConfig = harmonyconfig.HarmonyConfig{
Version: tomlConfigVersion,
General: generalConfig{
General: harmonyconfig.GeneralConfig{
NodeType: "validator",
NoStaking: false,
ShardID: -1,
@ -20,29 +23,29 @@ var defaultConfig = harmonyConfig{
DataDir: "./",
},
Network: getDefaultNetworkConfig(defNetworkType),
P2P: p2pConfig{
P2P: harmonyconfig.P2pConfig{
Port: nodeconfig.DefaultP2PPort,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
},
HTTP: httpConfig{
HTTP: harmonyconfig.HttpConfig{
Enabled: true,
RosettaEnabled: false,
IP: "127.0.0.1",
Port: nodeconfig.DefaultRPCPort,
RosettaPort: nodeconfig.DefaultRosettaPort,
},
WS: wsConfig{
WS: harmonyconfig.WsConfig{
Enabled: true,
IP: "127.0.0.1",
Port: nodeconfig.DefaultWSPort,
},
RPCOpt: rpcOptConfig{
RPCOpt: harmonyconfig.RpcOptConfig{
DebugEnabled: false,
RateLimterEnabled: true,
RequestsPerSecond: nodeconfig.DefaultRPCRateLimit,
},
BLSKeys: blsConfig{
BLSKeys: harmonyconfig.BlsConfig{
KeyDir: "./.hmy/blskeys",
KeyFiles: []string{},
MaxKeys: 10,
@ -55,15 +58,15 @@ var defaultConfig = harmonyConfig{
KMSConfigSrcType: kmsConfigTypeShared,
KMSConfigFile: "",
},
TxPool: txPoolConfig{
TxPool: harmonyconfig.TxPoolConfig{
BlacklistFile: "./.hmy/blacklist.txt",
},
Sync: getDefaultSyncConfig(defNetworkType),
Pprof: pprofConfig{
Pprof: harmonyconfig.PprofConfig{
Enabled: false,
ListenAddr: "127.0.0.1:6060",
},
Log: logConfig{
Log: harmonyconfig.LogConfig{
Folder: "./latest",
FileName: "harmony.log",
RotateSize: 100,
@ -72,33 +75,33 @@ var defaultConfig = harmonyConfig{
DNSSync: getDefaultDNSSyncConfig(defNetworkType),
}
var defaultSysConfig = sysConfig{
var defaultSysConfig = harmonyconfig.SysConfig{
NtpServer: "1.pool.ntp.org",
}
var defaultDevnetConfig = devnetConfig{
var defaultDevnetConfig = harmonyconfig.DevnetConfig{
NumShards: 2,
ShardSize: 10,
HmyNodeSize: 10,
}
var defaultRevertConfig = revertConfig{
var defaultRevertConfig = harmonyconfig.RevertConfig{
RevertBeacon: false,
RevertBefore: 0,
RevertTo: 0,
}
var defaultLogContext = logContext{
var defaultLogContext = harmonyconfig.LogContext{
IP: "127.0.0.1",
Port: 9000,
}
var defaultConsensusConfig = consensusConfig{
var defaultConsensusConfig = harmonyconfig.ConsensusConfig{
MinPeers: 6,
AggregateSig: true,
}
var defaultPrometheusConfig = prometheusConfig{
var defaultPrometheusConfig = harmonyconfig.PrometheusConfig{
Enabled: true,
IP: "0.0.0.0",
Port: 9900,
@ -107,7 +110,7 @@ var defaultPrometheusConfig = prometheusConfig{
}
var (
defaultMainnetSyncConfig = syncConfig{
defaultMainnetSyncConfig = harmonyconfig.SyncConfig{
Enabled: false,
Downloader: false,
Concurrency: 6,
@ -119,7 +122,7 @@ var (
DiscBatch: 8,
}
defaultTestNetSyncConfig = syncConfig{
defaultTestNetSyncConfig = harmonyconfig.SyncConfig{
Enabled: true,
Downloader: false,
Concurrency: 4,
@ -131,7 +134,7 @@ var (
DiscBatch: 8,
}
defaultLocalNetSyncConfig = syncConfig{
defaultLocalNetSyncConfig = harmonyconfig.SyncConfig{
Enabled: true,
Downloader: false,
Concurrency: 4,
@ -143,7 +146,7 @@ var (
DiscBatch: 8,
}
defaultElseSyncConfig = syncConfig{
defaultElseSyncConfig = harmonyconfig.SyncConfig{
Enabled: true,
Downloader: true,
Concurrency: 4,
@ -160,7 +163,7 @@ const (
defaultBroadcastInvalidTx = false
)
func getDefaultHmyConfigCopy(nt nodeconfig.NetworkType) harmonyConfig {
func getDefaultHmyConfigCopy(nt nodeconfig.NetworkType) harmonyconfig.HarmonyConfig {
config := defaultConfig
config.Network = getDefaultNetworkConfig(nt)
@ -174,32 +177,32 @@ func getDefaultHmyConfigCopy(nt nodeconfig.NetworkType) harmonyConfig {
return config
}
func getDefaultSysConfigCopy() sysConfig {
func getDefaultSysConfigCopy() harmonyconfig.SysConfig {
config := defaultSysConfig
return config
}
func getDefaultDevnetConfigCopy() devnetConfig {
func getDefaultDevnetConfigCopy() harmonyconfig.DevnetConfig {
config := defaultDevnetConfig
return config
}
func getDefaultRevertConfigCopy() revertConfig {
func getDefaultRevertConfigCopy() harmonyconfig.RevertConfig {
config := defaultRevertConfig
return config
}
func getDefaultLogContextCopy() logContext {
func getDefaultLogContextCopy() harmonyconfig.LogContext {
config := defaultLogContext
return config
}
func getDefaultConsensusConfigCopy() consensusConfig {
func getDefaultConsensusConfigCopy() harmonyconfig.ConsensusConfig {
config := defaultConsensusConfig
return config
}
func getDefaultPrometheusConfigCopy() prometheusConfig {
func getDefaultPrometheusConfigCopy() harmonyconfig.PrometheusConfig {
config := defaultPrometheusConfig
return config
}

@ -2,6 +2,7 @@ package main
import (
"fmt"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"strconv"
"strings"
@ -133,6 +134,7 @@ var (
logContextIPFlag,
logContextPortFlag,
logVerbosityFlag,
verbosePrintsFlag,
legacyVerbosityFlag,
legacyLogFolderFlag,
@ -297,7 +299,7 @@ func getRootFlags() []cli.Flag {
return flags
}
func applyGeneralFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyGeneralFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, nodeTypeFlag) {
config.General.NodeType = cli.GetStringFlagValue(cmd, nodeTypeFlag)
} else if cli.IsFlagChanged(cmd, legacyNodeTypeFlag) {
@ -434,7 +436,7 @@ func getNetworkType(cmd *cobra.Command) nodeconfig.NetworkType {
return parseNetworkType(raw)
}
func applyDNSSyncFlags(cmd *cobra.Command, cfg *harmonyConfig) {
func applyDNSSyncFlags(cmd *cobra.Command, cfg *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, dnsZoneFlag) {
cfg.DNSSync.Zone = cli.GetStringFlagValue(cmd, dnsZoneFlag)
} else if cli.IsFlagChanged(cmd, legacyDNSZoneFlag) {
@ -470,7 +472,7 @@ func applyDNSSyncFlags(cmd *cobra.Command, cfg *harmonyConfig) {
}
func applyNetworkFlags(cmd *cobra.Command, cfg *harmonyConfig) {
func applyNetworkFlags(cmd *cobra.Command, cfg *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, bootNodeFlag) {
cfg.Network.BootNodes = cli.GetStringSliceFlagValue(cmd, bootNodeFlag)
}
@ -507,7 +509,7 @@ var (
}
)
func applyP2PFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyP2PFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, p2pPortFlag) {
config.P2P.Port = cli.GetIntFlagValue(cmd, p2pPortFlag)
}
@ -559,7 +561,7 @@ var (
}
)
func applyHTTPFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyHTTPFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
var isRPCSpecified, isRosettaSpecified bool
if cli.IsFlagChanged(cmd, httpIPFlag) {
@ -610,7 +612,7 @@ var (
}
)
func applyWSFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyWSFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, wsEnabledFlag) {
config.WS.Enabled = cli.GetBoolFlagValue(cmd, wsEnabledFlag)
}
@ -644,7 +646,7 @@ var (
}
)
func applyRPCOptFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyRPCOptFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, rpcDebugEnabledFlag) {
config.RPCOpt.DebugEnabled = cli.GetBoolFlagValue(cmd, rpcDebugEnabledFlag)
}
@ -749,7 +751,7 @@ var (
}
)
func applyBLSFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyBLSFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, blsDirFlag) {
config.BLSKeys.KeyDir = cli.GetStringFlagValue(cmd, blsDirFlag)
} else if cli.IsFlagChanged(cmd, legacyBLSFolderFlag) {
@ -777,7 +779,7 @@ func applyBLSFlags(cmd *cobra.Command, config *harmonyConfig) {
}
}
func applyBLSPassFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyBLSPassFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
var passFileSpecified bool
if cli.IsFlagChanged(cmd, passEnabledFlag) {
@ -797,7 +799,7 @@ func applyBLSPassFlags(cmd *cobra.Command, config *harmonyConfig) {
}
}
func applyKMSFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyKMSFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
var fileSpecified bool
if cli.IsFlagChanged(cmd, kmsEnabledFlag) {
@ -814,7 +816,7 @@ func applyKMSFlags(cmd *cobra.Command, config *harmonyConfig) {
}
}
func applyLegacyBLSPassFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyLegacyBLSPassFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, legacyBLSPassFlag) {
val := cli.GetStringFlagValue(cmd, legacyBLSPassFlag)
legacyApplyBLSPassVal(val, config)
@ -824,14 +826,14 @@ func applyLegacyBLSPassFlags(cmd *cobra.Command, config *harmonyConfig) {
}
}
func applyLegacyKMSFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyLegacyKMSFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, legacyKMSConfigSourceFlag) {
val := cli.GetStringFlagValue(cmd, legacyKMSConfigSourceFlag)
legacyApplyKMSSourceVal(val, config)
}
}
func legacyApplyBLSPassVal(src string, config *harmonyConfig) {
func legacyApplyBLSPassVal(src string, config *harmonyconfig.HarmonyConfig) {
methodArgs := strings.SplitN(src, ":", 2)
method := methodArgs[0]
@ -852,7 +854,7 @@ func legacyApplyBLSPassVal(src string, config *harmonyConfig) {
}
}
func legacyApplyKMSSourceVal(src string, config *harmonyConfig) {
func legacyApplyKMSSourceVal(src string, config *harmonyconfig.HarmonyConfig) {
methodArgs := strings.SplitN(src, ":", 2)
method := methodArgs[0]
@ -903,7 +905,7 @@ var (
}
)
func applyConsensusFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyConsensusFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if config.Consensus == nil && cli.HasFlagsChanged(cmd, consensusValidFlags) {
cfg := getDefaultConsensusConfigCopy()
config.Consensus = &cfg
@ -935,7 +937,7 @@ var (
}
)
func applyTxPoolFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyTxPoolFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, tpBlacklistFileFlag) {
config.TxPool.BlacklistFile = cli.GetStringFlagValue(cmd, tpBlacklistFileFlag)
} else if cli.IsFlagChanged(cmd, legacyTPBlacklistFileFlag) {
@ -957,7 +959,7 @@ var (
}
)
func applyPprofFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyPprofFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
var pprofSet bool
if cli.IsFlagChanged(cmd, pprofListenAddrFlag) {
config.Pprof.ListenAddr = cli.GetStringFlagValue(cmd, pprofListenAddrFlag)
@ -993,6 +995,10 @@ var (
Usage: "logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail",
DefValue: defaultConfig.Log.Verbosity,
}
verbosePrintsFlag = cli.StringSliceFlag{
Name: "verbose-prints",
Usage: "verbose prints, available options: config",
}
// TODO: remove context (this shall not be in the log)
logContextIPFlag = cli.StringFlag{
Name: "log.ctx.ip",
@ -1026,7 +1032,7 @@ var (
}
)
func applyLogFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyLogFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, logFolderFlag) {
config.Log.Folder = cli.GetStringFlagValue(cmd, logFolderFlag)
} else if cli.IsFlagChanged(cmd, legacyLogFolderFlag) {
@ -1049,6 +1055,15 @@ func applyLogFlags(cmd *cobra.Command, config *harmonyConfig) {
config.Log.Verbosity = cli.GetIntFlagValue(cmd, legacyVerbosityFlag)
}
if cli.IsFlagChanged(cmd, verbosePrintsFlag) {
verbosePrintsSlice := cli.GetStringSliceFlagValue(cmd, verbosePrintsFlag)
verbosePrintsMap := make(map[string]bool, 0)
for _, verbosePrint := range verbosePrintsSlice {
verbosePrintsMap[verbosePrint] = true
}
config.Log.VerbosePrints = verbosePrintsMap
}
if cli.HasFlagsChanged(cmd, []cli.Flag{logContextIPFlag, logContextPortFlag}) {
ctx := getDefaultLogContextCopy()
config.Log.Context = &ctx
@ -1071,7 +1086,7 @@ var (
}
)
func applySysFlags(cmd *cobra.Command, config *harmonyConfig) {
func applySysFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.HasFlagsChanged(cmd, sysFlags) || config.Sys == nil {
cfg := getDefaultSysConfigCopy()
config.Sys = &cfg
@ -1121,7 +1136,7 @@ var (
}
)
func applyDevnetFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyDevnetFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.HasFlagsChanged(cmd, devnetFlags) && config.Devnet == nil {
cfg := getDefaultDevnetConfigCopy()
config.Devnet = &cfg
@ -1196,7 +1211,7 @@ var (
}
)
func applyRevertFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyRevertFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.HasFlagsChanged(cmd, revertFlags) {
cfg := getDefaultRevertConfigCopy()
config.Revert = &cfg
@ -1261,7 +1276,7 @@ var (
)
// Note: this function need to be called before parse other flags
func applyLegacyMiscFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyLegacyMiscFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, legacyPortFlag) {
legacyPort := cli.GetIntFlagValue(cmd, legacyPortFlag)
config.P2P.Port = legacyPort
@ -1296,7 +1311,7 @@ func applyLegacyMiscFlags(cmd *cobra.Command, config *harmonyConfig) {
logPort := cli.GetIntFlagValue(cmd, legacyPortFlag)
config.Log.FileName = fmt.Sprintf("validator-%v-%v.log", logIP, logPort)
logCtx := &logContext{
logCtx := &harmonyconfig.LogContext{
IP: logIP,
Port: logPort,
}
@ -1304,7 +1319,7 @@ func applyLegacyMiscFlags(cmd *cobra.Command, config *harmonyConfig) {
}
if cli.HasFlagsChanged(cmd, []cli.Flag{legacyWebHookConfigFlag, legacyTPBroadcastInvalidTxFlag}) {
config.Legacy = &legacyConfig{}
config.Legacy = &harmonyconfig.LegacyConfig{}
if cli.IsFlagChanged(cmd, legacyWebHookConfigFlag) {
val := cli.GetStringFlagValue(cmd, legacyWebHookConfigFlag)
config.Legacy.WebHookConfig = &val
@ -1345,7 +1360,7 @@ var (
}
)
func applyPrometheusFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyPrometheusFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if config.Prometheus == nil {
cfg := getDefaultPrometheusConfigCopy()
config.Prometheus = &cfg
@ -1426,7 +1441,7 @@ var (
)
// applySyncFlags apply the sync flags.
func applySyncFlags(cmd *cobra.Command, config *harmonyConfig) {
func applySyncFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, syncStreamEnabledFlag) {
config.Sync.Enabled = cli.GetBoolFlagValue(cmd, syncStreamEnabledFlag)
}

@ -18,7 +18,7 @@ var (
func TestHarmonyFlags(t *testing.T) {
tests := []struct {
argStr string
expConfig harmonyConfig
expConfig HarmonyConfig
}{
{
// running staking command from legacy node.sh
@ -29,7 +29,7 @@ func TestHarmonyFlags(t *testing.T) {
"et --dns_zone=t.hmny.io --blacklist=./.hmy/blacklist.txt --min_peers=6 --max_bls_keys_per_node=" +
"10 --broadcast_invalid_tx=true --verbosity=3 --is_archival=false --shard_id=-1 --staking=true -" +
"-aws-config-source file:config.json",
expConfig: harmonyConfig{
expConfig: HarmonyConfig{
Version: tomlConfigVersion,
General: generalConfig{
NodeType: "validator",
@ -229,12 +229,12 @@ func TestGeneralFlags(t *testing.T) {
func TestNetworkFlags(t *testing.T) {
tests := []struct {
args []string
expConfig harmonyConfig
expConfig HarmonyConfig
expErr error
}{
{
args: []string{},
expConfig: harmonyConfig{
expConfig: HarmonyConfig{
Network: networkConfig{
NetworkType: defNetworkType,
BootNodes: nodeconfig.GetDefaultBootNodes(defNetworkType),
@ -243,7 +243,7 @@ func TestNetworkFlags(t *testing.T) {
},
{
args: []string{"-n", "stn"},
expConfig: harmonyConfig{
expConfig: HarmonyConfig{
Network: networkConfig{
NetworkType: nodeconfig.Stressnet,
BootNodes: nodeconfig.GetDefaultBootNodes(nodeconfig.Stressnet),
@ -254,7 +254,7 @@ func TestNetworkFlags(t *testing.T) {
{
args: []string{"--network", "stk", "--bootnodes", "1,2,3,4", "--dns.zone", "8.8.8.8",
"--dns.port", "9001", "--dns.server-port", "9002"},
expConfig: harmonyConfig{
expConfig: HarmonyConfig{
Network: networkConfig{
NetworkType: "pangaea",
BootNodes: []string{"1", "2", "3", "4"},
@ -271,7 +271,7 @@ func TestNetworkFlags(t *testing.T) {
{
args: []string{"--network_type", "stk", "--bootnodes", "1,2,3,4", "--dns_zone", "8.8.8.8",
"--dns_port", "9001"},
expConfig: harmonyConfig{
expConfig: HarmonyConfig{
Network: networkConfig{
NetworkType: "pangaea",
BootNodes: []string{"1", "2", "3", "4"},
@ -287,7 +287,7 @@ func TestNetworkFlags(t *testing.T) {
},
{
args: []string{"--dns=false"},
expConfig: harmonyConfig{
expConfig: HarmonyConfig{
Network: networkConfig{
NetworkType: defNetworkType,
BootNodes: nodeconfig.GetDefaultBootNodes(defNetworkType),
@ -307,7 +307,7 @@ func TestNetworkFlags(t *testing.T) {
neededFlags := make([]cli.Flag, 0)
neededFlags = append(neededFlags, networkFlags...)
neededFlags = append(neededFlags, dnsSyncFlags...)
ts := newFlagTestSuite(t, neededFlags, func(cmd *cobra.Command, config *harmonyConfig) {
ts := newFlagTestSuite(t, neededFlags, func(cmd *cobra.Command, config *HarmonyConfig) {
// This is the network related logic in function getHarmonyConfig
nt := getNetworkType(cmd)
config.Network = getDefaultNetworkConfig(nt)
@ -367,7 +367,7 @@ func TestP2PFlags(t *testing.T) {
}
for i, test := range tests {
ts := newFlagTestSuite(t, append(p2pFlags, legacyMiscFlags...),
func(cmd *cobra.Command, config *harmonyConfig) {
func(cmd *cobra.Command, config *HarmonyConfig) {
applyLegacyMiscFlags(cmd, config)
applyP2PFlags(cmd, config)
},
@ -451,7 +451,7 @@ func TestRPCFlags(t *testing.T) {
}
for i, test := range tests {
ts := newFlagTestSuite(t, append(httpFlags, legacyMiscFlags...),
func(cmd *cobra.Command, config *harmonyConfig) {
func(cmd *cobra.Command, config *HarmonyConfig) {
applyLegacyMiscFlags(cmd, config)
applyHTTPFlags(cmd, config)
},
@ -510,7 +510,7 @@ func TestWSFlags(t *testing.T) {
}
for i, test := range tests {
ts := newFlagTestSuite(t, append(wsFlags, legacyMiscFlags...),
func(cmd *cobra.Command, config *harmonyConfig) {
func(cmd *cobra.Command, config *HarmonyConfig) {
applyLegacyMiscFlags(cmd, config)
applyWSFlags(cmd, config)
},
@ -852,10 +852,21 @@ func TestLogFlags(t *testing.T) {
},
},
},
{
args: []string{"--verbose-prints", "config"},
expConfig: logConfig{
Folder: defaultConfig.Log.Folder,
FileName: defaultConfig.Log.FileName,
RotateSize: defaultConfig.Log.RotateSize,
Verbosity: defaultConfig.Log.Verbosity,
VerbosePrints: []string{"config"},
Context: nil,
},
},
}
for i, test := range tests {
ts := newFlagTestSuite(t, append(logFlags, legacyMiscFlags...),
func(cmd *cobra.Command, config *harmonyConfig) {
func(cmd *cobra.Command, config *HarmonyConfig) {
applyLegacyMiscFlags(cmd, config)
applyLogFlags(cmd, config)
},
@ -1048,7 +1059,7 @@ func TestDNSSyncFlags(t *testing.T) {
}
for i, test := range tests {
ts := newFlagTestSuite(t, dnsSyncFlags, func(command *cobra.Command, config *harmonyConfig) {
ts := newFlagTestSuite(t, dnsSyncFlags, func(command *cobra.Command, config *HarmonyConfig) {
config.Network.NetworkType = test.network
applyDNSSyncFlags(command, config)
})
@ -1097,7 +1108,7 @@ func TestSyncFlags(t *testing.T) {
},
}
for i, test := range tests {
ts := newFlagTestSuite(t, syncFlags, func(command *cobra.Command, config *harmonyConfig) {
ts := newFlagTestSuite(t, syncFlags, func(command *cobra.Command, config *HarmonyConfig) {
applySyncFlags(command, config)
})
hc, err := ts.run(test.args)
@ -1120,10 +1131,10 @@ type flagTestSuite struct {
t *testing.T
cmd *cobra.Command
hc harmonyConfig
hc HarmonyConfig
}
func newFlagTestSuite(t *testing.T, flags []cli.Flag, applyFlags func(*cobra.Command, *harmonyConfig)) *flagTestSuite {
func newFlagTestSuite(t *testing.T, flags []cli.Flag, applyFlags func(*cobra.Command, *HarmonyConfig)) *flagTestSuite {
cli.SetParseErrorHandle(func(err error) { t.Fatal(err) })
ts := &flagTestSuite{hc: getDefaultHmyConfigCopy(defNetworkType)}
@ -1137,7 +1148,7 @@ func newFlagTestSuite(t *testing.T, flags []cli.Flag, applyFlags func(*cobra.Com
return ts
}
func (ts *flagTestSuite) run(args []string) (harmonyConfig, error) {
func (ts *flagTestSuite) run(args []string) (HarmonyConfig, error) {
ts.cmd.SetArgs(args)
err := ts.cmd.Execute()
return ts.hc, err

@ -1,7 +1,10 @@
package main
import (
"encoding/json"
"fmt"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
rpc_common "github.com/harmony-one/harmony/rpc/common"
"io/ioutil"
"math/big"
"math/rand"
@ -158,9 +161,9 @@ func raiseFdLimits() error {
return nil
}
func getHarmonyConfig(cmd *cobra.Command) (harmonyConfig, error) {
func getHarmonyConfig(cmd *cobra.Command) (harmonyconfig.HarmonyConfig, error) {
var (
config harmonyConfig
config harmonyconfig.HarmonyConfig
err error
migratedFrom string
configFile string
@ -175,7 +178,7 @@ func getHarmonyConfig(cmd *cobra.Command) (harmonyConfig, error) {
isUsingDefault = true
}
if err != nil {
return harmonyConfig{}, err
return harmonyconfig.HarmonyConfig{}, err
}
if migratedFrom != defaultConfig.Version && !isUsingDefault {
fmt.Printf("Old config version detected %s\n",
@ -199,13 +202,13 @@ func getHarmonyConfig(cmd *cobra.Command) (harmonyConfig, error) {
applyRootFlags(cmd, &config)
if err := validateHarmonyConfig(config); err != nil {
return harmonyConfig{}, err
return harmonyconfig.HarmonyConfig{}, err
}
sanityFixHarmonyConfig(&config)
return config, nil
}
func applyRootFlags(cmd *cobra.Command, config *harmonyConfig) {
func applyRootFlags(cmd *cobra.Command, config * harmonyconfig.HarmonyConfig) {
// Misc flags shall be applied first since legacy ip / port is overwritten
// by new ip / port flags
applyLegacyMiscFlags(cmd, config)
@ -228,7 +231,7 @@ func applyRootFlags(cmd *cobra.Command, config *harmonyConfig) {
applySyncFlags(cmd, config)
}
func setupNodeLog(config harmonyConfig) {
func setupNodeLog(config harmonyconfig.HarmonyConfig) {
logPath := filepath.Join(config.Log.Folder, config.Log.FileName)
rotateSize := config.Log.RotateSize
verbosity := config.Log.Verbosity
@ -242,7 +245,7 @@ func setupNodeLog(config harmonyConfig) {
}
}
func setupPprof(config harmonyConfig) {
func setupPprof(config harmonyconfig.HarmonyConfig) {
enabled := config.Pprof.Enabled
addr := config.Pprof.ListenAddr
@ -253,7 +256,7 @@ func setupPprof(config harmonyConfig) {
}
}
func setupNodeAndRun(hc harmonyConfig) {
func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) {
var err error
nodeconfigSetShardSchedule(hc)
@ -294,6 +297,17 @@ func setupNodeAndRun(hc harmonyConfig) {
os.Exit(1)
}
if hc.Log.VerbosePrints["config"] {
if cfgJson, err := json.MarshalIndent(rpc_common.Config{
HarmonyConfig: hc,
NodeConfig: *nodeConfig,
}, "", " "); err != nil {
panic(err)
} else {
println(string(cfgJson))
}
}
// Update ethereum compatible chain ids
params.UpdateEthChainIDByShard(nodeConfig.ShardID)
@ -443,7 +457,7 @@ func setupNodeAndRun(hc harmonyConfig) {
select {}
}
func nodeconfigSetShardSchedule(config harmonyConfig) {
func nodeconfigSetShardSchedule(config harmonyconfig.HarmonyConfig) {
switch config.Network.NetworkType {
case nodeconfig.Mainnet:
shard.Schedule = shardingconfig.MainnetSchedule
@ -458,7 +472,7 @@ func nodeconfigSetShardSchedule(config harmonyConfig) {
case nodeconfig.Stressnet:
shard.Schedule = shardingconfig.StressNetSchedule
case nodeconfig.Devnet:
var dnConfig devnetConfig
var dnConfig harmonyconfig.DevnetConfig
if config.Devnet != nil {
dnConfig = *config.Devnet
} else {
@ -486,7 +500,7 @@ func findAccountsByPubKeys(config shardingconfig.Instance, pubKeys multibls.Publ
}
}
func setupLegacyNodeAccount(hc harmonyConfig) error {
func setupLegacyNodeAccount(hc harmonyconfig.HarmonyConfig) error {
genesisShardingConfig := shard.Schedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch))
multiBLSPubKey := setupConsensusKeys(hc, nodeconfig.GetDefaultConfig())
@ -518,7 +532,7 @@ func setupLegacyNodeAccount(hc harmonyConfig) error {
return nil
}
func setupStakingNodeAccount(hc harmonyConfig) error {
func setupStakingNodeAccount(hc harmonyconfig.HarmonyConfig) error {
pubKeys := setupConsensusKeys(hc, nodeconfig.GetDefaultConfig())
shardID, err := nodeconfig.GetDefaultConfig().ShardIDFromConsensusKey()
if err != nil {
@ -539,7 +553,7 @@ func setupStakingNodeAccount(hc harmonyConfig) error {
return nil
}
func createGlobalConfig(hc harmonyConfig) (*nodeconfig.ConfigType, error) {
func createGlobalConfig(hc harmonyconfig.HarmonyConfig) (*nodeconfig.ConfigType, error) {
var err error
if len(initialAccounts) == 0 {
@ -604,7 +618,7 @@ func createGlobalConfig(hc harmonyConfig) (*nodeconfig.ConfigType, error) {
return nodeConfig, nil
}
func setupConsensusAndNode(hc harmonyConfig, nodeConfig *nodeconfig.ConfigType) *node.Node {
func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfig.ConfigType) *node.Node {
// Consensus object.
// TODO: consensus object shouldn't start here
decider := quorum.NewDecider(quorum.SuperMajorityVote, uint32(hc.General.ShardID))
@ -621,7 +635,7 @@ func setupConsensusAndNode(hc harmonyConfig, nodeConfig *nodeconfig.ConfigType)
os.Exit(1)
}
// Parse minPeers from harmonyConfig
// Parse minPeers from harmonyconfig.HarmonyConfig
var minPeers int
var aggregateSig bool
if hc.Consensus != nil {
@ -712,7 +726,7 @@ func setupConsensusAndNode(hc harmonyConfig, nodeConfig *nodeconfig.ConfigType)
return currentNode
}
func setupPrometheusService(node *node.Node, hc harmonyConfig, sid uint32) {
func setupPrometheusService(node *node.Node, hc harmonyconfig.HarmonyConfig, sid uint32) {
prometheusConfig := prometheus.Config{
Enabled: hc.Prometheus.Enabled,
IP: hc.Prometheus.IP,
@ -729,7 +743,7 @@ func setupPrometheusService(node *node.Node, hc harmonyConfig, sid uint32) {
node.RegisterService(service.Prometheus, p)
}
func setupSyncService(node *node.Node, host p2p.Host, hc harmonyConfig) {
func setupSyncService(node *node.Node, host p2p.Host, hc harmonyconfig.HarmonyConfig) {
blockchains := []*core.BlockChain{node.Blockchain()}
if !node.IsRunningBeaconChain() {
blockchains = append(blockchains, node.Beaconchain())
@ -762,7 +776,7 @@ func setupSyncService(node *node.Node, host p2p.Host, hc harmonyConfig) {
node.Consensus.SetDownloader(d)
}
func setupBlacklist(hc harmonyConfig) (map[ethCommon.Address]struct{}, error) {
func setupBlacklist(hc harmonyconfig.HarmonyConfig) (map[ethCommon.Address]struct{}, error) {
utils.Logger().Debug().Msgf("Using blacklist file at `%s`", hc.TxPool.BlacklistFile)
dat, err := ioutil.ReadFile(hc.TxPool.BlacklistFile)
if err != nil {

@ -0,0 +1,163 @@
package harmony
// HarmonyConfig contains all the configs user can set for running harmony binary. Served as the bridge
// from user set flags to internal node configs. Also user can persist this structure to a toml file
// to avoid inputting all arguments.
type HarmonyConfig struct {
Version string
General GeneralConfig
Network NetworkConfig
P2P P2pConfig
HTTP HttpConfig
WS WsConfig
RPCOpt RpcOptConfig
BLSKeys BlsConfig
TxPool TxPoolConfig
Pprof PprofConfig
Log LogConfig
Sync SyncConfig
Sys *SysConfig `toml:",omitempty"`
Consensus *ConsensusConfig `toml:",omitempty"`
Devnet *DevnetConfig `toml:",omitempty"`
Revert *RevertConfig `toml:",omitempty"`
Legacy *LegacyConfig `toml:",omitempty"`
Prometheus *PrometheusConfig `toml:",omitempty"`
DNSSync DnsSync
}
type DnsSync struct {
Port int // replaces: Network.DNSSyncPort
Zone string // replaces: Network.DNSZone
LegacySyncing bool // replaces: Network.LegacySyncing
Client bool // replaces: Sync.LegacyClient
Server bool // replaces: Sync.LegacyServer
ServerPort int
}
type NetworkConfig struct {
NetworkType string
BootNodes []string
}
type P2pConfig struct {
Port int
IP string
KeyFile string
DHTDataStore *string `toml:",omitempty"`
}
type GeneralConfig struct {
NodeType string
NoStaking bool
ShardID int
IsArchival bool
IsBeaconArchival bool
IsOffline bool
DataDir string
}
type ConsensusConfig struct {
MinPeers int
AggregateSig bool
}
type BlsConfig struct {
KeyDir string
KeyFiles []string
MaxKeys int
PassEnabled bool
PassSrcType string
PassFile string
SavePassphrase bool
KMSEnabled bool
KMSConfigSrcType string
KMSConfigFile string
}
type TxPoolConfig struct {
BlacklistFile string
}
type PprofConfig struct {
Enabled bool
ListenAddr string
}
type LogConfig struct {
Folder string
FileName string
RotateSize int
Verbosity int
VerbosePrints map[string]bool
Context *LogContext `toml:",omitempty"`
}
type LogContext struct {
IP string
Port int
}
type SysConfig struct {
NtpServer string
}
type HttpConfig struct {
Enabled bool
IP string
Port int
RosettaEnabled bool
RosettaPort int
}
type WsConfig struct {
Enabled bool
IP string
Port int
}
type RpcOptConfig struct {
DebugEnabled bool // Enables PrivateDebugService APIs, including the EVM tracer
RateLimterEnabled bool // Enable Rate limiter for RPC
RequestsPerSecond int // for RPC rate limiter
}
type DevnetConfig struct {
NumShards int
ShardSize int
HmyNodeSize int
}
// TODO: make `revert` to a separate command
type RevertConfig struct {
RevertBeacon bool
RevertTo int
RevertBefore int
}
type LegacyConfig struct {
WebHookConfig *string `toml:",omitempty"`
TPBroadcastInvalidTxn *bool `toml:",omitempty"`
}
type PrometheusConfig struct {
Enabled bool
IP string
Port int
EnablePush bool
Gateway string
}
type SyncConfig struct {
// TODO: Remove this bool after stream sync is fully up.
Enabled bool // enable the stream sync protocol
Downloader bool // start the sync downloader client
Concurrency int // concurrency used for stream sync protocol
MinPeers int // minimum streams to start a sync task.
InitStreams int // minimum streams in bootstrap to start sync loop.
DiscSoftLowCap int // when number of streams is below this value, spin discover during check
DiscHardLowCap int // when removing stream, num is below this value, spin discovery immediately
DiscHighCap int // upper limit of streams in one sync protocol
DiscBatch int // size of each discovery
}

@ -83,8 +83,8 @@ type ConfigType struct {
Downloader bool // Whether stream downloader is running; TODO: remove this after sync up
NtpServer string
StringRole string
P2PPriKey p2p_crypto.PrivKey
ConsensusPriKey multibls.PrivateKeys
P2PPriKey p2p_crypto.PrivKey `json:"-"`
ConsensusPriKey multibls.PrivateKeys `json:"-"`
// Database directory
DBDir string
networkType NetworkType

@ -2,6 +2,8 @@ package common
import (
"encoding/json"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/params"
"github.com/libp2p/go-libp2p-core/peer"
@ -80,3 +82,8 @@ type NodePeerInfo struct {
BlockedPeers []peer.ID `json:"blocked-peers"`
P []P `json:"connected-peers"`
}
type Config struct {
HarmonyConfig harmonyconfig.HarmonyConfig
NodeConfig nodeconfig.ConfigType
}
Loading…
Cancel
Save