Skip to content

Commit

Permalink
Merge branch 'acp-77' into node-create-local
Browse files Browse the repository at this point in the history
Signed-off-by: sukantoraymond <rsukanto@umich.edu>
  • Loading branch information
sukantoraymond authored Oct 15, 2024
2 parents 72c1464 + 4f797cb commit f22c1fd
Show file tree
Hide file tree
Showing 30 changed files with 747 additions and 587 deletions.
56 changes: 31 additions & 25 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"time"

"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 @@ -663,7 +665,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
deployer.CleanCacheWallet()
managerAddress := common.HexToAddress(validatormanager.ValidatorContractAddress)
isFullySigned, ConvertL1TxID, tx, remainingSubnetAuthKeys, err := deployer.ConvertL1(
isFullySigned, convertL1TxID, tx, remainingSubnetAuthKeys, err := deployer.ConvertL1(
controlKeys,
subnetAuthKeys,
subnetID,
Expand All @@ -677,7 +679,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}

savePartialTx = !isFullySigned && err == nil
ux.Logger.PrintToUser("ConvertL1Tx ID: %s", ConvertL1TxID)
ux.Logger.PrintToUser("ConvertL1Tx ID: %s", convertL1TxID)

if savePartialTx {
if err := SaveNotFullySignedTx(
Expand All @@ -695,7 +697,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {

bar, err := ux.TimedProgressBar(
30*time.Second,
"Waiting for Blockchain to be converted into Subnet Only Validator (SOV) Blockchain ...",
"Waiting for L1 to be converted into sovereign blockchain ...",
2,
)
if err != nil {
Expand Down Expand Up @@ -725,35 +727,31 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}

if false {
if !generateNodeID {
clusterName, err := node.GetClusterNameFromList(app)
if err != nil {
return err
}

if err = node.SyncSubnet(app, clusterName, blockchainName, true, nil); err != nil {
return err
}

if err := node.WaitForHealthyCluster(app, clusterName, node.HealthCheckTimeout, node.HealthCheckPoolTime); err != nil {
return err
}

chainSpec := contract.ChainSpec{
BlockchainName: blockchainName,
}
genesisAddress, genesisPrivateKey, err := contract.GetEVMSubnetPrefundedKey(
_, genesisPrivateKey, err := contract.GetEVMSubnetPrefundedKey(
app,
network,
chainSpec,
)
if err != nil {
return err
}
privateKey, err := privateKeyFlags.GetPrivateKey(app, genesisPrivateKey)
if err != nil {
return err
}
if privateKey == "" {
privateKey, err = prompts.PromptPrivateKey(
app.Prompt,
"Which key to you want to use to pay for initializing Validator Manager contract? (Uses Blockchain gas token)",
app.GetKeyDir(),
app.GetKey,
genesisAddress,
genesisPrivateKey,
)
if err != nil {
return err
}
}
rpcURL, _, err := contract.GetBlockchainEndpoints(
app,
network,
Expand All @@ -775,17 +773,25 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
contract.ChainSpec{
BlockchainName: blockchainName,
},
privateKey,
genesisPrivateKey,
common.HexToAddress(sidecar.PoAValidatorManagerOwner),
avaGoBootstrapValidators,
aggregatorExtraPeerEndpoints,
); err != nil {
return err
}
ux.Logger.GreenCheckmarkToUser("Subnet is successfully converted into Subnet Only Validator")
ux.Logger.GreenCheckmarkToUser("L1 is successfully converted to sovereign blockchain")
} else {
ux.Logger.GreenCheckmarkToUser("Generated Node ID and BLS info for bootstrap validator(s)")
ux.Logger.PrintToUser("To convert L1 to sovereign blockchain, create the corresponding Avalanche node(s) with the provided Node ID and BLS Info")
ux.Logger.PrintToUser("Created Node ID and BLS Info can be found at %s", app.GetSidecarPath(blockchainName))
ux.Logger.PrintToUser("Once the Avalanche Node(s) are created and are tracking the blockchain, call `avalanche contract initPoaManager %s` to finish converting L1 to sovereign blockchain", blockchainName)
}
} else {
if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", nil); err != nil {
return err
}
}

flags := make(map[string]string)
flags[constants.MetricsNetwork] = network.Name()
metrics.HandleTracking(cmd, constants.MetricsSubnetDeployCommand, app, flags)
Expand Down
3 changes: 2 additions & 1 deletion cmd/blockchaincmd/prompt_genesis_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@ func promptBootstrapValidators(network models.Network) ([]models.SubnetValidator
}
var setUpNodes bool
if generateNodeID {
setUpNodes = true
setUpNodes = false
} else {
setUpNodes, err = promptSetUpNodes()
if err != nil {
return nil, err
}
generateNodeID = !setUpNodes
}
previousAddr := ""
for len(subnetValidators) < numBootstrapValidators {
Expand Down
8 changes: 5 additions & 3 deletions cmd/nodecmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"sync"
"time"

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

awsAPI "github.com/ava-labs/avalanche-cli/pkg/cloud/aws"
"github.com/ava-labs/avalanche-cli/pkg/docker"

Expand Down Expand Up @@ -211,7 +213,7 @@ func preCreateChecks(clusterName string) error {
}

func checkClusterExternal(clusterName string) (bool, error) {
clusterExists, err := checkClusterExists(clusterName)
clusterExists, err := node.CheckClusterExists(app, clusterName)
if err != nil {
return false, fmt.Errorf("error checking cluster: %w", err)
}
Expand Down Expand Up @@ -399,7 +401,7 @@ func createNodes(cmd *cobra.Command, args []string) error {
} else {
if cloudService == constants.AWSCloudService {
// Get AWS Credential, region and AMI
if !(authorizeAccess || authorizedAccessFromSettings()) && (requestCloudAuth(constants.AWSCloudService) != nil) {
if !(authorizeAccess || node.AuthorizedAccessFromSettings(app)) && (requestCloudAuth(constants.AWSCloudService) != nil) {
return fmt.Errorf("cloud access is required")
}
ec2SvcMap, ami, numNodesMap, err := getAWSCloudConfig(awsProfile, false, nil, nodeType)
Expand Down Expand Up @@ -471,7 +473,7 @@ func createNodes(cmd *cobra.Command, args []string) error {
}
}
} else {
if !(authorizeAccess || authorizedAccessFromSettings()) && (requestCloudAuth(constants.GCPCloudService) != nil) {
if !(authorizeAccess || node.AuthorizedAccessFromSettings(app)) && (requestCloudAuth(constants.GCPCloudService) != nil) {
return fmt.Errorf("cloud access is required")
}
// Get GCP Credential, zone, Image ID, service account key file path, and GCP project name
Expand Down
6 changes: 4 additions & 2 deletions cmd/nodecmd/create_devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"sync"
"time"

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

"golang.org/x/exp/slices"

"github.com/ava-labs/avalanche-cli/pkg/ansible"
Expand Down Expand Up @@ -155,7 +157,7 @@ func generateCustomGenesis(
}

func setupDevnet(clusterName string, hosts []*models.Host, apiNodeIPMap map[string]string) error {
if err := checkCluster(clusterName); err != nil {
if err := node.CheckCluster(app, clusterName); err != nil {
return err
}
inventoryPath := app.GetAnsibleInventoryDirPath(clusterName)
Expand All @@ -178,7 +180,7 @@ func setupDevnet(clusterName string, hosts []*models.Host, apiNodeIPMap map[stri
} else {
endpointIP = ansibleHosts[ansibleHostIDs[0]].IP
}
endpoint := getAvalancheGoEndpoint(endpointIP)
endpoint := node.GetAvalancheGoEndpoint(endpointIP)
network := models.NewDevnetNetwork(endpoint, 0)
network = models.NewNetworkFromCluster(network, clusterName)

Expand Down
10 changes: 6 additions & 4 deletions cmd/nodecmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package nodecmd
import (
"fmt"

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

"github.com/ava-labs/avalanche-cli/cmd/blockchaincmd"
"github.com/ava-labs/avalanche-cli/pkg/ansible"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
Expand Down Expand Up @@ -41,7 +43,7 @@ It saves the deploy info both locally and remotely.
func deploySubnet(cmd *cobra.Command, args []string) error {
clusterName := args[0]
subnetName := args[1]
if err := checkCluster(clusterName); err != nil {
if err := node.CheckCluster(app, clusterName); err != nil {
return err
}
if _, err := blockchaincmd.ValidateSubnetNameAndGetChains([]string{subnetName}); err != nil {
Expand All @@ -61,12 +63,12 @@ func deploySubnet(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
defer disconnectHosts(hosts)
defer node.DisconnectHosts(hosts)
if !avoidChecks {
if err := checkHostsAreHealthy(hosts); err != nil {
if err := node.CheckHostsAreHealthy(hosts); err != nil {
return err
}
if err := checkHostsAreRPCCompatible(hosts, subnetName); err != nil {
if err := node.CheckHostsAreRPCCompatible(app, hosts, subnetName); err != nil {
return err
}
}
Expand Down
42 changes: 6 additions & 36 deletions cmd/nodecmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"strings"

nodePkg "github.com/ava-labs/avalanche-cli/pkg/node"

awsAPI "github.com/ava-labs/avalanche-cli/pkg/cloud/aws"
gcpAPI "github.com/ava-labs/avalanche-cli/pkg/cloud/gcp"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
Expand Down Expand Up @@ -146,7 +148,7 @@ func destroyNodes(_ *cobra.Command, args []string) error {
return Cleanup()
}
clusterName := args[0]
if err := checkCluster(clusterName); err != nil {
if err := nodePkg.CheckCluster(app, clusterName); err != nil {
return err
}
clusterConfig, err := app.GetClusterConfig(clusterName)
Expand All @@ -167,7 +169,7 @@ func destroyNodes(_ *cobra.Command, args []string) error {
if err := getDeleteConfigConfirmation(); err != nil {
return err
}
nodesToStop, err := getClusterNodes(clusterName)
nodesToStop, err := nodePkg.GetClusterNodes(app, clusterName)
if err != nil {
return err
}
Expand Down Expand Up @@ -234,7 +236,7 @@ func destroyNodes(_ *cobra.Command, args []string) error {
continue
}
if nodeConfig.CloudService == "" || nodeConfig.CloudService == constants.AWSCloudService {
if !(authorizeAccess || authorizedAccessFromSettings()) && (requestCloudAuth(constants.AWSCloudService) != nil) {
if !(authorizeAccess || nodePkg.AuthorizedAccessFromSettings(app)) && (requestCloudAuth(constants.AWSCloudService) != nil) {
return fmt.Errorf("cloud access is required")
}
if err = ec2SvcMap[nodeConfig.Region].DestroyAWSNode(nodeConfig, clusterName); err != nil {
Expand All @@ -256,7 +258,7 @@ func destroyNodes(_ *cobra.Command, args []string) error {
}
}
} else {
if !(authorizeAccess || authorizedAccessFromSettings()) && (requestCloudAuth(constants.GCPCloudService) != nil) {
if !(authorizeAccess || nodePkg.AuthorizedAccessFromSettings(app)) && (requestCloudAuth(constants.GCPCloudService) != nil) {
return fmt.Errorf("cloud access is required")
}
if gcpCloud == nil {
Expand Down Expand Up @@ -322,35 +324,3 @@ func getClusterMonitoringNode(clusterName string) (string, error) {
}
return clustersConfig.Clusters[clusterName].MonitoringInstance, nil
}

func checkCluster(clusterName string) error {
_, err := getClusterNodes(clusterName)
return err
}

func checkClusterExists(clusterName string) (bool, error) {
clustersConfig, err := app.GetClustersConfig()
if err != nil {
return false, err
}
_, ok := clustersConfig.Clusters[clusterName]
return ok, nil
}

func getClusterNodes(clusterName string) ([]string, error) {
if exists, err := checkClusterExists(clusterName); err != nil || !exists {
return nil, fmt.Errorf("cluster %q not found", clusterName)
}
clustersConfig, err := app.LoadClustersConfig()
if err != nil {
return nil, err
}
if clustersConfig.Clusters[clusterName].Local {
return []string{fmt.Sprintf("local: %s", clusterName)}, nil
}
clusterNodes := clustersConfig.Clusters[clusterName].Nodes
if len(clusterNodes) == 0 {
return nil, fmt.Errorf("no nodes found in cluster %s", clusterName)
}
return clusterNodes, nil
}
6 changes: 4 additions & 2 deletions cmd/nodecmd/dynamic_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"context"
"fmt"

nodePkg "github.com/ava-labs/avalanche-cli/pkg/node"

awsAPI "github.com/ava-labs/avalanche-cli/pkg/cloud/aws"
gcpAPI "github.com/ava-labs/avalanche-cli/pkg/cloud/gcp"

Expand Down Expand Up @@ -51,7 +53,7 @@ func getPublicIPsForNodesWithDynamicIP(nodesWithDynamicIP []models.NodeConfig) (
}
var publicIP map[string]string
if node.CloudService == constants.GCPCloudService {
if !(authorizeAccess || authorizedAccessFromSettings()) && (requestCloudAuth(constants.GCPCloudService) != nil) {
if !(authorizeAccess || nodePkg.AuthorizedAccessFromSettings(app)) && (requestCloudAuth(constants.GCPCloudService) != nil) {
return nil, fmt.Errorf("cloud access is required")
}
if gcpCloud == nil {
Expand Down Expand Up @@ -87,7 +89,7 @@ func getPublicIPsForNodesWithDynamicIP(nodesWithDynamicIP []models.NodeConfig) (
// - in ansible inventory file
// - in host config file
func updatePublicIPs(clusterName string) error {
clusterNodes, err := getClusterNodes(clusterName)
clusterNodes, err := nodePkg.GetClusterNodes(app, clusterName)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/nodecmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"path/filepath"

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

"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/models"
Expand Down Expand Up @@ -51,7 +53,7 @@ func exportFile(_ *cobra.Command, args []string) error {
ux.Logger.RedXToUser("file already exists, use --force to overwrite")
return nil
}
if err := checkCluster(clusterName); err != nil {
if err := node.CheckCluster(app, clusterName); err != nil {
ux.Logger.RedXToUser("cluster not found: %v", err)
return err
}
Expand Down
Loading

0 comments on commit f22c1fd

Please sign in to comment.