Skip to content

Commit

Permalink
Merge branch 'acp-77' into register-validator-local
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemadero committed Oct 17, 2024
2 parents 6850ff1 + 662105f commit 86e1f0a
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============= Compilation Stage ================
FROM golang:1.22.7-bullseye AS builder
FROM golang:1.22.8-bullseye AS builder

WORKDIR /build
# Copy and download avalanche dependencies using go mod
Expand Down
23 changes: 8 additions & 15 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import (
"strings"
"time"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/network/peer"

"github.com/ava-labs/avalanche-cli/pkg/evm"
"github.com/ava-labs/avalanchego/api/info"

"github.com/ava-labs/avalanche-cli/pkg/node"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/message"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -142,6 +141,7 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().BoolVar(&convertOnly, "convert-only", false, "avoid node track, restart and poa manager setup")
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 @@ -493,21 +493,16 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
if localMachineCluster != "" {
// don't destroy cluster if local cluster name is provided
clusterName = localMachineCluster
} else {
// destroy any cluster with same name before we start local node
// we don't want to reuse snapshots from previous sessions
if utils.DirectoryExists(app.GetLocalDir(clusterName)) {
_ = node.DestroyLocalNode(app, clusterName)
}
} 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 := false
if network.Kind == models.EtnaDevnet {
useEtnaDevnet = true
}
useEtnaDevnet := network.Kind == models.EtnaDevnet
if avagoBinaryPath == "" {
ux.Logger.PrintToUser("Local build of Avalanche Go is required to create an Avalanche node using local machine")
ux.Logger.PrintToUser("Please download Avalanche Go repo at https://github.com/ava-labs/avalanchego and build from source through ./scripts/build.sh")
Expand All @@ -523,7 +518,6 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
}

if len(bootstrapEndpoints) > 0 {
var changeAddr string
for _, endpoint := range bootstrapEndpoints {
Expand All @@ -549,8 +543,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
ChangeOwnerAddr: changeAddr,
})
}
}
if len(bootstrapValidators) == 0 {
} else {
bootstrapValidators, err = promptBootstrapValidators(network)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/blockchaincmd/remove_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,18 @@ func removeValidator(_ *cobra.Command, args []string) error {

// TODO: implement getMinNonce
// getMinNonce gets minNonce associated with the validationID from P-Chain
func getMinNonce(validationID [32]byte) (uint64, error) {
func getMinNonce(validationID [32]byte) (uint64, error) { //nolint:all
return 0, nil
}

// TODO: implement getValidationID
// get validation ID for a node from P Chain
func getValidationID(nodeID ids.NodeID) [32]byte {
func getValidationID(nodeID ids.NodeID) [32]byte { //nolint:all
return [32]byte{}
}

// TODO: implement generateWarpMessageRemoveValidator
func generateWarpMessageRemoveValidator(validationID [32]byte, nonce, weight uint64) (warpPlatformVM.Message, error) {
func generateWarpMessageRemoveValidator(validationID [32]byte, nonce, weight uint64) (warpPlatformVM.Message, error) { //nolint:all
return warpPlatformVM.Message{}, nil
}

Expand Down
9 changes: 3 additions & 6 deletions cmd/nodecmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,9 @@ var (
iops int
volumeType string
volumeSize int
versionComments = map[string]string{
"v1.11.0-fuji": " (recommended for fuji durango)",
}
grafanaPkg string
wizSubnet string
publicHTTPPortAccess bool
grafanaPkg string
wizSubnet string
publicHTTPPortAccess bool
)

func newCreateCmd() *cobra.Command {
Expand Down
10 changes: 6 additions & 4 deletions cmd/nodecmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ func list(_ *cobra.Command, _ []string) error {
if err := node.CheckCluster(app, clusterName); err != nil {
return err
}
cloudIDs := clusterConf.GetCloudIDs()
nodeIDs := []string{}
for _, cloudID := range clusterConf.GetCloudIDs() {
for _, cloudID := range cloudIDs {
nodeIDStr := "----------------------------------------"
if clusterConf.IsAvalancheGoHost(cloudID) {
if nodeID, err := getNodeID(app.GetNodeInstanceDirPath(cloudID)); err != nil {
Expand All @@ -56,11 +57,12 @@ func list(_ *cobra.Command, _ []string) error {
}
nodeIDs = append(nodeIDs, nodeIDStr)
}
if clusterConf.External {
switch {
case clusterConf.External:
ux.Logger.PrintToUser("cluster %q (%s) EXTERNAL", clusterName, clusterConf.Network.Kind.String())
} else if clusterConf.Local {
case clusterConf.Local:
ux.Logger.PrintToUser("cluster %q (%s) LOCAL", clusterName, clusterConf.Network.Kind.String())
} else {
default:
ux.Logger.PrintToUser("Cluster %q (%s)", clusterName, clusterConf.Network.Kind.String())
}
for i, cloudID := range clusterConf.GetCloudIDs() {
Expand Down
20 changes: 20 additions & 0 deletions cmd/nodecmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The node local command suite provides a collection of commands related to local
cmd.AddCommand(newLocalDestroyCmd())
// node local track
cmd.AddCommand(newLocalTrackCmd())
// node local status
cmd.AddCommand(newLocalStatusCmd())
return cmd
}

Expand Down Expand Up @@ -112,6 +114,16 @@ func newLocalDestroyCmd() *cobra.Command {
}
}

func newLocalStatusCmd() *cobra.Command {
return &cobra.Command{
Use: "status",
Short: "(ALPHA Warning) Get status of local node",
Long: `Get status of local node.`,
Args: cobra.MaximumNArgs(1),
RunE: localStatus,
}
}

func localStartNode(_ *cobra.Command, args []string) error {
clusterName := args[0]
anrSettings := node.ANRSettings{
Expand Down Expand Up @@ -145,6 +157,14 @@ func localTrack(_ *cobra.Command, args []string) error {
return node.TrackSubnetWithLocalMachine(app, args[0], args[1])
}

func localStatus(_ *cobra.Command, args []string) error {
clusterName := ""
if len(args) > 0 {
clusterName = args[0]
}
return node.LocalStatus(app, clusterName)
}

func notImplementedForLocal(what string) error {
ux.Logger.PrintToUser("Unsupported cmd: %s is not supported by local clusters", logging.LightBlue.Wrap(what))
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/node/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"encoding/json"
"errors"
"fmt"
"sync"
"time"

"github.com/ava-labs/avalanche-cli/pkg/binutils"
"github.com/ava-labs/avalanche-cli/pkg/subnet"
"github.com/ava-labs/avalanche-cli/pkg/vm"
"sync"
"time"

"github.com/ava-labs/avalanche-cli/pkg/ansible"

Expand Down Expand Up @@ -58,12 +59,12 @@ func GetClusterNodes(app *application.Avalanche, clusterName string) ([]string,
if exists, err := CheckClusterExists(app, clusterName); err != nil || !exists {
return nil, fmt.Errorf("cluster %q not found", clusterName)
}
clustersConfig, err := app.LoadClustersConfig()
clusterConfig, err := app.GetClusterConfig(clusterName)
if err != nil {
return nil, err
}
clusterNodes := clustersConfig.Clusters[clusterName].Nodes
if len(clusterNodes) == 0 {
clusterNodes := clusterConfig.Nodes
if len(clusterNodes) == 0 && !clusterConfig.Local {
return nil, fmt.Errorf("no nodes found in cluster %s", clusterName)
}
return clusterNodes, nil
Expand Down Expand Up @@ -416,7 +417,6 @@ func promptAvalancheGoVersionChoice(app *application.Avalanche, latestReleaseVer
ux.Logger.PrintToUser(fmt.Sprintf("no subnet named %s found", useAvalanchegoVersionFromSubnet))
}
return AvalancheGoVersionSettings{UseAvalanchegoVersionFromSubnet: useAvalanchegoVersionFromSubnet}, nil

}
}

Expand Down
83 changes: 79 additions & 4 deletions pkg/node/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ package node

import (
"fmt"
"os"
"path/filepath"
"slices"

"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/binutils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
Expand All @@ -16,9 +20,8 @@ import (
"github.com/ava-labs/avalanche-network-runner/client"
anrutils "github.com/ava-labs/avalanche-network-runner/utils"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
"os"
"path/filepath"
)

func TrackSubnetWithLocalMachine(app *application.Avalanche, clusterName, blockchainName string) error {
Expand Down Expand Up @@ -296,7 +299,7 @@ func StartLocalNode(app *application.Avalanche, clusterName string, useEtnaDevne
spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...")
if _, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...); err != nil {
ux.SpinFailWithError(spinner, "", err)
DestroyLocalNode(app, clusterName)
_ = DestroyLocalNode(app, clusterName)
return fmt.Errorf("failed to start local avalanchego: %w", err)
}
ux.SpinComplete(spinner)
Expand Down Expand Up @@ -393,7 +396,7 @@ func addLocalClusterConfig(app *application.Avalanche, network models.Network) e
}

func DestroyLocalNode(app *application.Avalanche, clusterName string) error {
StopLocalNode(app)
_ = StopLocalNode(app)

rootDir := app.GetLocalDir(clusterName)
if err := os.RemoveAll(rootDir); err != nil {
Expand Down Expand Up @@ -447,3 +450,75 @@ func StopLocalNode(app *application.Avalanche) error {
ux.Logger.GreenCheckmarkToUser("avalanchego stopped")
return nil
}

func listLocalClusters(app *application.Avalanche, clusterNamesToInclude []string) (map[string]string, error) {
localClusters := map[string]string{} // map[clusterName]rootDir
clustersConfig, err := app.GetClustersConfig()
if err != nil {
return localClusters, err
}
for clusterName := range clustersConfig.Clusters {
if len(clusterNamesToInclude) == 0 || slices.Contains(clusterNamesToInclude, clusterName) {
if ok, err := checkClusterIsLocal(app, clusterName); err == nil && ok {
localClusters[clusterName] = app.GetLocalDir(clusterName)
}
}
}
return localClusters, nil
}

func LocalStatus(app *application.Avalanche, clusterName string) error {
clustersToList := make([]string, 0)
if clusterName != "" {
if ok, err := checkClusterIsLocal(app, clusterName); err != nil || !ok {
return fmt.Errorf("local cluster %q not found", clusterName)
}
clustersToList = append(clustersToList, clusterName)
}

// get currently running local cluster
ctx, cancel := utils.GetANRContext()
defer cancel()
currentlyRunningRootDir := ""
isHealthy := false
cli, _ := binutils.NewGRPCClientWithEndpoint( // ignore error as ANR might be not running
binutils.LocalClusterGRPCServerEndpoint,
binutils.WithAvoidRPCVersionCheck(true),
binutils.WithDialTimeout(constants.FastGRPCDialTimeout),
)
if cli != nil {
status, _ := cli.Status(ctx) // ignore error as ANR might be not running
if status != nil && status.ClusterInfo != nil {
if status.ClusterInfo.RootDataDir != "" {
currentlyRunningRootDir = status.ClusterInfo.RootDataDir
}
isHealthy = status.ClusterInfo.Healthy
}
}
localClusters, err := listLocalClusters(app, clustersToList)
if err != nil {
return fmt.Errorf("failed to list local clusters: %w", err)
}
if clusterName != "" {
ux.Logger.PrintToUser("%s %s", logging.LightBlue.Wrap("Local cluster:"), logging.Green.Wrap(clusterName))
} else {
ux.Logger.PrintToUser(logging.LightBlue.Wrap("Local clusters:"))
}
for clusterName, rootDir := range localClusters {
currenlyRunning := ""
healthStatus := ""
if rootDir == currentlyRunningRootDir {
currenlyRunning = fmt.Sprintf(" [%s]", logging.Blue.Wrap("Running"))
if isHealthy {
healthStatus = fmt.Sprintf(" [%s]", logging.Green.Wrap("Healthy"))
} else {
healthStatus = fmt.Sprintf(" [%s]", logging.Red.Wrap("Unhealthy"))
}
} else {
currenlyRunning = fmt.Sprintf(" [%s]", logging.Black.Wrap("Stopped"))
}
ux.Logger.PrintToUser("- %s: %s %s %s", clusterName, rootDir, currenlyRunning, healthStatus)
}

return nil
}
7 changes: 4 additions & 3 deletions pkg/subnet/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ func (d *PublicDeployer) AddValidatorNonSOV(
return false, tx, remainingSubnetAuthKeys, nil
}

//nolint:all
func (d *PublicDeployer) SetL1ValidatorWeight(
message warp.Message,
) (*txs.Tx, error) {
return nil, nil
}

//nolint:all
func (d *PublicDeployer) RegisterL1Validator(
balance uint64,
pop signer.ProofOfPossession,
Expand Down Expand Up @@ -898,11 +900,10 @@ func printFee(kind string, wallet primary.Wallet, unsignedTx txs.UnsignedTx) err
}
txFee, err := pFeeCalculator.CalculateFee(unsignedTx)
if err != nil {
if errors.Is(err, avagofee.ErrUnsupportedTx) {
ux.Logger.PrintToUser(logging.Yellow.Wrap("unable to get %s fee: not supported by %s calculator"), kind, calcKind)
} else {
if !errors.Is(err, avagofee.ErrUnsupportedTx) {
return err
}
ux.Logger.PrintToUser(logging.Yellow.Wrap("unable to get %s fee: not supported by %s calculator"), kind, calcKind)
} else {
ux.Logger.PrintToUser(logging.Yellow.Wrap("%s fee: %.9f AVAX"), kind, float64(txFee)/float64(units.Avax))
}
Expand Down

0 comments on commit 86e1f0a

Please sign in to comment.