Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
arturrez committed Dec 5, 2024
1 parent 8abf976 commit c71906d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
20 changes: 13 additions & 7 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,26 @@ func addValidator(_ *cobra.Command, args []string) error {

// if we don't have a nodeID or ProofOfPossession by this point, prompt user if we want to add a aditional local node
if (!sovereign && nodeIDStr == "") || (sovereign && !createLocalValidator && nodeIDStr == "" && publicKey == "" && pop == "") {
createLocalValidator, err = prompts.NewPrompter().CaptureNoYes(
"Would you like to add a local validator to this Blockchain?",
)
if err != nil {
return err
for {
local := "Use my local machine to spin up an additional validator"
existing := "I have an existing Avalanche node (we will require its NodeID and BLS info)"
option, err := app.Prompt.CaptureList(
"How would you like to set up the new validator",
[]string{local, existing},
)
if err != nil {
return err
}
createLocalValidator = option == local
break

Check failure on line 217 in cmd/blockchaincmd/add_validator.go

View workflow job for this annotation

GitHub Actions / Lint

SA4004: the surrounding loop is unconditionally terminated (staticcheck)
}
}

// if user chose to upsize a local node to add another local validator
if createLocalValidator {
anrSettings := node.ANRSettings{}
nodeConfig := map[string]interface{}{}
ux.Logger.PrintToUser("Adding a local validator to blockchain %s", blockchainName)
ux.Logger.PrintToUser("Creating a new Avalanche node on local machine to add as a new validator to blockchain %s", blockchainName)
if app.AvagoNodeConfigExists(blockchainName) {
nodeConfig, err = utils.ReadJSON(app.GetAvagoNodeConfigPath(blockchainName))
if err != nil {
Expand Down Expand Up @@ -294,7 +301,6 @@ func addValidator(_ *cobra.Command, args []string) error {
if !sovereign {
return CallAddValidatorNonSOV(deployer, network, kc, useLedger, blockchainName, nodeIDStr, defaultValidatorParams, waitForTxAcceptance)
}
ux.Logger.PrintToUser("Using extra aggregator endpoints: %s", aggregatorExtraEndpoints)
return CallAddValidator(deployer, network, kc, blockchainName, nodeIDStr, publicKey, pop)
}

Expand Down
17 changes: 9 additions & 8 deletions pkg/node/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,19 +552,19 @@ func UpsizeLocalNode(
}

spinSession := ux.NewUserSpinner()
spinner := spinSession.SpinToUser("Adding validator with name: %s to the existing local node", newNodeName)
spinner := spinSession.SpinToUser("Creating new node with name %s on local machine", newNodeName)
// add new local node
if _, err := cli.AddNode(ctx, newNodeName, avalancheGoBinPath, anrOpts...); err != nil {
ux.SpinFailWithError(spinner, "", err)
return newNodeName, fmt.Errorf("failed to add local valildator: %w", err)
return newNodeName, fmt.Errorf("failed to add local validator: %w", err)
}
ux.Logger.Info("Waiting for node: %s to be healthy", newNodeName)
_, err = subnet.WaitForHealthy(ctx, cli)
if err != nil {
return newNodeName, fmt.Errorf("failed waiting for network to become healthy: %w", err)
return newNodeName, fmt.Errorf("failed waiting for node %s to be healthy: %w", newNodeName, err)
}
ux.SpinComplete(spinner)
spinner = spinSession.SpinToUser("Tracking a subnet for new local validator")
spinner = spinSession.SpinToUser("Tracking blockchain %s", blockchainName)
time.Sleep(10 * time.Second) // delay before restarting new node
if err := LocalNodeTrackSubnet(ctx,
cli,
Expand All @@ -576,13 +576,13 @@ func UpsizeLocalNode(
subnetID,
newNodeName); err != nil {
ux.SpinFailWithError(spinner, "", err)
return newNodeName, fmt.Errorf("failed to track subnet: %w", err)
return newNodeName, fmt.Errorf("failed to track blockchain: %w", err)
}
// wait until cluster is healthy
spinner = spinSession.SpinToUser("Waiting for healthy local node")
spinner = spinSession.SpinToUser("Waiting for blockchain to be healthy")
clusterInfo, err := subnet.WaitForHealthy(ctx, cli)
if err != nil {
return newNodeName, fmt.Errorf("failed waiting for network to become healthy: %w", err)
return newNodeName, fmt.Errorf("failed waiting for blockchain to become healthy: %w", err)
}
ux.SpinComplete(spinner)
spinSession.Stop()
Expand All @@ -592,8 +592,9 @@ func UpsizeLocalNode(
ux.Logger.PrintToUser("")

nodeInfo := clusterInfo.NodeInfos[newNodeName]
ux.Logger.PrintToUser("Node name: %s ", newNodeName)
ux.Logger.PrintToUser("URI: %s", nodeInfo.Uri)
ux.Logger.PrintToUser("NodeID: %s", nodeInfo.Id)
ux.Logger.PrintToUser("Node-ID: %s", nodeInfo.Id)
ux.Logger.PrintToUser("")
return newNodeName, nil
}
Expand Down

0 comments on commit c71906d

Please sign in to comment.