Skip to content

Commit

Permalink
Use existing cluster deploy (#2271)
Browse files Browse the repository at this point in the history
* fix no local

* fix generatre nod eid

* integrate deploy

* fix lint

* rm local machine cluster

* check for bootstrap endpoints before populating this slice

* lint

* fix inventory err for local (#2272)

* fix merge

---------

Co-authored-by: Artur Reznikov <artur.reznikov@avalabs.org>
Co-authored-by: arturrez <56270896+arturrez@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 17, 2024
1 parent 3b6c74a commit b714322
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
51 changes: 33 additions & 18 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ var (
outputTxPath string
useLedger bool
useLocalMachine bool
localMachineCluster string
useEwoq bool
ledgerAddresses []string
sovereign bool
Expand Down Expand Up @@ -144,7 +143,6 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().StringVar(&aggregatorLogLevel, "aggregator-log-level", "Off", "log level to use with signature aggregator")
cmd.Flags().StringSliceVar(&aggregatorExtraEndpoints, "aggregator-extra-endpoints", nil, "endpoints for extra nodes that are needed in signature aggregation")
cmd.Flags().BoolVar(&useLocalMachine, "use-local-machine", false, "use local machine as a blockchain validator")
cmd.Flags().StringVar(&localMachineCluster, "local-machine-cluster", "", "existing local machine to be used as a blockchain validator")

return cmd
}
Expand Down Expand Up @@ -482,7 +480,28 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {

if sidecar.Sovereign {
if !convertOnly && !generateNodeID {
if !useLocalMachine {
clusterName := fmt.Sprintf("%s-local-node", blockchainName)
if globalNetworkFlags.ClusterName != "" {
clusterName = globalNetworkFlags.ClusterName
clusterConfig, err := app.GetClusterConfig(clusterName)
if err != nil {
return err
}
// check if cluster is local
if clusterConfig.Local {
useLocalMachine = true
if len(bootstrapEndpoints) == 0 {
bootstrapEndpoints, err = getLocalBootstrapEndpoints()
if err != nil {
return fmt.Errorf("error getting local host bootstrap endpoints: %w, "+
"please create your local node again and call subnet deploy command again", err)
}
}
network = models.NewNetworkFromCluster(network, clusterName)
}
}
// ask user if we wants to use local machine if cluster is not provided
if !useLocalMachine && globalNetworkFlags.ClusterName == "" {
ux.Logger.PrintToUser("You can use your local machine as a bootstrap validator on the blockchain")
ux.Logger.PrintToUser("This means that you don't have to to set up a remote server on a cloud service (e.g. AWS / GCP) to be a validator on the blockchain.")

Expand All @@ -491,20 +510,10 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
}
if useLocalMachine {
// stop any local avalanche go process running before we start local node
// if no cluster provided - we create one with fmt.Sprintf("%s-local-node", blockchainName) name
if useLocalMachine && globalNetworkFlags.ClusterName == "" {
// stop local avalanchego process so that we can generate new local cluster
_ = node.StopLocalNode(app)
clusterName := fmt.Sprintf("%s-local-node", blockchainName)
if localMachineCluster != "" {
// don't destroy cluster if local cluster name is provided
clusterName = localMachineCluster
} else if utils.DirectoryExists(app.GetLocalDir(clusterName)) {
_ = node.DestroyLocalNode(app, clusterName)
}
// destroy any cluster with same name before we start local node
// we don't want to reuse snapshots from previous sessions
// TODO: replace bootstrapEndpoints with dynamic port number
bootstrapEndpoints = []string{"http://127.0.0.1:9650"}
anrSettings := node.ANRSettings{}
avagoVersionSettings := node.AvalancheGoVersionSettings{}
useEtnaDevnet := network.Kind == models.EtnaDevnet
Expand All @@ -524,14 +533,21 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
clusterName,
useEtnaDevnet,
avagoBinaryPath,
1,
5,
anrSettings,
avagoVersionSettings,
globalNetworkFlags,
nil,
); err != nil {
return err
}
if len(bootstrapEndpoints) == 0 {
bootstrapEndpoints, err = getLocalBootstrapEndpoints()
if err != nil {
return fmt.Errorf("error getting local host bootstrap endpoints: %w, "+
"please create your local node again and call subnet deploy command again", err)
}
}
}
}
if len(bootstrapEndpoints) > 0 {
Expand Down Expand Up @@ -802,7 +818,6 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
}

if !useLocalMachine {
if err = node.SyncSubnet(app, clusterName, blockchainName, true, nil); err != nil {
return err
Expand Down
21 changes: 21 additions & 0 deletions cmd/blockchaincmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"fmt"
"time"

"github.com/ava-labs/avalanche-cli/pkg/binutils"
"github.com/ava-labs/avalanche-cli/pkg/utils"

"github.com/ava-labs/avalanche-cli/pkg/keychain"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
Expand Down Expand Up @@ -130,3 +133,21 @@ func UpdatePChainHeight(
fmt.Println()
return nil
}

func getLocalBootstrapEndpoints() ([]string, error) {
ctx, cancel := utils.GetANRContext()
defer cancel()
cli, err := binutils.NewGRPCClientWithEndpoint(binutils.LocalClusterGRPCServerEndpoint)
if err != nil {
return nil, err
}
status, err := cli.Status(ctx)
if err != nil {
return nil, err
}
localBootstrapEndpoints := []string{}
for _, nodeInfo := range status.ClusterInfo.NodeInfos {
localBootstrapEndpoints = append(localBootstrapEndpoints, nodeInfo.Uri)
}
return localBootstrapEndpoints, nil
}
3 changes: 2 additions & 1 deletion pkg/node/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ func checkClusterIsLocal(app *application.Avalanche, clusterName string) (bool,

func StartLocalNode(
app *application.Avalanche,
clusterName string, useEtnaDevnet bool,
clusterName string,
useEtnaDevnet bool,
avalanchegoBinaryPath string,
numNodes uint32,
anrSettings ANRSettings,
Expand Down

0 comments on commit b714322

Please sign in to comment.