Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename validator CLI command to node and add default CLI values #230

Merged
4 commits merged into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/alicenet/alicenet/cmd/bootnode"
"github.com/alicenet/alicenet/cmd/firewalld"
"github.com/alicenet/alicenet/cmd/node"
"github.com/alicenet/alicenet/cmd/utils"
"github.com/alicenet/alicenet/cmd/validator"
"github.com/alicenet/alicenet/config"
"github.com/alicenet/alicenet/logging"
"github.com/sirupsen/logrus"
Expand All @@ -24,7 +24,8 @@ import (
// Variables set by goreleaser process: https://goreleaser.com/cookbooks/using-main.version.
var (
// Version from git tag.
version = "dev"
version = "dev"
defaultConfigLocation = "/alicenet/mainnet/config.toml"
This conversation was marked as resolved.
Show resolved Hide resolved
)

type option struct {
Expand Down Expand Up @@ -177,7 +178,7 @@ func main() {

&firewalld.Command: {},

&validator.Command: {
&node.Command: {
{"validator.rewardAccount", "", "", &config.Configuration.Validator.RewardAccount},
{"validator.rewardCurveSpec", "", "", &config.Configuration.Validator.RewardCurveSpec},
},
Expand All @@ -194,7 +195,7 @@ func main() {
hierarchy := map[*cobra.Command]*cobra.Command{
&firewalld.Command: &rootCommand,
&bootnode.Command: &rootCommand,
&validator.Command: &rootCommand,
&node.Command: &rootCommand,
&ethkey.Command: &rootCommand,
&utils.Command: &rootCommand,
&utils.SendWeiCommand: &utils.Command,
Expand Down Expand Up @@ -248,6 +249,9 @@ func main() {
}
}

// If none command and option are present, the `node` command with the default --config option will be executed.
setDefaultCommandIfNonePresent(&node.Command, logger)

// This has to be registered prior to root command execute. Cobra executes this first thing when executing.
cobra.OnInitialize(func() {
// Read the config file
Expand Down Expand Up @@ -296,3 +300,23 @@ func main() {
}
logger.Debugf("main() -- Configuration:%v", config.Configuration.Ethereum)
}

// setDefaultCommandIfNonePresent to be able to run a node if none command is present.
func setDefaultCommandIfNonePresent(defaultCommand *cobra.Command, logger *logrus.Logger) {
if len(os.Args) != 1 {
return
}

// Adding the `node` command to args.
os.Args = append([]string{os.Args[0], defaultCommand.Use})

// Setting te default --config location if it is not present in command options.
if config.Configuration.ConfigurationFileName == "" {
homeDirectory, err := os.UserHomeDir()
if err != nil {
logger.Fatalf("failed to obtain user's home directory with error: %v", err)
}

config.Configuration.ConfigurationFileName = homeDirectory + defaultConfigLocation
}
}
4 changes: 2 additions & 2 deletions cmd/validator/validator.go → cmd/node/node.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package validator
package node

import (
"context"
Expand Down Expand Up @@ -47,7 +47,7 @@ import (

// Command is the cobra.Command specifically for running as a node.
var Command = cobra.Command{
Use: "validator",
Use: "node",
Short: "Starts a node",
Long: "Runs a AliceNet node in mining or non-mining mode",
Run: validatorNode,
Expand Down
1 change: 1 addition & 0 deletions constants/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var ValidLoggers []string = []string{
"services",
"settings",
"validator",
"node",
"muxhandler",
"bootnode",
"p2pmux",
Expand Down
6 changes: 3 additions & 3 deletions scripts/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ CHECK_EXISTING() {
RUN_VALIDATOR() {
# Run a validator
CHECK_EXISTING $1
./alicenet --config ./scripts/generated/config/validator$1.toml validator
./alicenet --config ./scripts/generated/config/validator$1.toml node
}

RUN_NODE() {
# Run a normal node (non validator)
CHECK_EXISTING $1
./alicenet --config ./scripts/generated/extra-nodes/config/node$1.toml validator
./alicenet --config ./scripts/generated/extra-nodes/config/node$1.toml node
}

RACE_VALIDATOR() {
# Run a validator
CHECK_EXISTING $1
./alicerace --config ./scripts/generated/config/validator$1.toml validator
./alicerace --config ./scripts/generated/config/validator$1.toml node
}

STATUS() {
Expand Down