From 6f17f3d724293b67694ed4eb4344a8a1e8b804ba Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Thu, 31 Oct 2024 13:04:25 -0400 Subject: [PATCH 01/11] use network instead of cluster --- cmd/blockchaincmd/deploy.go | 4 ++-- pkg/application/app.go | 24 +++++++++++++++++++++++- pkg/node/local.go | 10 ++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index e23765f18..333664139 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -504,7 +504,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { "please create your local node again and call subnet deploy command again", err) } } - network = models.NewNetworkFromCluster(network, clusterName) + //network = models.NewNetworkFromCluster(network, clusterName) } } // ask user if we want to use local machine if cluster is not provided @@ -533,7 +533,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { return err } } - network = models.NewNetworkFromCluster(network, clusterName) + //network = models.NewNetworkFromCluster(network, clusterName) nodeConfig := "" if app.AvagoNodeConfigExists(blockchainName) { nodeConfigBytes, err := os.ReadFile(app.GetAvagoNodeConfigPath(blockchainName)) diff --git a/pkg/application/app.go b/pkg/application/app.go index 463336b44..f7ef9d34f 100644 --- a/pkg/application/app.go +++ b/pkg/application/app.go @@ -5,6 +5,7 @@ package application import ( "encoding/json" "fmt" + avagoconstants "github.com/ava-labs/avalanchego/utils/constants" "os" "path/filepath" "strings" @@ -847,9 +848,30 @@ func (app *Avalanche) GetClusterNetwork(clusterName string) (models.Network, err if err != nil { return models.UndefinedNetwork, err } - return clusterConfig.Network, nil + network, err := GetNetworkFromCluster(clusterConfig) + if err != nil { + return models.UndefinedNetwork, err + } + //return clusterConfig.Network, nil + return network, nil } +// GetNetworkFromCluster gets the network that a cluster is on +func GetNetworkFromCluster(clusterConfig models.ClusterConfig) (models.Network, error) { + network := clusterConfig.Network + switch { + case network.ID == constants.LocalNetworkID: + return models.NewLocalNetwork(), nil + case network.ID == avagoconstants.FujiID: + return models.NewFujiNetwork(), nil + case network.ID == avagoconstants.MainnetID: + return models.NewMainnetNetwork(), nil + case network.ID == constants.EtnaDevnetNetworkID: + return models.NewEtnaDevnetNetwork(), nil + default: + return models.UndefinedNetwork, fmt.Errorf("unable to get network from cluster %s", network.ClusterName) + } +} func (app *Avalanche) ListClusterNames() ([]string, error) { if !app.ClustersConfigExists() { return []string{}, nil diff --git a/pkg/node/local.go b/pkg/node/local.go index e3fc12a0c..d6e9674c3 100644 --- a/pkg/node/local.go +++ b/pkg/node/local.go @@ -48,7 +48,12 @@ func TrackSubnetWithLocalMachine( return err } clusterConfig := clustersConfig.Clusters[clusterName] - network := clusterConfig.Network + //network := clusterConfig.Network + network, err := app.GetNetworkFromCluster(clusterConfig) + if err != nil { + return err + } + fmt.Printf("obtained network name %s \n", network.Name()) if sc.Networks[network.Name()].BlockchainID == ids.Empty { return fmt.Errorf("blockchain %s has not been deployed to %s", blockchainName, network.Name()) } @@ -130,7 +135,8 @@ func TrackSubnetWithLocalMachine( return err } } - sc.Networks[clusterConfig.Network.Name()] = networkInfo + //sc.Networks[clusterConfig.Network.Name()] = networkInfo + sc.Networks[network.Name()] = networkInfo if err := app.UpdateSidecar(&sc); err != nil { return err } From 6fd36c23e1ec8ef812a8f5fab1c64f1515634755 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Thu, 31 Oct 2024 17:19:44 -0400 Subject: [PATCH 02/11] replace clustername with network --- cmd/blockchaincmd/add_validator.go | 2 +- cmd/blockchaincmd/deploy.go | 18 +++++++------ cmd/blockchaincmd/remove_validator.go | 4 +-- cmd/contractcmd/init_poa_validator_manager.go | 7 +++-- cmd/transactioncmd/transaction_commit.go | 2 +- pkg/application/app.go | 26 +++---------------- pkg/models/sidecar.go | 1 + pkg/node/local.go | 2 +- pkg/node/node.go | 20 ++++++++++++++ 9 files changed, 44 insertions(+), 38 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index 6d8e31806..b45d42f36 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -319,7 +319,7 @@ func CallAddValidator( Addresses: disableOwnerAddrID, } - extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints) + extraAggregatorPeers, err := GetAggregatorExtraPeers(network.ClusterName, aggregatorExtraEndpoints) if err != nil { return err } diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 333664139..505d26993 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -479,6 +479,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { deployInfo.ICMMessengerAddress, deployInfo.ICMRegistryAddress, nil, + globalNetworkFlags.ClusterName, ); err != nil { return err } @@ -557,6 +558,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { ); err != nil { return err } + globalNetworkFlags.ClusterName = clusterName if len(bootstrapEndpoints) == 0 { bootstrapEndpoints, err = getLocalBootstrapEndpoints() if err != nil { @@ -814,7 +816,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { } fmt.Println() - if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", bootstrapValidators); err != nil { + if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", bootstrapValidators, globalNetworkFlags.ClusterName); err != nil { return err } @@ -870,7 +872,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { return err } evm.WaitForChainID(client) - extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints) + extraAggregatorPeers, err := GetAggregatorExtraPeers(globalNetworkFlags.ClusterName, aggregatorExtraEndpoints) if err != nil { return err } @@ -914,7 +916,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { ux.Logger.PrintToUser("Once the Avalanche Node(s) are created and are tracking the blockchain, call `avalanche contract initPoaManager %s` to finish conversion to sovereign L1", blockchainName) } } else { - if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", nil); err != nil { + if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", nil, globalNetworkFlags.ClusterName); err != nil { return err } } @@ -1262,10 +1264,10 @@ func ConvertURIToPeers(uris []string) ([]info.Peer, error) { } func GetAggregatorExtraPeers( - network models.Network, + clusterName string, extraURIs []string, ) ([]info.Peer, error) { - uris, err := GetAggregatorNetworkUris(network) + uris, err := GetAggregatorNetworkUris(clusterName) if err != nil { return nil, err } @@ -1275,14 +1277,14 @@ func GetAggregatorExtraPeers( return ConvertURIToPeers(uris) } -func GetAggregatorNetworkUris(network models.Network) ([]string, error) { +func GetAggregatorNetworkUris(clusterName string) ([]string, error) { aggregatorExtraPeerEndpointsUris := []string{} - if network.ClusterName != "" { + if clusterName != "" { clustersConfig, err := app.LoadClustersConfig() if err != nil { return nil, err } - clusterConfig := clustersConfig.Clusters[network.ClusterName] + clusterConfig := clustersConfig.Clusters[clusterName] if clusterConfig.Local { cli, err := binutils.NewGRPCClientWithEndpoint( binutils.LocalClusterGRPCServerEndpoint, diff --git a/cmd/blockchaincmd/remove_validator.go b/cmd/blockchaincmd/remove_validator.go index b1cc7320a..cb3371a5c 100644 --- a/cmd/blockchaincmd/remove_validator.go +++ b/cmd/blockchaincmd/remove_validator.go @@ -215,8 +215,8 @@ func removeValidatorSOV( } } ux.Logger.PrintToUser(logging.Yellow.Wrap("RPC Endpoint: %s"), rpcURL) - - extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints) + clusterName := sc.Networks[network.Name()].ClusterName + extraAggregatorPeers, err := GetAggregatorExtraPeers(clusterName, aggregatorExtraEndpoints) if err != nil { return err } diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index 90bd7c36f..7cc211ca0 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -4,7 +4,6 @@ package contractcmd import ( "fmt" - "github.com/ava-labs/avalanche-cli/cmd/blockchaincmd" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/contract" @@ -31,6 +30,7 @@ var ( initPOAManagerSupportedNetworkOptions = []networkoptions.NetworkOption{ networkoptions.Local, networkoptions.Devnet, + networkoptions.EtnaDevnet, networkoptions.Fuji, } initPOAManagerFlags InitPOAManagerFlags @@ -70,6 +70,7 @@ func initPOAManager(_ *cobra.Command, args []string) error { if err != nil { return err } + // TODO: put a network cluster converter to etna/ fuji / mainnet if initPOAManagerFlags.rpcEndpoint == "" { initPOAManagerFlags.rpcEndpoint, _, err = contract.GetBlockchainEndpoints( app, @@ -120,7 +121,9 @@ func initPOAManager(_ *cobra.Command, args []string) error { if err != nil { return err } - extraAggregatorPeers, err := blockchaincmd.GetAggregatorExtraPeers(network, initPOAManagerFlags.aggregatorExtraEndpoints) + clusterName := sc.Networks[network.Name()].ClusterName + fmt.Printf("obtained clusterName %s \n", clusterName) + extraAggregatorPeers, err := blockchaincmd.GetAggregatorExtraPeers(clusterName, initPOAManagerFlags.aggregatorExtraEndpoints) if err != nil { return err } diff --git a/cmd/transactioncmd/transaction_commit.go b/cmd/transactioncmd/transaction_commit.go index f1ff6568d..9a04b81e6 100644 --- a/cmd/transactioncmd/transaction_commit.go +++ b/cmd/transactioncmd/transaction_commit.go @@ -97,7 +97,7 @@ func commitTx(_ *cobra.Command, args []string) error { if err := blockchaincmd.PrintDeployResults(subnetName, subnetID, txID); err != nil { return err } - return app.UpdateSidecarNetworks(&sc, network, subnetID, txID, "", "", sc.Networks[network.Name()].BootstrapValidators) + return app.UpdateSidecarNetworks(&sc, network, subnetID, txID, "", "", sc.Networks[network.Name()].BootstrapValidators, "") } return nil diff --git a/pkg/application/app.go b/pkg/application/app.go index f7ef9d34f..ee021e523 100644 --- a/pkg/application/app.go +++ b/pkg/application/app.go @@ -5,7 +5,6 @@ package application import ( "encoding/json" "fmt" - avagoconstants "github.com/ava-labs/avalanchego/utils/constants" "os" "path/filepath" "strings" @@ -539,6 +538,7 @@ func (app *Avalanche) UpdateSidecarNetworks( teleporterMessengerAddress string, teleporterRegistryAddress string, bootstrapValidators []models.SubnetValidator, + clusterName string, ) error { if sc.Networks == nil { sc.Networks = make(map[string]models.NetworkData) @@ -550,6 +550,7 @@ func (app *Avalanche) UpdateSidecarNetworks( TeleporterMessengerAddress: teleporterMessengerAddress, TeleporterRegistryAddress: teleporterRegistryAddress, BootstrapValidators: bootstrapValidators, + ClusterName: clusterName, } if err := app.UpdateSidecar(sc); err != nil { return fmt.Errorf("creation of chains and subnet was successful, but failed to update sidecar: %w", err) @@ -848,30 +849,9 @@ func (app *Avalanche) GetClusterNetwork(clusterName string) (models.Network, err if err != nil { return models.UndefinedNetwork, err } - network, err := GetNetworkFromCluster(clusterConfig) - if err != nil { - return models.UndefinedNetwork, err - } - //return clusterConfig.Network, nil - return network, nil + return clusterConfig.Network, nil } -// GetNetworkFromCluster gets the network that a cluster is on -func GetNetworkFromCluster(clusterConfig models.ClusterConfig) (models.Network, error) { - network := clusterConfig.Network - switch { - case network.ID == constants.LocalNetworkID: - return models.NewLocalNetwork(), nil - case network.ID == avagoconstants.FujiID: - return models.NewFujiNetwork(), nil - case network.ID == avagoconstants.MainnetID: - return models.NewMainnetNetwork(), nil - case network.ID == constants.EtnaDevnetNetworkID: - return models.NewEtnaDevnetNetwork(), nil - default: - return models.UndefinedNetwork, fmt.Errorf("unable to get network from cluster %s", network.ClusterName) - } -} func (app *Avalanche) ListClusterNames() ([]string, error) { if !app.ClustersConfigExists() { return []string{}, nil diff --git a/pkg/models/sidecar.go b/pkg/models/sidecar.go index 502766a4d..e3b3a57ae 100644 --- a/pkg/models/sidecar.go +++ b/pkg/models/sidecar.go @@ -16,6 +16,7 @@ type NetworkData struct { RPCEndpoints []string WSEndpoints []string BootstrapValidators []SubnetValidator + ClusterName string } type Sidecar struct { diff --git a/pkg/node/local.go b/pkg/node/local.go index d6e9674c3..8fc9742ee 100644 --- a/pkg/node/local.go +++ b/pkg/node/local.go @@ -49,7 +49,7 @@ func TrackSubnetWithLocalMachine( } clusterConfig := clustersConfig.Clusters[clusterName] //network := clusterConfig.Network - network, err := app.GetNetworkFromCluster(clusterConfig) + network, err := GetNetworkFromCluster(clusterConfig) if err != nil { return err } diff --git a/pkg/node/node.go b/pkg/node/node.go index de21b32ed..204124f42 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -3,12 +3,32 @@ package node import ( + "fmt" "github.com/ava-labs/avalanche-cli/pkg/ansible" "github.com/ava-labs/avalanche-cli/pkg/application" + "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/utils" + avagoconstants "github.com/ava-labs/avalanchego/utils/constants" ) +// GetNetworkFromCluster gets the network that a cluster is on +func GetNetworkFromCluster(clusterConfig models.ClusterConfig) (models.Network, error) { + network := clusterConfig.Network + switch { + case network.ID == constants.LocalNetworkID: + return models.NewLocalNetwork(), nil + case network.ID == avagoconstants.FujiID: + return models.NewFujiNetwork(), nil + case network.ID == avagoconstants.MainnetID: + return models.NewMainnetNetwork(), nil + case network.ID == constants.EtnaDevnetNetworkID: + return models.NewEtnaDevnetNetwork(), nil + default: + return models.UndefinedNetwork, fmt.Errorf("unable to get network from cluster %s", network.ClusterName) + } +} + func GetHostWithCloudID(app *application.Avalanche, clusterName string, cloudID string) (*models.Host, error) { hosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName)) if err != nil { From 3b0877f212a202f2c6b5104c23efda0f10c9f8c4 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Sun, 3 Nov 2024 12:43:35 -0500 Subject: [PATCH 03/11] update test --- cmd/blockchaincmd/deploy.go | 4 + cmd/contractcmd/init_poa_validator_manager.go | 8 +- pkg/models/network.go | 20 +++ pkg/node/local.go | 6 + .../subnet/sov/addRemoveValidator/suite.go | 1 - tests/e2e/testcases/subnet/sov/etna/suite.go | 141 +++++++++++++++++- 6 files changed, 176 insertions(+), 4 deletions(-) diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 505d26993..3c837d027 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -505,6 +505,10 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { "please create your local node again and call subnet deploy command again", err) } } + network, err = models.ConvertClusterToNetwork(network) + if err != nil { + return err + } //network = models.NewNetworkFromCluster(network, clusterName) } } diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index 7cc211ca0..bd74349fa 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -7,6 +7,7 @@ import ( "github.com/ava-labs/avalanche-cli/cmd/blockchaincmd" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/contract" + "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" "github.com/ava-labs/avalanche-cli/pkg/prompts" "github.com/ava-labs/avalanche-cli/pkg/ux" @@ -70,7 +71,12 @@ func initPOAManager(_ *cobra.Command, args []string) error { if err != nil { return err } - // TODO: put a network cluster converter to etna/ fuji / mainnet + if network.ClusterName != "" { + network, err = models.ConvertClusterToNetwork(network) + if err != nil { + return err + } + } if initPOAManagerFlags.rpcEndpoint == "" { initPOAManagerFlags.rpcEndpoint, _, err = contract.GetBlockchainEndpoints( app, diff --git a/pkg/models/network.go b/pkg/models/network.go index f7af6069f..7cc04fb71 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -3,6 +3,7 @@ package models import ( + "errors" "fmt" "os" "strings" @@ -75,6 +76,25 @@ func NewDevnetNetwork(endpoint string, id uint32) Network { return NewNetwork(Devnet, id, endpoint, "") } +// ConvertClusterToNetwork converts a cluster network into a non cluster network +func ConvertClusterToNetwork(clusterNetwork Network) (Network, error) { + if clusterNetwork.ClusterName == "" { + return UndefinedNetwork, errors.New("no cluster network is provided") + } + switch { + case clusterNetwork.ID == constants.LocalNetworkID: + return NewLocalNetwork(), nil + case clusterNetwork.ID == avagoconstants.FujiID: + return NewFujiNetwork(), nil + case clusterNetwork.ID == avagoconstants.MainnetID: + return NewMainnetNetwork(), nil + case clusterNetwork.ID == constants.EtnaDevnetNetworkID: + return NewEtnaDevnetNetwork(), nil + default: + return UndefinedNetwork, fmt.Errorf("unable to get network from cluster network %s", clusterNetwork.ClusterName) + } +} + func NewEtnaDevnetNetwork() Network { return NewNetwork(EtnaDevnet, constants.EtnaDevnetNetworkID, constants.EtnaDevnetEndpoint, "") } diff --git a/pkg/node/local.go b/pkg/node/local.go index 8fc9742ee..983a67155 100644 --- a/pkg/node/local.go +++ b/pkg/node/local.go @@ -53,6 +53,12 @@ func TrackSubnetWithLocalMachine( if err != nil { return err } + if network.ClusterName != "" { + network, err = models.ConvertClusterToNetwork(network) + if err != nil { + return err + } + } fmt.Printf("obtained network name %s \n", network.Name()) if sc.Networks[network.Name()].BlockchainID == ids.Empty { return fmt.Errorf("blockchain %s has not been deployed to %s", blockchainName, network.Name()) diff --git a/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go b/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go index 2f5ca94eb..08d9b6331 100644 --- a/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go +++ b/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go @@ -16,7 +16,6 @@ import ( var blockchainID = "" const ( - CLIBinary = "./bin/avalanche" subnetName = "e2eSubnetTest" keyName = "ewoq" ewoqEVMAddress = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC" diff --git a/tests/e2e/testcases/subnet/sov/etna/suite.go b/tests/e2e/testcases/subnet/sov/etna/suite.go index ae70a0f06..aeb67ceea 100644 --- a/tests/e2e/testcases/subnet/sov/etna/suite.go +++ b/tests/e2e/testcases/subnet/sov/etna/suite.go @@ -82,7 +82,7 @@ func destroyLocalNode() { gomega.Expect(err).Should(gomega.BeNil()) } -func deployEtnaSubnet() { +func deployEtnaSubnetEtnaFlag() { // Check config exists exists, err := utils.SubnetConfigExists(subnetName) gomega.Expect(err).Should(gomega.BeNil()) @@ -112,8 +112,114 @@ func deployEtnaSubnet() { gomega.Expect(err).Should(gomega.BeNil()) } +func deployEtnaSubnetEtnaFlagConvertOnly() { + // Check config exists + exists, err := utils.SubnetConfigExists(subnetName) + gomega.Expect(err).Should(gomega.BeNil()) + gomega.Expect(exists).Should(gomega.BeTrue()) + + // Deploy subnet on etna devnet with local machine as bootstrap validator + cmd := exec.Command( + CLIBinary, + "blockchain", + "deploy", + subnetName, + "--etna-devnet", + "--use-local-machine", + avalancheGoPath+"="+utils.EtnaAvalancheGoBinaryPath, + "--num-local-nodes=1", + "--convert-only", + "--ewoq", + "--change-owner-address", + ewoqPChainAddress, + "--"+constants.SkipUpdateFlag, + ) + output, err := cmd.CombinedOutput() + fmt.Println(string(output)) + if err != nil { + fmt.Println(cmd.String()) + utils.PrintStdErr(err) + } + gomega.Expect(err).Should(gomega.BeNil()) +} + +func deployEtnaSubnetClusterFlagConvertOnly(clusterName string) { + // Check config exists + exists, err := utils.SubnetConfigExists(subnetName) + gomega.Expect(err).Should(gomega.BeNil()) + gomega.Expect(exists).Should(gomega.BeTrue()) + + // Deploy subnet on etna devnet with local machine as bootstrap validator + cmd := exec.Command( + CLIBinary, + "blockchain", + "deploy", + subnetName, + fmt.Sprintf("--cluster=%s", clusterName), + "--convert-only", + "--ewoq", + "--change-owner-address", + ewoqPChainAddress, + "--"+constants.SkipUpdateFlag, + ) + output, err := cmd.CombinedOutput() + fmt.Println(string(output)) + if err != nil { + fmt.Println(cmd.String()) + utils.PrintStdErr(err) + } + gomega.Expect(err).Should(gomega.BeNil()) +} + +func initPoaManagerClusterFlag( + subnetName string, + clusterName string, +) (string, error) { + cmd := exec.Command( + CLIBinary, + "contract", + "initPoaManager", + subnetName, + "--cluster", + clusterName, + "--genesis-key", + "--"+constants.SkipUpdateFlag, + ) + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(cmd.String()) + fmt.Println(string(output)) + utils.PrintStdErr(err) + } + gomega.Expect(err).Should(gomega.BeNil()) + return string(output), err +} + +func initPoaManagerEtnaFlag( + subnetName string, +) (string, error) { + cmd := exec.Command( + CLIBinary, + "contract", + "initPoaManager", + subnetName, + "--etna-devnet", + "--genesis-key", + "--"+constants.SkipUpdateFlag, + ) + output, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(cmd.String()) + fmt.Println(string(output)) + utils.PrintStdErr(err) + } + gomega.Expect(err).Should(gomega.BeNil()) + return string(output), err +} + var _ = ginkgo.Describe("[Etna Subnet SOV]", func() { ginkgo.BeforeEach(func() { + fmt.Printf("We are runnign before each \n") // key _ = utils.DeleteKey(keyName) output, err := commands.CreateKeyFromPath(keyName, utils.EwoqKeyPath) @@ -128,6 +234,7 @@ var _ = ginkgo.Describe("[Etna Subnet SOV]", func() { }) ginkgo.AfterEach(func() { + fmt.Printf("We are runnign after each \n") destroyLocalNode() commands.DeleteSubnetConfig(subnetName) err := utils.DeleteKey(keyName) @@ -136,6 +243,36 @@ var _ = ginkgo.Describe("[Etna Subnet SOV]", func() { }) ginkgo.It("Create Etna Subnet Config & Deploy the Subnet To Public Etna On Local Machine", func() { createEtnaSubnetEvmConfig() - deployEtnaSubnet() + deployEtnaSubnetEtnaFlag() + }) + + ginkgo.It("Start Local Node on Etna & Deploy the Subnet To Public Etna using cluster flag", func() { + _, err := commands.CreateLocalEtnaDevnetNode(testLocalNodeName, 1, utils.EtnaAvalancheGoBinaryPath) + gomega.Expect(err).Should(gomega.BeNil()) + createEtnaSubnetEvmConfig() + deployEtnaSubnetClusterFlagConvertOnly(testLocalNodeName) + _, err = commands.TrackLocalEtnaSubnet(testLocalNodeName, subnetName) + gomega.Expect(err).Should(gomega.BeNil()) + _, err = initPoaManagerClusterFlag(subnetName, testLocalNodeName) + gomega.Expect(err).Should(gomega.BeNil()) + }) + + ginkgo.It("Mix and match network and cluster flags test 1", func() { + _, err := commands.CreateLocalEtnaDevnetNode(testLocalNodeName, 1, utils.EtnaAvalancheGoBinaryPath) + gomega.Expect(err).Should(gomega.BeNil()) + createEtnaSubnetEvmConfig() + deployEtnaSubnetClusterFlagConvertOnly(testLocalNodeName) + _, err = commands.TrackLocalEtnaSubnet(testLocalNodeName, subnetName) + gomega.Expect(err).Should(gomega.BeNil()) + _, err = initPoaManagerEtnaFlag(subnetName) + gomega.Expect(err).Should(gomega.BeNil()) + }) + ginkgo.It("Mix and match network and cluster flags test 2", func() { + createEtnaSubnetEvmConfig() + deployEtnaSubnetEtnaFlagConvertOnly() + _, err := commands.TrackLocalEtnaSubnet(testLocalNodeName, subnetName) + gomega.Expect(err).Should(gomega.BeNil()) + _, err = initPoaManagerClusterFlag(subnetName, testLocalNodeName) + gomega.Expect(err).Should(gomega.BeNil()) }) }) From 2bc92363721f341f5c06afc0c97e3af2ba851f87 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Sun, 3 Nov 2024 20:23:59 -0500 Subject: [PATCH 04/11] fix test --- cmd/blockchaincmd/deploy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 3c837d027..9132d0b71 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -825,7 +825,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { } if !convertOnly && !generateNodeID { - clusterName := network.ClusterName + clusterName := globalNetworkFlags.ClusterName if clusterName == "" { clusterName, err = node.GetClusterNameFromList(app) if err != nil { From 4ab10af4a50f4139dea6a42184e3d894eb97ea04 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Sun, 3 Nov 2024 20:25:08 -0500 Subject: [PATCH 05/11] fix test --- tests/e2e/testcases/subnet/sov/etna/suite.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/e2e/testcases/subnet/sov/etna/suite.go b/tests/e2e/testcases/subnet/sov/etna/suite.go index aeb67ceea..ab4a09788 100644 --- a/tests/e2e/testcases/subnet/sov/etna/suite.go +++ b/tests/e2e/testcases/subnet/sov/etna/suite.go @@ -219,7 +219,6 @@ func initPoaManagerEtnaFlag( var _ = ginkgo.Describe("[Etna Subnet SOV]", func() { ginkgo.BeforeEach(func() { - fmt.Printf("We are runnign before each \n") // key _ = utils.DeleteKey(keyName) output, err := commands.CreateKeyFromPath(keyName, utils.EwoqKeyPath) @@ -234,7 +233,6 @@ var _ = ginkgo.Describe("[Etna Subnet SOV]", func() { }) ginkgo.AfterEach(func() { - fmt.Printf("We are runnign after each \n") destroyLocalNode() commands.DeleteSubnetConfig(subnetName) err := utils.DeleteKey(keyName) From 00f6028b42a51c3c8e158a4a02924121ea087b28 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Mon, 4 Nov 2024 13:07:52 -0500 Subject: [PATCH 06/11] fix lint --- cmd/blockchaincmd/deploy.go | 2 -- pkg/node/local.go | 2 -- tests/e2e/testcases/subnet/sov/etna/suite.go | 8 ++++---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 9132d0b71..eb5ab9772 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -509,7 +509,6 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { if err != nil { return err } - //network = models.NewNetworkFromCluster(network, clusterName) } } // ask user if we want to use local machine if cluster is not provided @@ -538,7 +537,6 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { return err } } - //network = models.NewNetworkFromCluster(network, clusterName) nodeConfig := "" if app.AvagoNodeConfigExists(blockchainName) { nodeConfigBytes, err := os.ReadFile(app.GetAvagoNodeConfigPath(blockchainName)) diff --git a/pkg/node/local.go b/pkg/node/local.go index 983a67155..063f85965 100644 --- a/pkg/node/local.go +++ b/pkg/node/local.go @@ -48,7 +48,6 @@ func TrackSubnetWithLocalMachine( return err } clusterConfig := clustersConfig.Clusters[clusterName] - //network := clusterConfig.Network network, err := GetNetworkFromCluster(clusterConfig) if err != nil { return err @@ -141,7 +140,6 @@ func TrackSubnetWithLocalMachine( return err } } - //sc.Networks[clusterConfig.Network.Name()] = networkInfo sc.Networks[network.Name()] = networkInfo if err := app.UpdateSidecar(&sc); err != nil { return err diff --git a/tests/e2e/testcases/subnet/sov/etna/suite.go b/tests/e2e/testcases/subnet/sov/etna/suite.go index ab4a09788..6976e4a16 100644 --- a/tests/e2e/testcases/subnet/sov/etna/suite.go +++ b/tests/e2e/testcases/subnet/sov/etna/suite.go @@ -174,7 +174,7 @@ func deployEtnaSubnetClusterFlagConvertOnly(clusterName string) { func initPoaManagerClusterFlag( subnetName string, clusterName string, -) (string, error) { +) error { cmd := exec.Command( CLIBinary, "contract", @@ -192,7 +192,7 @@ func initPoaManagerClusterFlag( utils.PrintStdErr(err) } gomega.Expect(err).Should(gomega.BeNil()) - return string(output), err + return err } func initPoaManagerEtnaFlag( @@ -251,7 +251,7 @@ var _ = ginkgo.Describe("[Etna Subnet SOV]", func() { deployEtnaSubnetClusterFlagConvertOnly(testLocalNodeName) _, err = commands.TrackLocalEtnaSubnet(testLocalNodeName, subnetName) gomega.Expect(err).Should(gomega.BeNil()) - _, err = initPoaManagerClusterFlag(subnetName, testLocalNodeName) + err = initPoaManagerClusterFlag(subnetName, testLocalNodeName) gomega.Expect(err).Should(gomega.BeNil()) }) @@ -270,7 +270,7 @@ var _ = ginkgo.Describe("[Etna Subnet SOV]", func() { deployEtnaSubnetEtnaFlagConvertOnly() _, err := commands.TrackLocalEtnaSubnet(testLocalNodeName, subnetName) gomega.Expect(err).Should(gomega.BeNil()) - _, err = initPoaManagerClusterFlag(subnetName, testLocalNodeName) + err = initPoaManagerClusterFlag(subnetName, testLocalNodeName) gomega.Expect(err).Should(gomega.BeNil()) }) }) From 2c9759fbda78178f10b5d0153e4c20bf921695f6 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Mon, 4 Nov 2024 13:25:04 -0500 Subject: [PATCH 07/11] fix lint --- cmd/contractcmd/init_poa_validator_manager.go | 1 + pkg/node/node.go | 1 + 2 files changed, 2 insertions(+) diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index bd74349fa..62b16f9ba 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -4,6 +4,7 @@ package contractcmd import ( "fmt" + "github.com/ava-labs/avalanche-cli/cmd/blockchaincmd" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/contract" diff --git a/pkg/node/node.go b/pkg/node/node.go index 204124f42..995bab1d0 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -4,6 +4,7 @@ package node import ( "fmt" + "github.com/ava-labs/avalanche-cli/pkg/ansible" "github.com/ava-labs/avalanche-cli/pkg/application" "github.com/ava-labs/avalanche-cli/pkg/constants" From e480cfc4797817a64192c1b5d2d5aa754c9e3fe3 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Tue, 5 Nov 2024 11:47:01 -0500 Subject: [PATCH 08/11] fix test --- cmd/blockchaincmd/add_validator.go | 6 ++++++ cmd/blockchaincmd/remove_validator.go | 7 ++++++- tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go | 3 +-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index b45d42f36..9bea17940 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -134,6 +134,12 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return err } + if network.ClusterName != "" { + network, err = models.ConvertClusterToNetwork(network) + if err != nil { + return err + } + } fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee kc, err := keychain.GetKeychainFromCmdLineFlags( diff --git a/cmd/blockchaincmd/remove_validator.go b/cmd/blockchaincmd/remove_validator.go index cb3371a5c..28be5d416 100644 --- a/cmd/blockchaincmd/remove_validator.go +++ b/cmd/blockchaincmd/remove_validator.go @@ -82,7 +82,12 @@ func removeValidator(_ *cobra.Command, args []string) error { if err != nil { return err } - + if network.ClusterName != "" { + network, err = models.ConvertClusterToNetwork(network) + if err != nil { + return err + } + } fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.TxFee kc, err := keychain.GetKeychainFromCmdLineFlags( app, diff --git a/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go b/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go index 08d9b6331..88332d68d 100644 --- a/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go +++ b/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go @@ -5,12 +5,11 @@ package subnet import ( "fmt" - "regexp" - "github.com/ava-labs/avalanche-cli/tests/e2e/commands" "github.com/ava-labs/avalanche-cli/tests/e2e/utils" ginkgo "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" + "regexp" ) var blockchainID = "" From 15bb8bf7d8ca8a729b66964b2020f4aa55702fa3 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Tue, 5 Nov 2024 11:49:02 -0500 Subject: [PATCH 09/11] fix lint --- tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go b/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go index 88332d68d..08d9b6331 100644 --- a/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go +++ b/tests/e2e/testcases/subnet/sov/addRemoveValidator/suite.go @@ -5,11 +5,12 @@ package subnet import ( "fmt" + "regexp" + "github.com/ava-labs/avalanche-cli/tests/e2e/commands" "github.com/ava-labs/avalanche-cli/tests/e2e/utils" ginkgo "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" - "regexp" ) var blockchainID = "" From b9503e3bb332debac4aad6f61fa72e1fd0e17e12 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Tue, 5 Nov 2024 16:35:06 -0500 Subject: [PATCH 10/11] fix test --- cmd/blockchaincmd/add_validator.go | 5 +++-- pkg/models/network.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index 9bea17940..f773c53e8 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -135,6 +135,7 @@ func addValidator(_ *cobra.Command, args []string) error { return err } if network.ClusterName != "" { + globalNetworkFlags.ClusterName = network.ClusterName network, err = models.ConvertClusterToNetwork(network) if err != nil { return err @@ -325,11 +326,11 @@ func CallAddValidator( Addresses: disableOwnerAddrID, } - extraAggregatorPeers, err := GetAggregatorExtraPeers(network.ClusterName, aggregatorExtraEndpoints) + extraAggregatorPeers, err := GetAggregatorExtraPeers(globalNetworkFlags.ClusterName, aggregatorExtraEndpoints) if err != nil { return err } - + fmt.Printf("extraAggregatorPeers %s \n", extraAggregatorPeers) signedMessage, validationID, err := validatormanager.InitValidatorRegistration( app, network, diff --git a/pkg/models/network.go b/pkg/models/network.go index 7cc04fb71..758543134 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -81,6 +81,7 @@ func ConvertClusterToNetwork(clusterNetwork Network) (Network, error) { if clusterNetwork.ClusterName == "" { return UndefinedNetwork, errors.New("no cluster network is provided") } + fmt.Printf("clusterNetwork.ID %s \n", clusterNetwork.ID) switch { case clusterNetwork.ID == constants.LocalNetworkID: return NewLocalNetwork(), nil From a88d80c405542d2be4e4e59781e3424ab6ceecd1 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Tue, 5 Nov 2024 16:38:18 -0500 Subject: [PATCH 11/11] fix lint --- cmd/blockchaincmd/add_validator.go | 1 - cmd/contractcmd/init_poa_validator_manager.go | 1 - pkg/models/network.go | 1 - pkg/node/local.go | 1 - 4 files changed, 4 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index f773c53e8..27de0e5bb 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -330,7 +330,6 @@ func CallAddValidator( if err != nil { return err } - fmt.Printf("extraAggregatorPeers %s \n", extraAggregatorPeers) signedMessage, validationID, err := validatormanager.InitValidatorRegistration( app, network, diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index 62b16f9ba..f67fca95c 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -129,7 +129,6 @@ func initPOAManager(_ *cobra.Command, args []string) error { return err } clusterName := sc.Networks[network.Name()].ClusterName - fmt.Printf("obtained clusterName %s \n", clusterName) extraAggregatorPeers, err := blockchaincmd.GetAggregatorExtraPeers(clusterName, initPOAManagerFlags.aggregatorExtraEndpoints) if err != nil { return err diff --git a/pkg/models/network.go b/pkg/models/network.go index 758543134..7cc04fb71 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -81,7 +81,6 @@ func ConvertClusterToNetwork(clusterNetwork Network) (Network, error) { if clusterNetwork.ClusterName == "" { return UndefinedNetwork, errors.New("no cluster network is provided") } - fmt.Printf("clusterNetwork.ID %s \n", clusterNetwork.ID) switch { case clusterNetwork.ID == constants.LocalNetworkID: return NewLocalNetwork(), nil diff --git a/pkg/node/local.go b/pkg/node/local.go index 063f85965..68940c779 100644 --- a/pkg/node/local.go +++ b/pkg/node/local.go @@ -58,7 +58,6 @@ func TrackSubnetWithLocalMachine( return err } } - fmt.Printf("obtained network name %s \n", network.Name()) if sc.Networks[network.Name()].BlockchainID == ids.Empty { return fmt.Errorf("blockchain %s has not been deployed to %s", blockchainName, network.Name()) }