Merge pull request #3734 from touhonoob/bounty-41

[feature] expose all configuration variables and values
pull/3777/head
Leo Chen 3 years ago committed by GitHub
commit 0976cc9859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      cmd/harmony/bls.go
  2. 184
      cmd/harmony/config.go
  3. 23
      cmd/harmony/config_migrations.go
  4. 6
      cmd/harmony/config_migrations_test.go
  5. 12
      cmd/harmony/config_test.go
  6. 64
      cmd/harmony/default.go
  7. 65
      cmd/harmony/flags.go
  8. 233
      cmd/harmony/flags_test.go
  9. 49
      cmd/harmony/main.go
  10. 1
      hmy/hmy.go
  11. 186
      internal/configs/harmony/harmony.go
  12. 4
      internal/configs/node/config.go
  13. 8
      node/api.go
  14. 4
      node/node.go
  15. 6
      node/node_handler_test.go
  16. 2
      node/node_newblock_test.go
  17. 4
      node/node_test.go
  18. 9
      rpc/common/types.go
  19. 7
      rpc/debug.go

@ -5,6 +5,8 @@ import (
"os"
"sync"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/harmony-one/harmony/internal/blsgen"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/multibls"
@ -16,7 +18,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 +32,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 +50,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 +71,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 +92,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
}
@ -156,4 +157,14 @@ func init() {
confTree.Set("Version", "2.0.0")
return confTree
}
migrations["2.0.0"] = func(confTree *toml.Tree) *toml.Tree {
// Legacy conf missing fields
if confTree.Get("Log.VerbosePrints") == nil {
confTree.Set("Log.VerbosePrints", defaultConfig.Log.VerbosePrints)
}
confTree.Set("Version", "2.1.0")
return confTree
}
}

