Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use network name instead of cluster name on sidecar #2303

Open
wants to merge 11 commits into
base: acp-77
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ func addValidator(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
if network.ClusterName != "" {
globalNetworkFlags.ClusterName = network.ClusterName
network, err = models.ConvertClusterToNetwork(network)
if err != nil {
return err
}
}

fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee
kc, err := keychain.GetKeychainFromCmdLineFlags(
Expand Down Expand Up @@ -319,11 +326,10 @@ func CallAddValidator(
Addresses: disableOwnerAddrID,
}

extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints)
extraAggregatorPeers, err := GetAggregatorExtraPeers(globalNetworkFlags.ClusterName, aggregatorExtraEndpoints)
if err != nil {
return err
}

signedMessage, validationID, err := validatormanager.InitValidatorRegistration(
app,
network,
Expand Down
26 changes: 15 additions & 11 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
deployInfo.ICMMessengerAddress,
deployInfo.ICMRegistryAddress,
nil,
globalNetworkFlags.ClusterName,
); err != nil {
return err
}
Expand All @@ -504,7 +505,10 @@ 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, err = models.ConvertClusterToNetwork(network)
if err != nil {
return err
}
}
}
// ask user if we want to use local machine if cluster is not provided
Expand Down Expand Up @@ -533,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))
Expand All @@ -557,6 +560,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 {
Expand Down Expand Up @@ -814,12 +818,12 @@ 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
}

if !convertOnly && !generateNodeID {
clusterName := network.ClusterName
clusterName := globalNetworkFlags.ClusterName
if clusterName == "" {
clusterName, err = node.GetClusterNameFromList(app)
if err != nil {
Expand Down Expand Up @@ -870,7 +874,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
}
Expand Down Expand Up @@ -914,7 +918,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
}
}
Expand Down Expand Up @@ -1262,10 +1266,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
}
Expand All @@ -1275,14 +1279,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,
Expand Down
11 changes: 8 additions & 3 deletions cmd/blockchaincmd/remove_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -215,8 +220,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
}
Expand Down
11 changes: 10 additions & 1 deletion cmd/contractcmd/init_poa_validator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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"
Expand All @@ -31,6 +32,7 @@ var (
initPOAManagerSupportedNetworkOptions = []networkoptions.NetworkOption{
networkoptions.Local,
networkoptions.Devnet,
networkoptions.EtnaDevnet,
networkoptions.Fuji,
}
initPOAManagerFlags InitPOAManagerFlags
Expand Down Expand Up @@ -70,6 +72,12 @@ func initPOAManager(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
if network.ClusterName != "" {
network, err = models.ConvertClusterToNetwork(network)
if err != nil {
return err
}
}
if initPOAManagerFlags.rpcEndpoint == "" {
initPOAManagerFlags.rpcEndpoint, _, err = contract.GetBlockchainEndpoints(
app,
Expand Down Expand Up @@ -120,7 +128,8 @@ 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
extraAggregatorPeers, err := blockchaincmd.GetAggregatorExtraPeers(clusterName, initPOAManagerFlags.aggregatorExtraEndpoints)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/transactioncmd/transaction_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,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)
Expand All @@ -549,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)
Expand Down
20 changes: 20 additions & 0 deletions pkg/models/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package models

import (
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -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, "")
}
Expand Down
1 change: 1 addition & 0 deletions pkg/models/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type NetworkData struct {
RPCEndpoints []string
WSEndpoints []string
BootstrapValidators []SubnetValidator
ClusterName string
}

type Sidecar struct {
Expand Down
13 changes: 11 additions & 2 deletions pkg/node/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ func TrackSubnetWithLocalMachine(
return err
}
clusterConfig := clustersConfig.Clusters[clusterName]
network := clusterConfig.Network
network, err := GetNetworkFromCluster(clusterConfig)
if err != nil {
return err
}
if network.ClusterName != "" {
network, err = models.ConvertClusterToNetwork(network)
if err != nil {
return err
}
}
if sc.Networks[network.Name()].BlockchainID == ids.Empty {
return fmt.Errorf("blockchain %s has not been deployed to %s", blockchainName, network.Name())
}
Expand Down Expand Up @@ -130,7 +139,7 @@ func TrackSubnetWithLocalMachine(
return err
}
}
sc.Networks[clusterConfig.Network.Name()] = networkInfo
sc.Networks[network.Name()] = networkInfo
if err := app.UpdateSidecar(&sc); err != nil {
return err
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
var blockchainID = ""

const (
CLIBinary = "./bin/avalanche"
subnetName = "e2eSubnetTest"
keyName = "ewoq"
ewoqEVMAddress = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
Expand Down
Loading
Loading