Skip to content

Commit

Permalink
Merge branch 'development' into EN-4248-compact-miniblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sasurobert authored Oct 23, 2019
2 parents c853a04 + 609ecd4 commit cce05b0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
3 changes: 0 additions & 3 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
# StatusPollingIntervalSec represents the no of seconds between multiple polling for the status for AppStatusHandler
StatusPollingIntervalSec = 2

# NodeDisplayName represents the friendly name a user can pick for his node in the status monitor
NodeDisplayName = ""

[Explorer]
Enabled = false
IndexerURL = "http://localhost:9200"
Expand Down
3 changes: 3 additions & 0 deletions cmd/node/config/prefs.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Preferences]
# NodeDisplayName represents the friendly name a user can pick for his node in the status monitor
NodeDisplayName = ""
33 changes: 30 additions & 3 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ VERSION:
Usage: "The economics configuration file to load",
Value: "./config/economics.toml",
}

// configurationPreferencesFile defines a flag for the path to the preferences toml configuration file
configurationPreferencesFile = cli.StringFlag{
Name: "configPreferences",
Usage: "The preferences configuration file to load",
Value: "./config/prefs.toml",
}
// p2pConfigurationFile defines a flag for the path to the toml file containing P2P configuration
p2pConfigurationFile = cli.StringFlag{
Name: "p2pconfig",
Expand Down Expand Up @@ -297,6 +302,7 @@ func main() {
port,
configurationFile,
configurationEconomicsFile,
configurationPreferencesFile,
p2pConfigurationFile,
txSignSk,
sk,
Expand Down Expand Up @@ -380,6 +386,13 @@ func startNode(ctx *cli.Context, log *logger.Logger, version string) error {
}
log.Info(fmt.Sprintf("Initialized with config economics from: %s", configurationEconomicsFileName))

configurationPreferencesFileName := ctx.GlobalString(configurationPreferencesFile.Name)
preferencesConfig, err := loadPreferencesConfig(configurationPreferencesFileName, log)
if err != nil {
return err
}
log.Info(fmt.Sprintf("Initialized with config preferences from: %s", configurationPreferencesFileName))

p2pConfigurationFileName := ctx.GlobalString(p2pConfigurationFile.Name)
p2pConfig, err := core.LoadP2PConfig(p2pConfigurationFileName)
if err != nil {
Expand Down Expand Up @@ -447,7 +460,7 @@ func startNode(ctx *cli.Context, log *logger.Logger, version string) error {
}

if ctx.IsSet(nodeDisplayName.Name) {
generalConfig.GeneralSettings.NodeDisplayName = ctx.GlobalString(nodeDisplayName.Name)
preferencesConfig.Preferences.NodeDisplayName = ctx.GlobalString(nodeDisplayName.Name)
}

shardCoordinator, nodeType, err := createShardCoordinator(nodesConfig, pubKey, generalConfig.GeneralSettings, log)
Expand Down Expand Up @@ -679,6 +692,7 @@ func startNode(ctx *cli.Context, log *logger.Logger, version string) error {

currentNode, err := createNode(
generalConfig,
preferencesConfig,
nodesConfig,
syncer,
keyGen,
Expand Down Expand Up @@ -845,6 +859,7 @@ func loadMainConfig(filepath string, log *logger.Logger) (*config.Config, error)
if err != nil {
return nil, err
}

return cfg, nil
}

Expand All @@ -854,6 +869,17 @@ func loadEconomicsConfig(filepath string, log *logger.Logger) (*config.ConfigEco
if err != nil {
return nil, err
}

return cfg, nil
}

func loadPreferencesConfig(filepath string, log *logger.Logger) (*config.ConfigPreferences, error) {
cfg := &config.ConfigPreferences{}
err := core.LoadTomlFile(cfg, filepath, log)
if err != nil {
return nil, err
}

return cfg, nil
}

Expand Down Expand Up @@ -1027,6 +1053,7 @@ func getConsensusGroupSize(nodesConfig *sharding.NodesSetup, shardCoordinator sh

func createNode(
config *config.Config,
preferencesConfig *config.ConfigPreferences,
nodesConfig *sharding.NodesSetup,
syncer ntp.SyncTimer,
keyGen crypto.KeyGenerator,
Expand Down Expand Up @@ -1088,7 +1115,7 @@ func createNode(
return nil, errors.New("error creating node: " + err.Error())
}

err = nd.StartHeartbeat(config.Heartbeat, version, config.GeneralSettings.NodeDisplayName)
err = nd.StartHeartbeat(config.Heartbeat, version, preferencesConfig.Preferences.NodeDisplayName)
if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions config/prefsConfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package config

// ConfigPreferences will hold the configuration related to node's preferences
type ConfigPreferences struct {
Preferences PreferencesConfig
}

// PreferencesConfig will hold the fields which are node specific such as the display name
type PreferencesConfig struct {
NodeDisplayName string
}
22 changes: 22 additions & 0 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,25 @@ func TestTomlEconomicsParser(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, cfgEconomicsExpected, cfg)
}

func TestTomlPreferencesParser(t *testing.T) {
nodeDisplayName := "test-name"

cfgPreferencesExpected := ConfigPreferences{
Preferences: PreferencesConfig{
NodeDisplayName: nodeDisplayName,
},
}

testString := `
[Preferences]
NodeDisplayName = "` + nodeDisplayName + `"
`

cfg := ConfigPreferences{}

err := toml.Unmarshal([]byte(testString), &cfg)

assert.Nil(t, err)
assert.Equal(t, cfgPreferencesExpected, cfg)
}

0 comments on commit cce05b0

Please sign in to comment.