@ -4,6 +4,8 @@ import (
"reflect"
"testing"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
)
@ -308,7 +310,7 @@ func Test_migrateConf(t *testing.T) {
tests := []struct {
name string
args args
want harmonyConfig
want harmonyconfig.HarmonyConfig
wantErr bool
}{
{
@ -340,7 +342,7 @@ func Test_migrateConf(t *testing.T) {
args: args{
confBytes: V1_0_4ConfigDownloaderOn,
},
want: func() harmonyConfig {
want: func() harmonyconfig.HarmonyConfig {
hc := defConf
hc.Sync.Downloader = true
hc.Sync.Enabled = true

@ -8,12 +8,14 @@ import (
"reflect"
"testing"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
)
type testCfgOpt func(config *harmonyConfig)
type testCfgOpt func(config *harmonyconfig.HarmonyConfig)
func makeTestConfig(nt nodeconfig.NetworkType, opt testCfgOpt) harmonyConfig {
func makeTestConfig(nt nodeconfig.NetworkType, opt testCfgOpt) harmonyconfig.HarmonyConfig {
cfg := getDefaultHmyConfigCopy(nt)
if opt != nil {
opt(&cfg)
@ -133,7 +135,7 @@ func TestPersistConfig(t *testing.T) {
os.MkdirAll(testDir, 0777)
tests := []struct {
config harmonyConfig
config harmonyconfig.HarmonyConfig
}{
{
config: makeTestConfig("mainnet", nil),
@ -142,7 +144,7 @@ func TestPersistConfig(t *testing.T) {
config: makeTestConfig("devnet", nil),
},
{
config: makeTestConfig("mainnet", func(cfg *harmonyConfig) {
config: makeTestConfig("mainnet", func(cfg *harmonyconfig.HarmonyConfig) {
consensus := getDefaultConsensusConfigCopy()
cfg.Consensus = &consensus
@ -153,7 +155,7 @@ func TestPersistConfig(t *testing.T) {
cfg.Revert = &revert
webHook := "web hook"
cfg.Legacy = &legacyConfig{
cfg.Legacy = &harmonyconfig.LegacyConfig{
WebHookConfig: &webHook,
TPBroadcastInvalidTxn: &trueBool,
}

@ -1,16 +1,19 @@
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"
const tomlConfigVersion = "2.1.0"
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,50 +58,53 @@ 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,
Verbosity: 3,
VerbosePrints: harmonyconfig.LogVerbosePrints{
Config: false,
},
},
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 +113,7 @@ var defaultPrometheusConfig = prometheusConfig{
}
var (
defaultMainnetSyncConfig = syncConfig{
defaultMainnetSyncConfig = harmonyconfig.SyncConfig{
Enabled: false,
Downloader: false,
Concurrency: 6,
@ -119,7 +125,7 @@ var (
DiscBatch: 8,
}
defaultTestNetSyncConfig = syncConfig{
defaultTestNetSyncConfig = harmonyconfig.SyncConfig{
Enabled: true,
Downloader: false,
Concurrency: 4,
@ -131,7 +137,7 @@ var (
DiscBatch: 8,
}
defaultLocalNetSyncConfig = syncConfig{
defaultLocalNetSyncConfig = harmonyconfig.SyncConfig{
Enabled: true,
Downloader: false,
Concurrency: 4,
@ -143,7 +149,7 @@ var (
DiscBatch: 8,
}
defaultElseSyncConfig = syncConfig{
defaultElseSyncConfig = harmonyconfig.SyncConfig{
Enabled: true,
Downloader: true,
Concurrency: 4,
@ -160,7 +166,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 +180,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
}

@ -5,6 +5,8 @@ import (
"strconv"
"strings"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/harmony-one/harmony/api/service/legacysync"
"github.com/harmony-one/harmony/internal/cli"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
@ -133,6 +135,7 @@ var (
logContextIPFlag,
logContextPortFlag,
logVerbosityFlag,
logVerbosePrintsFlag,
legacyVerbosityFlag,
legacyLogFolderFlag,
@ -297,7 +300,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 +437,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 +473,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 +510,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 +562,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 +613,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 +647,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 +752,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 +780,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 +800,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 +817,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 +827,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 +855,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 +906,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 +938,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 +960,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 +996,11 @@ var (
Usage: "logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail",
DefValue: defaultConfig.Log.Verbosity,
}
logVerbosePrintsFlag = cli.StringSliceFlag{
Name: "log.verbose-prints",
Usage: "debugging feature. to print verbose internal objects as JSON in log file. available internal objects: config",
DefValue: []string{},
}
// TODO: remove context (this shall not be in the log)
logContextIPFlag = cli.StringFlag{
Name: "log.ctx.ip",
@ -1026,7 +1034,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 +1057,11 @@ func applyLogFlags(cmd *cobra.Command, config *harmonyConfig) {
config.Log.Verbosity = cli.GetIntFlagValue(cmd, legacyVerbosityFlag)
}
if cli.IsFlagChanged(cmd, logVerbosePrintsFlag) {
verbosePrintsFlagSlice := cli.GetStringSliceFlagValue(cmd, logVerbosePrintsFlag)
config.Log.VerbosePrints = harmonyconfig.FlagSliceToLogVerbosePrints(verbosePrintsFlagSlice)
}
if cli.HasFlagsChanged(cmd, []cli.Flag{logContextIPFlag, logContextPortFlag}) {
ctx := getDefaultLogContextCopy()
config.Log.Context = &ctx
@ -1071,7 +1084,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 +1134,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 +1209,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 +1274,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 +1309,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 +1317,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 +1358,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 +1439,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)
}

@ -6,6 +6,8 @@ import (
"strings"
"testing"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/harmony-one/harmony/internal/cli"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/spf13/cobra"
@ -18,7 +20,7 @@ var (
func TestHarmonyFlags(t *testing.T) {
tests := []struct {
argStr string
expConfig harmonyConfig
expConfig harmonyconfig.HarmonyConfig
}{
{
// running staking command from legacy node.sh
@ -29,16 +31,16 @@ 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.HarmonyConfig{
Version: tomlConfigVersion,
General: generalConfig{
General: harmonyconfig.GeneralConfig{
NodeType: "validator",
NoStaking: false,
ShardID: -1,
IsArchival: false,
DataDir: "./",
},
Network: networkConfig{
Network: harmonyconfig.NetworkConfig{
NetworkType: "mainnet",
BootNodes: []string{
"/ip4/100.26.90.187/tcp/9874/p2p/Qmdfjtk6hPoyrH1zVD9PEH4zfWLo38dP2mDvvKXfh3tnEv",
@ -47,40 +49,40 @@ func TestHarmonyFlags(t *testing.T) {
"/ip4/99.81.170.167/tcp/12019/p2p/QmRVbTpEYup8dSaURZfF6ByrMTSKa4UyUzJhSjahFzRqNj",
},
},
DNSSync: dnsSync{
DNSSync: harmonyconfig.DnsSync{
Port: 6000,
Zone: "t.hmny.io",
Server: true,
Client: true,
ServerPort: nodeconfig.DefaultDNSPort,
},
P2P: p2pConfig{
P2P: harmonyconfig.P2pConfig{
Port: 9000,
IP: defaultConfig.P2P.IP,
KeyFile: defaultConfig.P2P.KeyFile,
},
HTTP: httpConfig{
HTTP: harmonyconfig.HttpConfig{
Enabled: true,
IP: "127.0.0.1",
Port: 9500,
RosettaEnabled: false,
RosettaPort: 9700,
},
RPCOpt: rpcOptConfig{
RPCOpt: harmonyconfig.RpcOptConfig{
DebugEnabled: false,
RateLimterEnabled: true,
RequestsPerSecond: 1000,
},
WS: wsConfig{
WS: harmonyconfig.WsConfig{
Enabled: true,
IP: "127.0.0.1",
Port: 9800,
},
Consensus: &consensusConfig{
Consensus: &harmonyconfig.ConsensusConfig{
MinPeers: 6,
AggregateSig: true,
},
BLSKeys: blsConfig{
BLSKeys: harmonyconfig.BlsConfig{
KeyDir: "./.hmy/blskeys",
KeyFiles: []string{},
MaxKeys: 10,
@ -92,30 +94,30 @@ func TestHarmonyFlags(t *testing.T) {
KMSConfigSrcType: "file",
KMSConfigFile: "config.json",
},
TxPool: txPoolConfig{
TxPool: harmonyconfig.TxPoolConfig{
BlacklistFile: "./.hmy/blacklist.txt",
},
Pprof: pprofConfig{
Pprof: harmonyconfig.PprofConfig{
Enabled: false,
ListenAddr: "127.0.0.1:6060",
},
Log: logConfig{
Log: harmonyconfig.LogConfig{
Folder: "./latest",
FileName: "validator-8.8.8.8-9000.log",
RotateSize: 100,
Verbosity: 3,
Context: &logContext{
Context: &harmonyconfig.LogContext{
IP: "8.8.8.8",
Port: 9000,
},
},
Sys: &sysConfig{
Sys: &harmonyconfig.SysConfig{
NtpServer: defaultSysConfig.NtpServer,
},
Legacy: &legacyConfig{
Legacy: &harmonyconfig.LegacyConfig{
TPBroadcastInvalidTxn: &trueBool,
},
Prometheus: &prometheusConfig{
Prometheus: &harmonyconfig.PrometheusConfig{
Enabled: true,
IP: "0.0.0.0",
Port: 9900,
@ -142,12 +144,12 @@ func TestHarmonyFlags(t *testing.T) {
func TestGeneralFlags(t *testing.T) {
tests := []struct {
args []string
expConfig generalConfig
expConfig harmonyconfig.GeneralConfig
expErr error
}{
{
args: []string{},
expConfig: generalConfig{
expConfig: harmonyconfig.GeneralConfig{
NodeType: "validator",
NoStaking: false,
ShardID: -1,
@ -158,7 +160,7 @@ func TestGeneralFlags(t *testing.T) {
{
args: []string{"--run", "explorer", "--run.legacy", "--run.shard=0",
"--run.archive=true", "--datadir=./.hmy"},
expConfig: generalConfig{
expConfig: harmonyconfig.GeneralConfig{
NodeType: "explorer",
NoStaking: true,
ShardID: 0,
@ -169,7 +171,7 @@ func TestGeneralFlags(t *testing.T) {
{
args: []string{"--node_type", "explorer", "--staking", "--shard_id", "0",
"--is_archival", "--db_dir", "./"},
expConfig: generalConfig{
expConfig: harmonyconfig.GeneralConfig{
NodeType: "explorer",
NoStaking: false,
ShardID: 0,
@ -179,7 +181,7 @@ func TestGeneralFlags(t *testing.T) {
},
{
args: []string{"--staking=false", "--is_archival=false"},
expConfig: generalConfig{
expConfig: harmonyconfig.GeneralConfig{
NodeType: "validator",
NoStaking: true,
ShardID: -1,
@ -189,7 +191,7 @@ func TestGeneralFlags(t *testing.T) {
},
{
args: []string{"--run", "explorer", "--run.shard", "0"},
expConfig: generalConfig{
expConfig: harmonyconfig.GeneralConfig{
NodeType: "explorer",
NoStaking: false,
ShardID: 0,
@ -199,7 +201,7 @@ func TestGeneralFlags(t *testing.T) {
},
{
args: []string{"--run", "explorer", "--run.shard", "0", "--run.archive=false"},
expConfig: generalConfig{
expConfig: harmonyconfig.GeneralConfig{
NodeType: "explorer",
NoStaking: false,
ShardID: 0,
@ -229,13 +231,13 @@ func TestGeneralFlags(t *testing.T) {
func TestNetworkFlags(t *testing.T) {
tests := []struct {
args []string
expConfig harmonyConfig
expConfig harmonyconfig.HarmonyConfig
expErr error
}{
{
args: []string{},
expConfig: harmonyConfig{
Network: networkConfig{
expConfig: harmonyconfig.HarmonyConfig{
Network: harmonyconfig.NetworkConfig{
NetworkType: defNetworkType,
BootNodes: nodeconfig.GetDefaultBootNodes(defNetworkType),
},
@ -243,8 +245,8 @@ func TestNetworkFlags(t *testing.T) {
},
{
args: []string{"-n", "stn"},
expConfig: harmonyConfig{
Network: networkConfig{
expConfig: harmonyconfig.HarmonyConfig{
Network: harmonyconfig.NetworkConfig{
NetworkType: nodeconfig.Stressnet,
BootNodes: nodeconfig.GetDefaultBootNodes(nodeconfig.Stressnet),
},
@ -254,12 +256,12 @@ 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{
Network: networkConfig{
expConfig: harmonyconfig.HarmonyConfig{
Network: harmonyconfig.NetworkConfig{
NetworkType: "pangaea",
BootNodes: []string{"1", "2", "3", "4"},
},
DNSSync: dnsSync{
DNSSync: harmonyconfig.DnsSync{
Port: 9001,
Zone: "8.8.8.8",
LegacySyncing: false,
@ -271,12 +273,12 @@ 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{
Network: networkConfig{
expConfig: harmonyconfig.HarmonyConfig{
Network: harmonyconfig.NetworkConfig{
NetworkType: "pangaea",
BootNodes: []string{"1", "2", "3", "4"},
},
DNSSync: dnsSync{
DNSSync: harmonyconfig.DnsSync{
Port: 9001,
Zone: "8.8.8.8",
LegacySyncing: false,
@ -287,12 +289,12 @@ func TestNetworkFlags(t *testing.T) {
},
{
args: []string{"--dns=false"},
expConfig: harmonyConfig{
Network: networkConfig{
expConfig: harmonyconfig.HarmonyConfig{
Network: harmonyconfig.NetworkConfig{
NetworkType: defNetworkType,
BootNodes: nodeconfig.GetDefaultBootNodes(defNetworkType),
},
DNSSync: dnsSync{
DNSSync: harmonyconfig.DnsSync{
Port: nodeconfig.GetDefaultDNSPort(defNetworkType),
Zone: nodeconfig.GetDefaultDNSZone(defNetworkType),
LegacySyncing: true,
@ -307,8 +309,8 @@ 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) {
// This is the network related logic in function getHarmonyConfig
ts := newFlagTestSuite(t, neededFlags, func(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
// This is the network related logic in function getharmonyconfig.HarmonyConfig
nt := getNetworkType(cmd)
config.Network = getDefaultNetworkConfig(nt)
config.DNSSync = getDefaultDNSSyncConfig(nt)
@ -339,7 +341,7 @@ var defDataStore = ".dht-127.0.0.1"
func TestP2PFlags(t *testing.T) {
tests := []struct {
args []string
expConfig p2pConfig
expConfig harmonyconfig.P2pConfig
expErr error
}{
{
@ -349,7 +351,7 @@ func TestP2PFlags(t *testing.T) {
{
args: []string{"--p2p.port", "9001", "--p2p.keyfile", "./key.file", "--p2p.dht.datastore",
defDataStore},
expConfig: p2pConfig{
expConfig: harmonyconfig.P2pConfig{
Port: 9001,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./key.file",
@ -358,7 +360,7 @@ func TestP2PFlags(t *testing.T) {
},
{
args: []string{"--port", "9001", "--key", "./key.file"},
expConfig: p2pConfig{
expConfig: harmonyconfig.P2pConfig{
Port: 9001,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./key.file",
@ -367,7 +369,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.HarmonyConfig) {
applyLegacyMiscFlags(cmd, config)
applyP2PFlags(cmd, config)
},
@ -391,7 +393,7 @@ func TestP2PFlags(t *testing.T) {
func TestRPCFlags(t *testing.T) {
tests := []struct {
args []string
expConfig httpConfig
expConfig harmonyconfig.HttpConfig
expErr error
}{
{
@ -400,7 +402,7 @@ func TestRPCFlags(t *testing.T) {
},
{
args: []string{"--http=false"},
expConfig: httpConfig{
expConfig: harmonyconfig.HttpConfig{
Enabled: false,
RosettaEnabled: false,
IP: defaultConfig.HTTP.IP,
@ -410,7 +412,7 @@ func TestRPCFlags(t *testing.T) {
},
{
args: []string{"--http.ip", "8.8.8.8", "--http.port", "9001"},
expConfig: httpConfig{
expConfig: harmonyconfig.HttpConfig{
Enabled: true,
RosettaEnabled: false,
IP: "8.8.8.8",
@ -420,7 +422,7 @@ func TestRPCFlags(t *testing.T) {
},
{
args: []string{"--http.ip", "8.8.8.8", "--http.port", "9001", "--http.rosetta.port", "10001"},
expConfig: httpConfig{
expConfig: harmonyconfig.HttpConfig{
Enabled: true,
RosettaEnabled: true,
IP: "8.8.8.8",
@ -430,7 +432,7 @@ func TestRPCFlags(t *testing.T) {
},
{
args: []string{"--http.ip", "8.8.8.8", "--http.rosetta.port", "10001"},
expConfig: httpConfig{
expConfig: harmonyconfig.HttpConfig{
Enabled: true,
RosettaEnabled: true,
IP: "8.8.8.8",
@ -440,7 +442,7 @@ func TestRPCFlags(t *testing.T) {
},
{
args: []string{"--ip", "8.8.8.8", "--port", "9001", "--public_rpc"},
expConfig: httpConfig{
expConfig: harmonyconfig.HttpConfig{
Enabled: true,
RosettaEnabled: false,
IP: nodeconfig.DefaultPublicListenIP,
@ -451,7 +453,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.HarmonyConfig) {
applyLegacyMiscFlags(cmd, config)
applyHTTPFlags(cmd, config)
},
@ -476,7 +478,7 @@ func TestRPCFlags(t *testing.T) {
func TestWSFlags(t *testing.T) {
tests := []struct {
args []string
expConfig wsConfig
expConfig harmonyconfig.WsConfig
expErr error
}{
{
@ -485,7 +487,7 @@ func TestWSFlags(t *testing.T) {
},
{
args: []string{"--ws=false"},
expConfig: wsConfig{
expConfig: harmonyconfig.WsConfig{
Enabled: false,
IP: defaultConfig.WS.IP,
Port: defaultConfig.WS.Port,
@ -493,7 +495,7 @@ func TestWSFlags(t *testing.T) {
},
{
args: []string{"--ws", "--ws.ip", "8.8.8.8", "--ws.port", "9001"},
expConfig: wsConfig{
expConfig: harmonyconfig.WsConfig{
Enabled: true,
IP: "8.8.8.8",
Port: 9001,
@ -501,7 +503,7 @@ func TestWSFlags(t *testing.T) {
},
{
args: []string{"--ip", "8.8.8.8", "--port", "9001", "--public_rpc"},
expConfig: wsConfig{
expConfig: harmonyconfig.WsConfig{
Enabled: true,
IP: nodeconfig.DefaultPublicListenIP,
Port: 9801,
@ -510,7 +512,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.HarmonyConfig) {
applyLegacyMiscFlags(cmd, config)
applyWSFlags(cmd, config)
},
@ -535,11 +537,11 @@ func TestWSFlags(t *testing.T) {
func TestRPCOptFlags(t *testing.T) {
tests := []struct {
args []string
expConfig rpcOptConfig
expConfig harmonyconfig.RpcOptConfig
}{
{
args: []string{"--rpc.debug"},
expConfig: rpcOptConfig{
expConfig: harmonyconfig.RpcOptConfig{
DebugEnabled: true,
RateLimterEnabled: true,
RequestsPerSecond: 1000,
@ -548,7 +550,7 @@ func TestRPCOptFlags(t *testing.T) {
{
args: []string{},
expConfig: rpcOptConfig{
expConfig: harmonyconfig.RpcOptConfig{
DebugEnabled: false,
RateLimterEnabled: true,
RequestsPerSecond: 1000,
@ -557,7 +559,7 @@ func TestRPCOptFlags(t *testing.T) {
{
args: []string{"--rpc.ratelimiter", "--rpc.ratelimit", "2000"},
expConfig: rpcOptConfig{
expConfig: harmonyconfig.RpcOptConfig{
DebugEnabled: false,
RateLimterEnabled: true,
RequestsPerSecond: 2000,
@ -566,7 +568,7 @@ func TestRPCOptFlags(t *testing.T) {
{
args: []string{"--rpc.ratelimiter=false", "--rpc.ratelimit", "2000"},
expConfig: rpcOptConfig{
expConfig: harmonyconfig.RpcOptConfig{
DebugEnabled: false,
RateLimterEnabled: false,
RequestsPerSecond: 2000,
@ -589,7 +591,7 @@ func TestRPCOptFlags(t *testing.T) {
func TestBLSFlags(t *testing.T) {
tests := []struct {
args []string
expConfig blsConfig
expConfig harmonyconfig.BlsConfig
expErr error
}{
{
@ -601,7 +603,7 @@ func TestBLSFlags(t *testing.T) {
"--bls.maxkeys", "8", "--bls.pass", "--bls.pass.src", "auto", "--bls.pass.save",
"--bls.kms", "--bls.kms.src", "shared",
},
expConfig: blsConfig{
expConfig: harmonyconfig.BlsConfig{
KeyDir: "./blskeys",
KeyFiles: []string{"key1", "key2"},
MaxKeys: 8,
@ -616,7 +618,7 @@ func TestBLSFlags(t *testing.T) {
},
{
args: []string{"--bls.pass.file", "xxx.pass", "--bls.kms.config", "config.json"},
expConfig: blsConfig{
expConfig: harmonyconfig.BlsConfig{
KeyDir: defaultConfig.BLSKeys.KeyDir,
KeyFiles: defaultConfig.BLSKeys.KeyFiles,
MaxKeys: defaultConfig.BLSKeys.MaxKeys,
@ -634,7 +636,7 @@ func TestBLSFlags(t *testing.T) {
"--max_bls_keys_per_node", "5", "--blspass", "file:xxx.pass", "--save-passphrase",
"--aws-config-source", "file:config.json",
},
expConfig: blsConfig{
expConfig: harmonyconfig.BlsConfig{
KeyDir: "./hmykeys",
KeyFiles: []string{"key1", "key2"},
MaxKeys: 5,
@ -670,7 +672,7 @@ func TestBLSFlags(t *testing.T) {
func TestConsensusFlags(t *testing.T) {
tests := []struct {
args []string
expConfig *consensusConfig
expConfig *harmonyconfig.ConsensusConfig
expErr error
}{
{
@ -679,7 +681,7 @@ func TestConsensusFlags(t *testing.T) {
},
{
args: []string{"--consensus.min-peers", "10", "--consensus.aggregate-sig=false"},
expConfig: &consensusConfig{
expConfig: &harmonyconfig.ConsensusConfig{
MinPeers: 10,
AggregateSig: false,
},
@ -687,7 +689,7 @@ func TestConsensusFlags(t *testing.T) {
{
args: []string{"--delay_commit", "10ms", "--block_period", "5", "--min_peers", "10",
"--consensus.aggregate-sig=true"},
expConfig: &consensusConfig{
expConfig: &harmonyconfig.ConsensusConfig{
MinPeers: 10,
AggregateSig: true,
},
@ -715,24 +717,24 @@ func TestConsensusFlags(t *testing.T) {
func TestTxPoolFlags(t *testing.T) {
tests := []struct {
args []string
expConfig txPoolConfig
expConfig harmonyconfig.TxPoolConfig
expErr error
}{
{
args: []string{},
expConfig: txPoolConfig{
expConfig: harmonyconfig.TxPoolConfig{
BlacklistFile: defaultConfig.TxPool.BlacklistFile,
},
},
{
args: []string{"--txpool.blacklist", "blacklist.file"},
expConfig: txPoolConfig{
expConfig: harmonyconfig.TxPoolConfig{
BlacklistFile: "blacklist.file",
},
},
{
args: []string{"--blacklist", "blacklist.file"},
expConfig: txPoolConfig{
expConfig: harmonyconfig.TxPoolConfig{
BlacklistFile: "blacklist.file",
},
},
@ -758,7 +760,7 @@ func TestTxPoolFlags(t *testing.T) {
func TestPprofFlags(t *testing.T) {
tests := []struct {
args []string
expConfig pprofConfig
expConfig harmonyconfig.PprofConfig
expErr error
}{
{
@ -767,21 +769,21 @@ func TestPprofFlags(t *testing.T) {
},
{
args: []string{"--pprof"},
expConfig: pprofConfig{
expConfig: harmonyconfig.PprofConfig{
Enabled: true,
ListenAddr: defaultConfig.Pprof.ListenAddr,
},
},
{
args: []string{"--pprof.addr", "8.8.8.8:9001"},
expConfig: pprofConfig{
expConfig: harmonyconfig.PprofConfig{
Enabled: true,
ListenAddr: "8.8.8.8:9001",
},
},
{
args: []string{"--pprof=false", "--pprof.addr", "8.8.8.8:9001"},
expConfig: pprofConfig{
expConfig: harmonyconfig.PprofConfig{
Enabled: false,
ListenAddr: "8.8.8.8:9001",
},
@ -807,7 +809,7 @@ func TestPprofFlags(t *testing.T) {
func TestLogFlags(t *testing.T) {
tests := []struct {
args []string
expConfig logConfig
expConfig harmonyconfig.LogConfig
expErr error
}{
{
@ -816,23 +818,27 @@ func TestLogFlags(t *testing.T) {
},
{
args: []string{"--log.dir", "latest_log", "--log.max-size", "10", "--log.name", "harmony.log",
"--log.verb", "5"},
expConfig: logConfig{
"--log.verb", "5", "--log.verbose-prints", "config"},
expConfig: harmonyconfig.LogConfig{
Folder: "latest_log",
FileName: "harmony.log",
RotateSize: 10,
Verbosity: 5,
Context: nil,
VerbosePrints: harmonyconfig.LogVerbosePrints{
Config: true,
},
Context: nil,
},
},
{
args: []string{"--log.ctx.ip", "8.8.8.8", "--log.ctx.port", "9001"},
expConfig: logConfig{
Folder: defaultConfig.Log.Folder,
FileName: defaultConfig.Log.FileName,
RotateSize: defaultConfig.Log.RotateSize,
Verbosity: defaultConfig.Log.Verbosity,
Context: &logContext{
expConfig: harmonyconfig.LogConfig{
Folder: defaultConfig.Log.Folder,
FileName: defaultConfig.Log.FileName,
RotateSize: defaultConfig.Log.RotateSize,
Verbosity: defaultConfig.Log.Verbosity,
VerbosePrints: defaultConfig.Log.VerbosePrints,
Context: &harmonyconfig.LogContext{
IP: "8.8.8.8",
Port: 9001,
},
@ -841,12 +847,13 @@ func TestLogFlags(t *testing.T) {
{
args: []string{"--log_folder", "latest_log", "--log_max_size", "10", "--verbosity",
"5", "--ip", "8.8.8.8", "--port", "9001"},
expConfig: logConfig{
Folder: "latest_log",
FileName: "validator-8.8.8.8-9001.log",
RotateSize: 10,
Verbosity: 5,
Context: &logContext{
expConfig: harmonyconfig.LogConfig{
Folder: "latest_log",
FileName: "validator-8.8.8.8-9001.log",
RotateSize: 10,
Verbosity: 5,
VerbosePrints: defaultConfig.Log.VerbosePrints,
Context: &harmonyconfig.LogContext{
IP: "8.8.8.8",
Port: 9001,
},
@ -855,7 +862,7 @@ func TestLogFlags(t *testing.T) {
}
for i, test := range tests {
ts := newFlagTestSuite(t, append(logFlags, legacyMiscFlags...),
func(cmd *cobra.Command, config *harmonyConfig) {
func(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
applyLegacyMiscFlags(cmd, config)
applyLogFlags(cmd, config)
},
@ -879,18 +886,18 @@ func TestLogFlags(t *testing.T) {
func TestSysFlags(t *testing.T) {
tests := []struct {
args []string
expConfig *sysConfig
expConfig *harmonyconfig.SysConfig
expErr error
}{
{
args: []string{},
expConfig: &sysConfig{
expConfig: &harmonyconfig.SysConfig{
NtpServer: defaultSysConfig.NtpServer,
},
},
{
args: []string{"--sys.ntp", "0.pool.ntp.org"},
expConfig: &sysConfig{
expConfig: &harmonyconfig.SysConfig{
NtpServer: "0.pool.ntp.org",
},
},
@ -917,7 +924,7 @@ func TestSysFlags(t *testing.T) {
func TestDevnetFlags(t *testing.T) {
tests := []struct {
args []string
expConfig *devnetConfig
expConfig *harmonyconfig.DevnetConfig
expErr error
}{
{
@ -927,7 +934,7 @@ func TestDevnetFlags(t *testing.T) {
{
args: []string{"--devnet.num-shard", "3", "--devnet.shard-size", "100",
"--devnet.hmy-node-size", "60"},
expConfig: &devnetConfig{
expConfig: &harmonyconfig.DevnetConfig{
NumShards: 3,
ShardSize: 100,
HmyNodeSize: 60,
@ -936,7 +943,7 @@ func TestDevnetFlags(t *testing.T) {
{
args: []string{"--dn_num_shards", "3", "--dn_shard_size", "100", "--dn_hmy_size",
"60"},
expConfig: &devnetConfig{
expConfig: &harmonyconfig.DevnetConfig{
NumShards: 3,
ShardSize: 100,
HmyNodeSize: 60,
@ -964,7 +971,7 @@ func TestDevnetFlags(t *testing.T) {
func TestRevertFlags(t *testing.T) {
tests := []struct {
args []string
expConfig *revertConfig
expConfig *harmonyconfig.RevertConfig
expErr error
}{
{
@ -973,7 +980,7 @@ func TestRevertFlags(t *testing.T) {
},
{
args: []string{"--revert.beacon"},
expConfig: &revertConfig{
expConfig: &harmonyconfig.RevertConfig{
RevertBeacon: true,
RevertTo: defaultRevertConfig.RevertTo,
RevertBefore: defaultRevertConfig.RevertBefore,
@ -981,7 +988,7 @@ func TestRevertFlags(t *testing.T) {
},
{
args: []string{"--revert.beacon", "--revert.to", "100", "--revert.do-before", "10000"},
expConfig: &revertConfig{
expConfig: &harmonyconfig.RevertConfig{
RevertBeacon: true,
RevertTo: 100,
RevertBefore: 10000,
@ -989,7 +996,7 @@ func TestRevertFlags(t *testing.T) {
},
{
args: []string{"--revert_beacon", "--do_revert_before", "10000", "--revert_to", "100"},
expConfig: &revertConfig{
expConfig: &harmonyconfig.RevertConfig{
RevertBeacon: true,
RevertTo: 100,
RevertBefore: 10000,
@ -1017,7 +1024,7 @@ func TestDNSSyncFlags(t *testing.T) {
tests := []struct {
args []string
network string
expConfig dnsSync
expConfig harmonyconfig.DnsSync
expErr error
}{
{
@ -1033,7 +1040,7 @@ func TestDNSSyncFlags(t *testing.T) {
{
args: []string{"--sync.legacy.server", "--sync.legacy.client"},
network: "testnet",
expConfig: func() dnsSync {
expConfig: func() harmonyconfig.DnsSync {
cfg := getDefaultDNSSyncConfig(nodeconfig.Mainnet)
cfg.Client = true
cfg.Server = true
@ -1048,7 +1055,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.HarmonyConfig) {
config.Network.NetworkType = test.network
applyDNSSyncFlags(command, config)
})
@ -1071,7 +1078,7 @@ func TestSyncFlags(t *testing.T) {
tests := []struct {
args []string
network string
expConfig syncConfig
expConfig harmonyconfig.SyncConfig
expErr error
}{
{
@ -1081,7 +1088,7 @@ func TestSyncFlags(t *testing.T) {
"--sync.disc.batch", "10",
},
network: "mainnet",
expConfig: func() syncConfig {
expConfig: func() harmonyconfig.SyncConfig {
cfgSync := defaultMainnetSyncConfig
cfgSync.Enabled = true
cfgSync.Downloader = true
@ -1097,7 +1104,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.HarmonyConfig) {
applySyncFlags(command, config)
})
hc, err := ts.run(test.args)
@ -1120,10 +1127,10 @@ type flagTestSuite struct {
t *testing.T
cmd *cobra.Command
hc harmonyConfig
hc harmonyconfig.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.HarmonyConfig)) *flagTestSuite {
cli.SetParseErrorHandle(func(err error) { t.Fatal(err) })
ts := &flagTestSuite{hc: getDefaultHmyConfigCopy(defNetworkType)}
@ -1137,7 +1144,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.HarmonyConfig, error) {
ts.cmd.SetArgs(args)
err := ts.cmd.Execute()
return ts.hc, err

@ -16,6 +16,9 @@ import (
"syscall"
"time"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
rpc_common "github.com/harmony-one/harmony/rpc/common"
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/bls/ffi/go/bls"
@ -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)
@ -379,6 +382,14 @@ func setupNodeAndRun(hc harmonyConfig) {
nodeconfig.SetPeerID(myHost.GetID())
if hc.Log.VerbosePrints.Config {
utils.Logger().Info().Interface("config", rpc_common.Config{
HarmonyConfig: hc,
NodeConfig: *nodeConfig,
ChainConfig: *currentNode.Blockchain().Config(),
}).Msg("verbose prints config")
}
// Setup services
if hc.Sync.Enabled {
setupSyncService(currentNode, myHost, hc)
@ -443,7 +454,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 +469,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 +497,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 +529,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 +550,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 +615,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 +632,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 {
@ -642,7 +653,7 @@ func setupConsensusAndNode(hc harmonyConfig, nodeConfig *nodeconfig.ConfigType)
// Current node.
chainDBFactory := &shardchain.LDBFactory{RootDir: nodeConfig.DBDir}
currentNode := node.New(myHost, currentConsensus, chainDBFactory, blacklist, nodeConfig.ArchiveModes())
currentNode := node.New(myHost, currentConsensus, chainDBFactory, blacklist, nodeConfig.ArchiveModes(), &hc)
if hc.Legacy != nil && hc.Legacy.TPBroadcastInvalidTxn != nil {
currentNode.BroadcastInvalidTx = *hc.Legacy.TPBroadcastInvalidTxn
@ -712,7 +723,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 +740,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 +773,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 {

@ -106,6 +106,7 @@ type NodeAPI interface {
GetConsensusPhase() string
GetConsensusViewChangingID() uint64
GetConsensusCurViewID() uint64
GetConfig() commonRPC.Config
ShutDown()
}

@ -0,0 +1,186 @@
package harmony
import (
"reflect"
"strings"
)
// 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 LogVerbosePrints
Context *LogContext `toml:",omitempty"`
}
type LogVerbosePrints struct {
Config bool
}
func FlagSliceToLogVerbosePrints(verbosePrintsFlagSlice []string) LogVerbosePrints {
verbosePrints := LogVerbosePrints{}
verbosePrintsReflect := reflect.Indirect(reflect.ValueOf(&verbosePrints))
for _, verbosePrint := range verbosePrintsFlagSlice {
verbosePrint = strings.Title(verbosePrint)
field := verbosePrintsReflect.FieldByName(verbosePrint)
if field.IsValid() && field.CanSet() {
field.SetBool(true)
}
}
return verbosePrints
}
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

@ -142,3 +142,11 @@ func (node *Node) GetConsensusInternal() rpc_common.ConsensusInternal {
ConsensusTime: node.Consensus.GetFinality(),
}
}
func (node *Node) GetConfig() rpc_common.Config {
return rpc_common.Config{
HarmonyConfig: *node.HarmonyConfig,
NodeConfig: *node.NodeConfig,
ChainConfig: node.chainConfig,
}
}

@ -10,6 +10,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/rlp"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/ethereum/go-ethereum/common"
protobuf "github.com/golang/protobuf/proto"
@ -105,6 +106,7 @@ type Node struct {
ContractAddresses []common.Address
// Channel to notify consensus service to really start consensus
startConsensus chan struct{}
HarmonyConfig *harmonyconfig.HarmonyConfig
// node configuration, including group ID, shard ID, etc
NodeConfig *nodeconfig.ConfigType
// Chain configuration.
@ -938,6 +940,7 @@ func New(
chainDBFactory shardchain.DBFactory,
blacklist map[common.Address]struct{},
isArchival map[uint32]bool,
harmonyconfig *harmonyconfig.HarmonyConfig,
) *Node {
node := Node{}
node.unixTimeAtNodeStart = time.Now().Unix()
@ -948,6 +951,7 @@ func New(
} else {
node.NodeConfig = nodeconfig.GetDefaultConfig()
}
node.HarmonyConfig = harmonyconfig
copy(node.syncID[:], GenerateRandomString(SyncIDLength))
if host != nil {

@ -39,7 +39,7 @@ func TestAddNewBlock(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err)
}
nodeconfig.SetNetworkType(nodeconfig.Devnet)
node := New(host, consensus, testDBFactory, nil, nil)
node := New(host, consensus, testDBFactory, nil, nil, nil)
txs := make(map[common.Address]types.Transactions)
stks := staking.StakingTransactions{}
@ -88,7 +88,7 @@ func TestVerifyNewBlock(t *testing.T) {
archiveMode := make(map[uint32]bool)
archiveMode[0] = true
archiveMode[1] = false
node := New(host, consensus, testDBFactory, nil, archiveMode)
node := New(host, consensus, testDBFactory, nil, archiveMode, nil)
txs := make(map[common.Address]types.Transactions)
stks := staking.StakingTransactions{}
@ -134,7 +134,7 @@ func TestVerifyVRF(t *testing.T) {
archiveMode := make(map[uint32]bool)
archiveMode[0] = true
archiveMode[1] = false
node := New(host, consensus, testDBFactory, nil, archiveMode)
node := New(host, consensus, testDBFactory, nil, archiveMode, nil)
consensus.Blockchain = node.Blockchain()
txs := make(map[common.Address]types.Transactions)

@ -40,7 +40,7 @@ func TestFinalizeNewBlockAsync(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err)
}
var testDBFactory = &shardchain.MemDBFactory{}
node := New(host, consensus, testDBFactory, nil, nil)
node := New(host, consensus, testDBFactory, nil, nil, nil)
node.Worker.UpdateCurrent()

@ -39,7 +39,7 @@ func TestNewNode(t *testing.T) {
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}
node := New(host, consensus, testDBFactory, nil, nil)
node := New(host, consensus, testDBFactory, nil, nil, nil)
if node.Consensus == nil {
t.Error("Consensus is not initialized for the node")
}
@ -216,7 +216,7 @@ func TestAddBeaconPeer(t *testing.T) {
archiveMode := make(map[uint32]bool)
archiveMode[0] = true
archiveMode[1] = false
node := New(host, consensus, testDBFactory, nil, archiveMode)
node := New(host, consensus, testDBFactory, nil, archiveMode, nil)
for _, p := range peers1 {
ret := node.AddBeaconPeer(p)
if ret {

@ -3,6 +3,9 @@ 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 +83,9 @@ type NodePeerInfo struct {
BlockedPeers []peer.ID `json:"blocked-peers"`
P []P `json:"connected-peers"`
}
type Config struct {
HarmonyConfig harmonyconfig.HarmonyConfig
NodeConfig nodeconfig.ConfigType
ChainConfig params.ChainConfig
}

@ -64,3 +64,10 @@ func (s *PrivateDebugService) GetConsensusPhase(
) string {
return s.hmy.NodeAPI.GetConsensusPhase()
}
// GetConfig get harmony config
func (s *PrivateDebugService) GetConfig(
ctx context.Context,
) (StructuredResponse, error) {
return NewStructuredResponse(s.hmy.NodeAPI.GetConfig())
}

Loading…
Cancel
Save