From bc89a4d1904a65f2b4c66b5dd6bea566410b70d2 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 1 Oct 2024 18:10:29 -0700 Subject: [PATCH 01/57] node local init --- cmd/nodecmd/create.go | 2 +- cmd/nodecmd/local.go | 103 ++++++++++++++++++++++++++++++++++++++++++ cmd/nodecmd/node.go | 2 + pkg/models/network.go | 35 ++++++++++++++ 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 cmd/nodecmd/local.go diff --git a/cmd/nodecmd/create.go b/cmd/nodecmd/create.go index 5f8d66553..2782cb0ca 100644 --- a/cmd/nodecmd/create.go +++ b/cmd/nodecmd/create.go @@ -900,7 +900,7 @@ func addNodeToClustersConfig(network models.Network, nodeID, clusterName string, } clusterConfig := clustersConfig.Clusters[clusterName] // if supplied network in argument is empty, don't change current cluster network in cluster_config.json - if network != models.UndefinedNetwork { + if !network.IsUndefined() { clusterConfig.Network = network } clusterConfig.HTTPAccess = constants.HTTPAccess(publicHTTPPortAccess) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go new file mode 100644 index 000000000..beb43d9d7 --- /dev/null +++ b/cmd/nodecmd/local.go @@ -0,0 +1,103 @@ +// Copyright (C) 2022, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. +package nodecmd + +import ( + "fmt" + + "github.com/ava-labs/avalanche-cli/pkg/models" + "github.com/ava-labs/avalanche-cli/pkg/networkoptions" + "github.com/ava-labs/avalanche-cli/pkg/utils" + "github.com/ava-labs/avalanche-cli/pkg/ux" + "github.com/spf13/cobra" +) + +var ( + bootstrapIDs []string + bootstrapIPs []string + genesisPath string + upgradePath string + useEtnaDevnet bool +) + +func newLocalCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "local", + Short: "(ALPHA Warning) Create a new validator on local machine", + Long: `(ALPHA Warning) This command is currently in experimental mode. + +The node local command sets up a validator on a local server. +The validator will be validating the Avalanche Primary Network and Subnet +of your choice. By default, the command runs an interactive wizard. It +walks you through all the steps you need to set up a validator. +Once this command is completed, you will have to wait for the validator +to finish bootstrapping on the primary network before running further +commands on it, e.g. validating a Subnet. You can check the bootstrapping +status by running avalanche node status local +`, + RunE: localNode, + PersistentPostRun: handlePostRun, + } + networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, false, createSupportedNetworkOptions) + cmd.Flags().BoolVar(&useLatestAvalanchegoReleaseVersion, "latest-avalanchego-version", false, "install latest avalanchego release version on node/s") + cmd.Flags().BoolVar(&useLatestAvalanchegoPreReleaseVersion, "latest-avalanchego-pre-release-version", false, "install latest avalanchego pre-release version on node/s") + cmd.Flags().StringVar(&useCustomAvalanchegoVersion, "custom-avalanchego-version", "", "install given avalanchego version on node/s") + cmd.Flags().StringVar(&useAvalanchegoVersionFromSubnet, "avalanchego-version-from-subnet", "", "install latest avalanchego version, that is compatible with the given subnet, on node/s") + cmd.Flags().StringArrayVar(&bootstrapIDs, "bootstrap-id", []string{}, "nodeIDs of bootstrap nodes") + cmd.Flags().StringArrayVar(&bootstrapIPs, "bootstrap-ip", []string{}, "IP:port pairs of bootstrap nodes") + cmd.Flags().StringVar(&genesisPath, "genesis", "", "path to genesis file") + cmd.Flags().StringVar(&upgradePath, "upgrade", "", "path to upgrade file") + cmd.Flags().BoolVar(&useEtnaDevnet, "etna-devnet", false, "use Etna devnet. Prepopulated with Etna DevNet bootstrap configuration along with genesis and upgrade files") + return cmd +} + +// stub for now +func preLocalChecks() error { + if useEtnaDevnet && !globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji { + return fmt.Errorf("etna devnet can only be used with devnet") + } + if useEtnaDevnet && genesisPath != "" { + return fmt.Errorf("etna devnet uses predefined genesis file") + } + if useEtnaDevnet && upgradePath != "" { + return fmt.Errorf("etna devnet uses predefined upgrade file") + } + if useEtnaDevnet && (len(bootstrapIDs) != 0 || len(bootstrapIPs) != 0) { + return fmt.Errorf("etna devnet uses predefined bootstrap configuration") + } + if len(bootstrapIDs) != len(bootstrapIPs) { + return fmt.Errorf("number of bootstrap IDs and bootstrap IP:port pairs must be equal") + } + if genesisPath != "" && !utils.FileExists(genesisPath) { + return fmt.Errorf("genesis file %s does not exist", genesisPath) + } + if upgradePath != "" && !utils.FileExists(upgradePath) { + return fmt.Errorf("upgrade file %s does not exist", upgradePath) + } + return nil +} + +func localNode(cmd *cobra.Command, args []string) error { + network, err := networkoptions.GetNetworkFromCmdLineFlags( + app, + "", + globalNetworkFlags, + false, + true, + createSupportedNetworkOptions, + "", + ) + if err != nil { + return err + } + globalNetworkFlags.UseDevnet = network.Kind == models.Devnet // set globalNetworkFlags.UseDevnet to true if network is devnet for further use + if err := preLocalChecks(); err != nil { + return err + } + avalancheGoVersion, err := getAvalancheGoVersion() + if err != nil { + return err + } + ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) + return nil +} diff --git a/cmd/nodecmd/node.go b/cmd/nodecmd/node.go index c67100453..e438470e8 100644 --- a/cmd/nodecmd/node.go +++ b/cmd/nodecmd/node.go @@ -58,5 +58,7 @@ rest of the commands to maintain your node and make your node a Subnet Validator cmd.AddCommand(newExportCmd()) // node import cmd.AddCommand(newImportCmd()) + // node local + cmd.AddCommand(newLocalCmd()) return cmd } diff --git a/pkg/models/network.go b/pkg/models/network.go index 08128c2fc..fc7a1d845 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -4,11 +4,14 @@ package models import ( "fmt" + "net/netip" "os" "strings" "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanchego/genesis" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/beacon" avagoconstants "github.com/ava-labs/avalanchego/utils/constants" ) @@ -20,6 +23,7 @@ const ( Fuji Local Devnet + Custom ) func (nk NetworkKind) String() string { @@ -32,6 +36,8 @@ func (nk NetworkKind) String() string { return "Local Network" case Devnet: return "Devnet" + case Custom: + return "Custom Network" } return "invalid network" } @@ -43,6 +49,14 @@ type Network struct { ClusterName string } +type CustomNetwork struct { + Network + GenesisData []byte + UpgradeData []byte + BootstrapIDs []ids.NodeID + BootstrapIPs beacon.Set +} + var UndefinedNetwork = Network{} func NewNetwork(kind NetworkKind, id uint32, endpoint string, clusterName string) Network { @@ -54,6 +68,27 @@ func NewNetwork(kind NetworkKind, id uint32, endpoint string, clusterName string } } +func (n Network) Customize(genesisData []byte, upgradeData []byte, bootstrapIDs []ids.NodeID, bootstrapIPs []netip.AddrPort) (CustomNetwork, error) { + if len(bootstrapIPs) != len(bootstrapIDs) { + return CustomNetwork{}, fmt.Errorf("number of bootstrap IDs and bootstrap IP:port pairs must be equal") + } + beaconSet := beacon.NewSet() + for index, ip := range bootstrapIPs { + beaconSet.Add(beacon.New(bootstrapIDs[index], ip)) + } + return CustomNetwork{ + Network: n, + GenesisData: genesisData, + UpgradeData: upgradeData, + BootstrapIDs: bootstrapIDs, + BootstrapIPs: beaconSet, + }, nil +} + +func (n Network) IsUndefined() bool { + return n.Kind == Undefined +} + func NewLocalNetwork() Network { return NewNetwork(Local, constants.LocalNetworkID, constants.LocalAPIEndpoint, "") } From 37da482f93d5f29bf118ef8cac4b0b90b49a0770 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Wed, 2 Oct 2024 12:55:53 -0700 Subject: [PATCH 02/57] hardcode etna devnet config --- cmd/nodecmd/local.go | 53 +++++++++++++++- pkg/constants/etna.go | 44 ++++++++++++++ pkg/constants/etnaDevnet/genesis.json | 87 +++++++++++++++++++++++++++ pkg/constants/etnaDevnet/upgrade.json | 16 +++++ pkg/models/network.go | 28 ++++++--- pkg/utils/net.go | 36 +++++++++++ 6 files changed, 252 insertions(+), 12 deletions(-) create mode 100644 pkg/constants/etna.go create mode 100644 pkg/constants/etnaDevnet/genesis.json create mode 100644 pkg/constants/etnaDevnet/upgrade.json diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index beb43d9d7..c2b465650 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -4,8 +4,9 @@ package nodecmd import ( "fmt" + "os" - "github.com/ava-labs/avalanche-cli/pkg/models" + "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" @@ -53,6 +54,14 @@ status by running avalanche node status local // stub for now func preLocalChecks() error { + // expand passed paths + if genesisPath != "" { + genesisPath = utils.ExpandHome(genesisPath) + } + if upgradePath != "" { + upgradePath = utils.ExpandHome(upgradePath) + } + // checks if useEtnaDevnet && !globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji { return fmt.Errorf("etna devnet can only be used with devnet") } @@ -90,7 +99,6 @@ func localNode(cmd *cobra.Command, args []string) error { if err != nil { return err } - globalNetworkFlags.UseDevnet = network.Kind == models.Devnet // set globalNetworkFlags.UseDevnet to true if network is devnet for further use if err := preLocalChecks(); err != nil { return err } @@ -99,5 +107,46 @@ func localNode(cmd *cobra.Command, args []string) error { return err } ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) + + genesisData := []byte{} + upgradeData := []byte{} + if useEtnaDevnet { + bootstrapIDs = constants.EtnaDevnetBootstrapNodeIDs + bootstrapIPs = constants.EtnaDevnetBootstrapIPs + genesisData = constants.EtnaDevnetGenesisData + upgradeData = constants.EtnaDevnetUpgradeData + } else { + // read genesis and upgrade files if passes + if genesisPath != "" && utils.FileExists(genesisPath) { + genesisData, err = os.ReadFile(genesisPath) + if err != nil { + return fmt.Errorf("could not read genesis file %s: %w", genesisPath, err) + } + } + if upgradePath != "" && utils.FileExists(upgradePath) { + upgradeData, err = os.ReadFile(upgradePath) + if err != nil { + return fmt.Errorf("could not read upgrade file %s: %w", upgradePath, err) + } + } + } + bootstrapConfigNodeIDs, err := utils.StringSliceToNodeIds(bootstrapIDs) + if err != nil { + return fmt.Errorf("could not convert bootstrap IDs: %w", err) + } + bootstrapConfigNodeIPs, err := utils.StringSliceToNetipPorts(bootstrapIPs) + if err != nil { + return fmt.Errorf("could not convert bootstrap IP:port pairs: %w", err) + } + customNetwork, err := network.Customize( + genesisData, + upgradeData, + bootstrapConfigNodeIDs, + bootstrapConfigNodeIPs, + ) + if err != nil { + return fmt.Errorf("could not configure network: %w", err) + } + return nil } diff --git a/pkg/constants/etna.go b/pkg/constants/etna.go new file mode 100644 index 000000000..8c6a3f7a9 --- /dev/null +++ b/pkg/constants/etna.go @@ -0,0 +1,44 @@ +// Copyright (C) 2022, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. +package constants + +import ( + _ "embed" +) + +//go:embed etnaDevnet/genesis.json +var EtnaDevnetGenesisData []byte + +//go:embed etnaDevnet/upgrade.json +var EtnaDevnetUpgradeData []byte + +const ( + EtnaDevnetEndpoint = "https://etna.avax-dev.network" +) + +var ( + EtnaDevnetBootstrapNodeIDs = []string{ + "NodeID-WrLWMK5sJ4dBUAsx1dP2FUyTqrYwbFA1", + "NodeID-bojBKDrpt81bYhxYKQfLw89V7CpoH2m7", + "NodeID-8LbTmmGsDC991SbD8Nkx88VULT3XYzYXC", + "NodeID-DDhXtFm6Q9tCq2yiFRmcSMKvHgUgh8yQC", + "NodeID-QDYnWDQd6g4cQ5H6yiWNqSmfRMBqEH9AG", + "NodeID-P5QGH4EXddrcyNAzkqyZKHXgEpVX6HExL", + "NodeID-78ibWpjtZz5ZGT6EyTEdu8VKmboUHTuGT", + "NodeID-7eRvnfs2a2PvrPHUuCRRpPVAoVjbWxaFG", + "NodeID-gpXWBExQSZXqJPQt6L6MnveUfgr7HJ4q", + "NodeID-L4CY8B5uVSDe4cnN1BpeDsHacMp4q4q8q", + } + EtnaDevnetBootstrapIPs = []string{ + "107.21.11.213:9651", + "34.233.248.130:9651", + "52.201.126.172:9651", + "35.170.144.5:9651", + "98.82.41.186:9651", + "34.228.34.127:9651", + "44.205.136.166:9651", + "52.6.31.40:9651", + "54.197.98.148:9651", + "18.211.108.228:9651", + } +) diff --git a/pkg/constants/etnaDevnet/genesis.json b/pkg/constants/etnaDevnet/genesis.json new file mode 100644 index 000000000..38cd96de0 --- /dev/null +++ b/pkg/constants/etnaDevnet/genesis.json @@ -0,0 +1,87 @@ +{ + "networkID": 76, + "allocations": [ + { + "ethAddr": "0xC71A61a815e49d16C425482A342a367CD42E38a6", + "avaxAddr": "X-custom1v6vuwxjgr043sg0nuuhq70k6vgnule692fvnr9", + "initialAmount": 500000000000000000, + "unlockSchedule": [ + { + "amount": 100000000000000000, + "locktime": 1633824000 + }, + { + "amount": 100000000000000000, + "locktime": 1633825000 + }, + { + "amount": 100000000000000000, + "locktime": 1633826000 + }, + { + "amount": 100000000000000000, + "locktime": 1633827000 + }, + { + "amount": 100000000000000000, + "locktime": 1633828000 + } + ] + } + ], + "startTime": 1725300000, + "initialStakeDuration": 31530000, + "initialStakeDurationOffset": 5400, + "initialStakedFunds": [ + "X-custom1v6vuwxjgr043sg0nuuhq70k6vgnule692fvnr9" + ], + "initialStakers": [ + { + "nodeID": "NodeID-gpXWBExQSZXqJPQt6L6MnveUfgr7HJ4q", + "rewardAddress": "X-custom1v6vuwxjgr043sg0nuuhq70k6vgnule692fvnr9", + "delegationFee": 62500, + "signer": { + "publicKey": "0xa14d67f097d7e6514696fd83080794b6b5ca664001f2ede4fd6f01da4933db875ff028fec42b29fc5524941e0f20830f", + "proofOfPossession": "0x82352ae1e01038173e92e088bd34c2bee9cc4b34df5c5e8bd2773cef9238eef870c2f93fa89607332ccbb84aa66608c706b7c2f127b8b80c461c04bbc6082afbffe220aac79f66533ea7c63f0451d7d32456369dd335c9710938ee4111d08d79" + } + }, + { + "nodeID": "NodeID-78ibWpjtZz5ZGT6EyTEdu8VKmboUHTuGT", + "rewardAddress": "X-custom1v6vuwxjgr043sg0nuuhq70k6vgnule692fvnr9", + "delegationFee": 62500, + "signer": { + "publicKey": "0x8327dbe1ba411c270637b080a8471fb41eeb8a9b3917af0727501ef8bdaa901d063780bd702f30f458a61f3d4297dc98", + "proofOfPossession": "0xa9c039b5765ab068bd632bbcdc9bc2a53f29e2c56b33e30d732a23d8c430d53ef47ebccfaa5cfcedd8f041c2c1348f0b0eac413192b7544d284f82d1fa0f74f98d5805905363b8186efdef6e77182fb1e7147f8511e900d195db06da6a22f0a0" + } + }, + { + "nodeID": "NodeID-L4CY8B5uVSDe4cnN1BpeDsHacMp4q4q8q", + "rewardAddress": "X-custom1v6vuwxjgr043sg0nuuhq70k6vgnule692fvnr9", + "delegationFee": 62500, + "signer": { + "publicKey": "0xa98c646a8c862ec15326e4cfe2a0f66a8fb7cf555765f83ff320a1a76268228f3c8b262d1de4008e0ba49a89cfabfb95", + "proofOfPossession": "0x95c816a4d292a47c4d9934e358621d0785fd2920a1a304cebc9b7e47417e3fff780cfcddf7ca1177b45bbfac2f9978581761d9ddd55ec6142d92998eeadbafe8cd7651056fbb79afea643f0cd20ff4f6389ddd91ee2db4579438a6908609b4c1" + } + }, + { + "nodeID": "NodeID-P5QGH4EXddrcyNAzkqyZKHXgEpVX6HExL", + "rewardAddress": "X-custom1v6vuwxjgr043sg0nuuhq70k6vgnule692fvnr9", + "delegationFee": 62500, + "signer": { + "publicKey": "0xb0d35ccf70a6d84e2bca1dc166a4c3324d7edd86e879add2ba6511c8ef6bfd89a15534e67467ccd9c9211534b33295a1", + "proofOfPossession": "0xa4b480a9a07b4a97630dd9d6e2bf4834a3e670448b5575e3ba72a03e06ec509ec859840a1104b18f0cd54696e6f98adb0e9f5260161332fe32a50cb1a9806b1b5025037731ea77c641d607fd0584ce29d7954f5e8f523c13a2e5732511227f50" + } + }, + { + "nodeID": "NodeID-7eRvnfs2a2PvrPHUuCRRpPVAoVjbWxaFG", + "rewardAddress": "X-custom1v6vuwxjgr043sg0nuuhq70k6vgnule692fvnr9", + "delegationFee": 62500, + "signer": { + "publicKey": "0xa5fde6042c6e0ee482f46346df046000cd57dd878d36637a5a62adec07a5114cdeea094a85f4f72b46645f94e9076692", + "proofOfPossession": "0x91444230c5ceb8e51642139e1842b56f8563865376b6f4205beca4dc0bb0bc4b314bce1e19e3b542a3941ece51ae205e03a094824fee28f9f702ed310756f0637bf166371656e1c3eb9001df89f4cdccc73410242a6d875eb6363d12bce40316" + } + } + ], + "cChainGenesis": "{\"config\":{\"chainId\":43117,\"homesteadBlock\":0,\"daoForkBlock\":0,\"daoForkSupport\":true,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x5f5e100\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0100000000000000000000000000000000000000\":{\"code\":\"0x7300000000000000000000000000000000000000003014608060405260043610603d5760003560e01c80631e010439146042578063b6510bb314606e575b600080fd5b605c60048036036020811015605657600080fd5b503560b1565b60408051918252519081900360200190f35b818015607957600080fd5b5060af60048036036080811015608e57600080fd5b506001600160a01b03813516906020810135906040810135906060013560b6565b005b30cd90565b836001600160a01b031681836108fc8690811502906040516000604051808303818888878c8acf9550505050505015801560f4573d6000803e3d6000fd5b505050505056fea26469706673582212201eebce970fe3f5cb96bf8ac6ba5f5c133fc2908ae3dcd51082cfee8f583429d064736f6c634300060a0033\",\"balance\":\"0x0\"},\"0x643F2454430E218750b5e6533d9C0e0Dd50B8d68\":{\"balance\":\"0x1431E0FAE6D7217CAA0000000\"},\"0xf9BFA4C45a8d830a591B3374320fd8CCF3FD75D4\":{\"balance\":\"0x1431E0FAE6D7217CAA0000000\"},\"0xD9d4f16a71E23eDf8e2F2a1Ebecd46B03177a22c\":{\"balance\":\"0x1431E0FAE6D7217CAA0000000\"},\"0x2a17831425bc6D20084D1526b1001C451ED4C4A7\":{\"balance\":\"0x1431E0FAE6D7217CAA0000000\"},\"0x7c5A8639F1e86F134f1E4239429f756A1441e322\":{\"balance\":\"0x1431E0FAE6D7217CAA0000000\"},\"0xfDDEf5cb0D09E483dBAB587BA958657B79A42E58\":{\"balance\":\"0x1431E0FAE6D7217CAA0000000\"},\"0xB4cA6C121D6287af7ac7cb62Ae33d2b054b9FC44\":{\"balance\":\"0x1431E0FAE6D7217CAA0000000\"},\"0xC71A61a815e49d16C425482A342a367CD42E38a6\":{\"balance\":\"0x1431E0FAE6D7217CAA0000000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}", + "message": "Etna here we come" +} diff --git a/pkg/constants/etnaDevnet/upgrade.json b/pkg/constants/etnaDevnet/upgrade.json new file mode 100644 index 000000000..914b8ba83 --- /dev/null +++ b/pkg/constants/etnaDevnet/upgrade.json @@ -0,0 +1,16 @@ +{ + "apricotPhase1Time": "2020-12-05T05:00:00Z", + "apricotPhase2Time": "2020-12-05T05:00:00Z", + "apricotPhase3Time": "2020-12-05T05:00:00Z", + "apricotPhase4Time": "2020-12-05T05:00:00Z", + "apricotPhase4MinPChainHeight": 0, + "apricotPhase5Time": "2020-12-05T05:00:00Z", + "apricotPhasePre6Time": "2020-12-05T05:00:00Z", + "apricotPhase6Time": "2020-12-05T05:00:00Z", + "apricotPhasePost6Time": "2020-12-05T05:00:00Z", + "banffTime": "2020-12-05T05:00:00Z", + "cortinaTime": "2020-12-05T05:00:00Z", + "cortinaXChainStopVertexID": "11111111111111111111111111111111LpoYY", + "durangoTime": "2020-12-05T05:00:00Z", + "etnaTime": "9999-12-01T00:00:00Z" +} diff --git a/pkg/models/network.go b/pkg/models/network.go index fc7a1d845..e63376e56 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -49,12 +49,16 @@ type Network struct { ClusterName string } +type BootstrapConfig struct { + NodeIDs []ids.NodeID + NodeIPs beacon.Set +} + type CustomNetwork struct { Network - GenesisData []byte - UpgradeData []byte - BootstrapIDs []ids.NodeID - BootstrapIPs beacon.Set + BootstrapConfig BootstrapConfig + GenesisData []byte + UpgradeData []byte } var UndefinedNetwork = Network{} @@ -74,14 +78,18 @@ func (n Network) Customize(genesisData []byte, upgradeData []byte, bootstrapIDs } beaconSet := beacon.NewSet() for index, ip := range bootstrapIPs { - beaconSet.Add(beacon.New(bootstrapIDs[index], ip)) + if err := beaconSet.Add(beacon.New(bootstrapIDs[index], ip)); err != nil { + return CustomNetwork{}, fmt.Errorf("failed to add bootstrap IP:port pair: %w", err) + } } return CustomNetwork{ - Network: n, - GenesisData: genesisData, - UpgradeData: upgradeData, - BootstrapIDs: bootstrapIDs, - BootstrapIPs: beaconSet, + Network: n, + GenesisData: genesisData, + UpgradeData: upgradeData, + BootstrapConfig: BootstrapConfig{ + NodeIDs: bootstrapIDs, + NodeIPs: beaconSet, + }, }, nil } diff --git a/pkg/utils/net.go b/pkg/utils/net.go index 99dad17a2..471dcbf70 100644 --- a/pkg/utils/net.go +++ b/pkg/utils/net.go @@ -8,7 +8,11 @@ import ( "io" "net" "net/http" + "net/netip" "net/url" + "strings" + + "github.com/ava-labs/avalanchego/ids" ) // GetUserIPAddress retrieves the IP address of the user. @@ -56,3 +60,35 @@ func IsValidURL(urlString string) bool { } return true } + +func StringSliceToNodeIds(s []string) ([]ids.NodeID, error) { + nodeIDs := []ids.NodeID{} + for _, id := range s { + id = strings.Trim(id, " ") + if id == "" { + continue + } + nodeId, err := ids.NodeIDFromString(id) + if err != nil { + return nil, err + } + nodeIDs = append(nodeIDs, nodeId) + } + return nodeIDs, nil +} + +func StringSliceToNetipPorts(s []string) ([]netip.AddrPort, error) { + var nodeIds []netip.AddrPort + for _, id := range s { + id = strings.Trim(id, " ") + if id == "" { + continue + } + addrPort, err := netip.ParseAddrPort(id) + if err != nil { + return nil, err + } + nodeIds = append(nodeIds, addrPort) + } + return nodeIds, nil +} From 9459b43b1903867d7bcaeab298371efbb2224b74 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Wed, 2 Oct 2024 18:43:31 -0700 Subject: [PATCH 03/57] wip --- cmd/networkcmd/start.go | 4 +- cmd/nodecmd/local.go | 214 +++++++++++++++++++++++++++++++------ go.mod | 6 +- go.sum | 8 ++ pkg/application/app.go | 4 + pkg/constants/constants.go | 1 + pkg/models/network.go | 22 ---- pkg/utils/net.go | 10 +- 8 files changed, 207 insertions(+), 62 deletions(-) diff --git a/cmd/networkcmd/start.go b/cmd/networkcmd/start.go index ab19a9160..aca86c4a8 100644 --- a/cmd/networkcmd/start.go +++ b/cmd/networkcmd/start.go @@ -85,7 +85,7 @@ func StartNetwork(*cobra.Command, []string) error { ctx, cancel := utils.GetANRContext() defer cancel() - bootstrapped, err := checkNetworkIsAlreadyBootstrapped(ctx, cli) + bootstrapped, err := CheckNetworkIsAlreadyBootstrapped(ctx, cli) if err != nil { return err } @@ -243,7 +243,7 @@ func determineAvagoVersion(userProvidedAvagoVersion string) (string, error) { ) } -func checkNetworkIsAlreadyBootstrapped(ctx context.Context, cli client.Client) (bool, error) { +func CheckNetworkIsAlreadyBootstrapped(ctx context.Context, cli client.Client) (bool, error) { _, err := cli.Status(ctx) if err != nil { if server.IsServerError(err, server.ErrNotBootstrapped) { diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index c2b465650..8d74a09e5 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -5,15 +5,25 @@ package nodecmd import ( "fmt" "os" + "path/filepath" + "github.com/ava-labs/avalanche-cli/cmd/networkcmd" + "github.com/ava-labs/avalanche-cli/pkg/binutils" + "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/constants" + "github.com/ava-labs/avalanche-cli/pkg/localnet" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" + "github.com/ava-labs/avalanche-cli/pkg/subnet" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" + "github.com/ava-labs/avalanche-network-runner/client" + anrutils "github.com/ava-labs/avalanche-network-runner/utils" "github.com/spf13/cobra" ) var ( + avalanchegoBinaryPath string + bootstrapIDs []string bootstrapIPs []string genesisPath string @@ -24,10 +34,28 @@ var ( func newLocalCmd() *cobra.Command { cmd := &cobra.Command{ Use: "local", + Short: "(ALPHA Warning) Suite of commands for a local avalanche node", + Long: `(ALPHA Warning) This command is currently in experimental mode. + +The node local command suite provides a collection of commands related to local nodes`, + RunE: cobrautils.CommandSuiteUsage, + } + // node local start + cmd.AddCommand(newLocalStartCmd()) + // node local stop + cmd.AddCommand(newLocalStopCmd()) + // node local cleanup + cmd.AddCommand(newLocalCleanupCmd()) + return cmd +} + +func newLocalStartCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "start", Short: "(ALPHA Warning) Create a new validator on local machine", Long: `(ALPHA Warning) This command is currently in experimental mode. -The node local command sets up a validator on a local server. +The node local start command sets up a validator on a local server. The validator will be validating the Avalanche Primary Network and Subnet of your choice. By default, the command runs an interactive wizard. It walks you through all the steps you need to set up a validator. @@ -36,14 +64,14 @@ to finish bootstrapping on the primary network before running further commands on it, e.g. validating a Subnet. You can check the bootstrapping status by running avalanche node status local `, - RunE: localNode, + RunE: localStartNode, PersistentPostRun: handlePostRun, } networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, false, createSupportedNetworkOptions) cmd.Flags().BoolVar(&useLatestAvalanchegoReleaseVersion, "latest-avalanchego-version", false, "install latest avalanchego release version on node/s") cmd.Flags().BoolVar(&useLatestAvalanchegoPreReleaseVersion, "latest-avalanchego-pre-release-version", false, "install latest avalanchego pre-release version on node/s") cmd.Flags().StringVar(&useCustomAvalanchegoVersion, "custom-avalanchego-version", "", "install given avalanchego version on node/s") - cmd.Flags().StringVar(&useAvalanchegoVersionFromSubnet, "avalanchego-version-from-subnet", "", "install latest avalanchego version, that is compatible with the given subnet, on node/s") + cmd.Flags().StringVar(&avalanchegoBinaryPath, "avalanchego-path", "", "use this avalanchego binary path") cmd.Flags().StringArrayVar(&bootstrapIDs, "bootstrap-id", []string{}, "nodeIDs of bootstrap nodes") cmd.Flags().StringArrayVar(&bootstrapIPs, "bootstrap-ip", []string{}, "IP:port pairs of bootstrap nodes") cmd.Flags().StringVar(&genesisPath, "genesis", "", "path to genesis file") @@ -52,6 +80,24 @@ status by running avalanche node status local return cmd } +func newLocalStopCmd() *cobra.Command { + return &cobra.Command{ + Use: "stop", + Short: "(ALPHA Warning) Stop local node", + Long: `Stop local node.`, + RunE: localStopNode, + } +} + +func newLocalCleanupCmd() *cobra.Command { + return &cobra.Command{ + Use: "cleanup", + Short: "(ALPHA Warning) Cleanup local node", + Long: `Cleanup local node.`, + RunE: localCleanupNode, + } +} + // stub for now func preLocalChecks() error { // expand passed paths @@ -62,6 +108,12 @@ func preLocalChecks() error { upgradePath = utils.ExpandHome(upgradePath) } // checks + if useCustomAvalanchegoVersion != "" && (useLatestAvalanchegoReleaseVersion || useLatestAvalanchegoPreReleaseVersion) { + return fmt.Errorf("specify either --custom-avalanchego-version or --latest-avalanchego-version") + } + if avalanchegoBinaryPath != "" && (useLatestAvalanchegoReleaseVersion || useLatestAvalanchegoPreReleaseVersion || useCustomAvalanchegoVersion != "") { + return fmt.Errorf("specify either --avalanchego-path or --latest-avalanchego-version or --custom-avalanchego-version") + } if useEtnaDevnet && !globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji { return fmt.Errorf("etna devnet can only be used with devnet") } @@ -86,7 +138,7 @@ func preLocalChecks() error { return nil } -func localNode(cmd *cobra.Command, args []string) error { +func localStartNode(cmd *cobra.Command, args []string) error { network, err := networkoptions.GetNetworkFromCmdLineFlags( app, "", @@ -108,45 +160,147 @@ func localNode(cmd *cobra.Command, args []string) error { } ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) - genesisData := []byte{} - upgradeData := []byte{} if useEtnaDevnet { bootstrapIDs = constants.EtnaDevnetBootstrapNodeIDs bootstrapIPs = constants.EtnaDevnetBootstrapIPs - genesisData = constants.EtnaDevnetGenesisData - upgradeData = constants.EtnaDevnetUpgradeData - } else { - // read genesis and upgrade files if passes - if genesisPath != "" && utils.FileExists(genesisPath) { - genesisData, err = os.ReadFile(genesisPath) - if err != nil { - return fmt.Errorf("could not read genesis file %s: %w", genesisPath, err) - } + // prepare genesis and upgrade files for anr + genesisFile, err := os.CreateTemp("", "etna_devnet_genesis") + if err != nil { + return fmt.Errorf("could not create save Etna Devnet genesis file: %w", err) + } + if _, err := genesisFile.Write(constants.EtnaDevnetGenesisData); err != nil { + return fmt.Errorf("could not write Etna Devnet genesis data: %w", err) + } + genesisFile.Close() + genesisPath = genesisFile.Name() + defer os.Remove(genesisPath) + + upgradeFile, err := os.CreateTemp("", "etna_devnet_upgrade") + if err != nil { + return fmt.Errorf("could not create save Etna Devnet upgrade file: %w", err) + } + if _, err := upgradeFile.Write(constants.EtnaDevnetUpgradeData); err != nil { + return fmt.Errorf("could not write Etna Devnet upgrade data: %w", err) + } + upgradePath = upgradeFile.Name() + upgradeFile.Close() + defer os.Remove(upgradePath) + } + if err != nil { + return fmt.Errorf("could not configure network: %w", err) + } + + sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") + + if err := sd.StartServer(); err != nil { + return err + } + + needsRestart, avalancheGoBinPath, err := sd.SetupLocalEnv() + if err != nil { + return err + } + + cli, err := binutils.NewGRPCClient() + if err != nil { + return err + } + + ctx, cancel := utils.GetANRContext() + defer cancel() + + bootstrapped, err := networkcmd.CheckNetworkIsAlreadyBootstrapped(ctx, cli) + if err != nil { + return err + } + + if bootstrapped { + if !needsRestart { + ux.Logger.PrintToUser("Network has already been booted.") + return nil } - if upgradePath != "" && utils.FileExists(upgradePath) { - upgradeData, err = os.ReadFile(upgradePath) - if err != nil { - return fmt.Errorf("could not read upgrade file %s: %w", upgradePath, err) - } + if _, err := cli.Stop(ctx); err != nil { + return err } + if err := app.ResetPluginsDir(); err != nil { + return err + } + } + + rootDir := app.GetLocalDir() + //make sure rootDir exists + if err := os.MkdirAll(rootDir, 0o700); err != nil { + return fmt.Errorf("could not create root directory %s: %w", rootDir, err) } - bootstrapConfigNodeIDs, err := utils.StringSliceToNodeIds(bootstrapIDs) + ux.Logger.PrintToUser("Starting local avalanchego node using root: %s ...", rootDir) + logDir, err := anrutils.MkDirWithTimestamp(filepath.Join(app.GetRunDir(), "network")) if err != nil { - return fmt.Errorf("could not convert bootstrap IDs: %w", err) + return err + } + pluginDir := app.GetPluginsDir() + anrOpts := []client.OpOption{ + client.WithNumNodes(1), + client.WithNetworkID(network.ID), + client.WithExecPath(avalancheGoBinPath), + client.WithRootDataDir(rootDir), + client.WithLogRootDir(logDir), + client.WithReassignPortsIfUsed(true), + client.WithPluginDir(pluginDir), } - bootstrapConfigNodeIPs, err := utils.StringSliceToNetipPorts(bootstrapIPs) + // load global node configs if they exist + configStr, err := app.Conf.LoadNodeConfig() if err != nil { - return fmt.Errorf("could not convert bootstrap IP:port pairs: %w", err) + return err + } + if configStr != "" { + anrOpts = append(anrOpts, client.WithGlobalNodeConfig(configStr)) + } + if genesisPath != "" && utils.FileExists(genesisPath) { + anrOpts = append(anrOpts, client.WithGenesisPath(genesisPath)) + } + if upgradePath != "" && utils.FileExists(upgradePath) { + anrOpts = append(anrOpts, client.WithUpgradePath(upgradePath)) + } + if bootstrapIDs != nil { + anrOpts = append(anrOpts, client.WithBootstrapNodeIDs(bootstrapIDs)) + } + if bootstrapIPs != nil { + anrOpts = append(anrOpts, client.WithBootstrapNodeIPPortPairs(bootstrapIPs)) } - customNetwork, err := network.Customize( - genesisData, - upgradeData, - bootstrapConfigNodeIDs, - bootstrapConfigNodeIPs, + + ux.Logger.PrintToUser("Booting Network. Wait until healthy...") + + startResp, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...) + if err != nil { + return fmt.Errorf("failed to start local avalanchego: %w \n %s", err, startResp) + } + + ux.Logger.PrintToUser("Local Avalanchego started. Saving state to %s", rootDir) + + saveSnapshotResp, err := cli.SaveSnapshot( + ctx, + "local-snapshot", + true, ) if err != nil { - return fmt.Errorf("could not configure network: %w", err) + return fmt.Errorf("failed to save avalanche state : %w \n %s", err, saveSnapshotResp) } + ux.Logger.PrintToUser("Node logs directory: %s/node/logs", startResp.ClusterInfo.LogRootDir) + ux.Logger.PrintToUser("") + ux.Logger.PrintToUser("Network ready to use.") + ux.Logger.PrintToUser("") + + if err := localnet.PrintEndpoints(ux.Logger.PrintToUser, ""); err != nil { + return err + } + + return nil +} + +func localStopNode(cmd *cobra.Command, args []string) error { + return nil +} +func localCleanupNode(cmd *cobra.Command, args []string) error { return nil } diff --git a/go.mod b/go.mod index 666da684e..b391561bc 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.22.7 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.3-0.20240815175406-50423422fb5b - github.com/ava-labs/avalanchego v1.11.11-0.20240815211142-ce78e7f1799f + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241001174645-5168904c806a + github.com/ava-labs/avalanchego v1.11.11 github.com/ava-labs/awm-relayer v1.3.0 - github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180 + github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 github.com/ava-labs/subnet-evm v0.6.9-0.20240815191823-9f3608326298 github.com/aws/aws-sdk-go-v2 v1.30.3 github.com/aws/aws-sdk-go-v2/config v1.27.26 diff --git a/go.sum b/go.sum index 6c6254a15..82d30b98a 100644 --- a/go.sum +++ b/go.sum @@ -85,12 +85,20 @@ github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= github.com/ava-labs/avalanche-network-runner v1.8.3-0.20240815175406-50423422fb5b h1:9DEFDbJFdkMxzfjwUm1KbyzqYlhn8QDYrW9pYmFVNdA= github.com/ava-labs/avalanche-network-runner v1.8.3-0.20240815175406-50423422fb5b/go.mod h1:X4ly6Ebq6vzsj9q9G9W00YftOrS7ZT2jLi9cxLqT4eQ= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20240930181211-bfc2f5f85973 h1:rsAfxjQLCs9dyDGqUZK29fGDrW4uzLzYjQLUVMEkvdQ= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20240930181211-bfc2f5f85973/go.mod h1:T6AYu2HBw4N6oAIRJWATSLx3/uWLVVADTbfSCIcSlEY= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241001174645-5168904c806a h1:rTiBqSDCCi8TgfjCwtxX1D90FcS6wEjRnt0/BOS1HjI= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241001174645-5168904c806a/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.11.11-0.20240815211142-ce78e7f1799f h1:fLWva3zOGwhZAnLq+nhiTs1Q24dL1nPvF4qVZZ6IGFg= github.com/ava-labs/avalanchego v1.11.11-0.20240815211142-ce78e7f1799f/go.mod h1:UkyrRDXK2E15Lq2abyae2Pt+JsWvgsg1pe0/AtoMyAM= +github.com/ava-labs/avalanchego v1.11.11 h1:MIQq8xRavRj4ZXHA4G+aMiymig7SOScGOG1SApmMvBc= +github.com/ava-labs/avalanchego v1.11.11/go.mod h1:yFx3V31Jy9NFa8GZlgGnwiVf8KGjeF2+Uc99l9Scd/8= github.com/ava-labs/awm-relayer v1.3.0 h1:aI90Daoq7bs9SnfZpyjXajj7YLcdZoFgEkyCd52fOHE= github.com/ava-labs/awm-relayer v1.3.0/go.mod h1:UI1Tm0jfFIpO1S2hpE5WGzJCDpLHLldhsE1bWn2FjEE= github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180 h1:6aIHp7wbyGVYdhHVQUbG7BEcbCMEQ5SYopPPJyipyvk= github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180/go.mod h1:/wNBVq7J7wlC2Kbov7kk6LV5xZvau7VF9zwTVOeyAjY= +github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 h1:wlhGJbmb7s3bU2QWtxKjscGjfHknQiq+cVhhUjONsB8= +github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732/go.mod h1:RkQLaQ961Xe/sUb3ycn4Qi18vPPuEetTqDf2eDcquAs= github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c= github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g= github.com/ava-labs/subnet-evm v0.6.9-0.20240815191823-9f3608326298 h1:g7JdXUEZ5Hk3sKhJPoZattE4obRaF7qapHREnB4O+Rg= diff --git a/pkg/application/app.go b/pkg/application/app.go index 391484f24..5a694f8b4 100644 --- a/pkg/application/app.go +++ b/pkg/application/app.go @@ -89,6 +89,10 @@ func (app *Avalanche) GetPluginsDir() string { return filepath.Join(app.baseDir, constants.PluginDir) } +func (app *Avalanche) GetLocalDir() string { + return filepath.Join(app.baseDir, constants.LocalDir) +} + // Remove all plugins from plugin dir func (app *Avalanche) ResetPluginsDir() error { pluginDir := app.GetPluginsDir() diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index df572b316..ab287677b 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -340,6 +340,7 @@ const ( BlockchainIDLabel = "BlockchainID: " PluginDir = "plugins" + LocalDir = "local" MetricsNetwork = "network" MultiSig = "multi-sig" diff --git a/pkg/models/network.go b/pkg/models/network.go index e63376e56..a1a4fd94a 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -4,7 +4,6 @@ package models import ( "fmt" - "net/netip" "os" "strings" @@ -72,27 +71,6 @@ func NewNetwork(kind NetworkKind, id uint32, endpoint string, clusterName string } } -func (n Network) Customize(genesisData []byte, upgradeData []byte, bootstrapIDs []ids.NodeID, bootstrapIPs []netip.AddrPort) (CustomNetwork, error) { - if len(bootstrapIPs) != len(bootstrapIDs) { - return CustomNetwork{}, fmt.Errorf("number of bootstrap IDs and bootstrap IP:port pairs must be equal") - } - beaconSet := beacon.NewSet() - for index, ip := range bootstrapIPs { - if err := beaconSet.Add(beacon.New(bootstrapIDs[index], ip)); err != nil { - return CustomNetwork{}, fmt.Errorf("failed to add bootstrap IP:port pair: %w", err) - } - } - return CustomNetwork{ - Network: n, - GenesisData: genesisData, - UpgradeData: upgradeData, - BootstrapConfig: BootstrapConfig{ - NodeIDs: bootstrapIDs, - NodeIPs: beaconSet, - }, - }, nil -} - func (n Network) IsUndefined() bool { return n.Kind == Undefined } diff --git a/pkg/utils/net.go b/pkg/utils/net.go index 471dcbf70..1b62e995b 100644 --- a/pkg/utils/net.go +++ b/pkg/utils/net.go @@ -68,17 +68,17 @@ func StringSliceToNodeIds(s []string) ([]ids.NodeID, error) { if id == "" { continue } - nodeId, err := ids.NodeIDFromString(id) + nodeID, err := ids.NodeIDFromString(id) if err != nil { return nil, err } - nodeIDs = append(nodeIDs, nodeId) + nodeIDs = append(nodeIDs, nodeID) } return nodeIDs, nil } func StringSliceToNetipPorts(s []string) ([]netip.AddrPort, error) { - var nodeIds []netip.AddrPort + nodeIDs := []netip.AddrPort{} for _, id := range s { id = strings.Trim(id, " ") if id == "" { @@ -88,7 +88,7 @@ func StringSliceToNetipPorts(s []string) ([]netip.AddrPort, error) { if err != nil { return nil, err } - nodeIds = append(nodeIds, addrPort) + nodeIDs = append(nodeIDs, addrPort) } - return nodeIds, nil + return nodeIDs, nil } From 3ddc12c77a7bb509f3f9321c6755cfbe99612b84 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Wed, 2 Oct 2024 18:43:55 -0700 Subject: [PATCH 04/57] rm not needed utils --- pkg/utils/net.go | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/pkg/utils/net.go b/pkg/utils/net.go index 1b62e995b..99dad17a2 100644 --- a/pkg/utils/net.go +++ b/pkg/utils/net.go @@ -8,11 +8,7 @@ import ( "io" "net" "net/http" - "net/netip" "net/url" - "strings" - - "github.com/ava-labs/avalanchego/ids" ) // GetUserIPAddress retrieves the IP address of the user. @@ -60,35 +56,3 @@ func IsValidURL(urlString string) bool { } return true } - -func StringSliceToNodeIds(s []string) ([]ids.NodeID, error) { - nodeIDs := []ids.NodeID{} - for _, id := range s { - id = strings.Trim(id, " ") - if id == "" { - continue - } - nodeID, err := ids.NodeIDFromString(id) - if err != nil { - return nil, err - } - nodeIDs = append(nodeIDs, nodeID) - } - return nodeIDs, nil -} - -func StringSliceToNetipPorts(s []string) ([]netip.AddrPort, error) { - nodeIDs := []netip.AddrPort{} - for _, id := range s { - id = strings.Trim(id, " ") - if id == "" { - continue - } - addrPort, err := netip.ParseAddrPort(id) - if err != nil { - return nil, err - } - nodeIDs = append(nodeIDs, addrPort) - } - return nodeIDs, nil -} From 035cb9271e37c30aaeddada555f2ef63857f11b8 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Thu, 3 Oct 2024 13:49:40 -0700 Subject: [PATCH 05/57] ready for draft PR --- cmd/nodecmd/local.go | 127 ++++++++++++++++++++++++++++++++---------- go.mod | 2 +- go.sum | 4 +- pkg/constants/etna.go | 3 +- 4 files changed, 102 insertions(+), 34 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 8d74a09e5..f46c6c095 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -11,13 +11,13 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/binutils" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/constants" - "github.com/ava-labs/avalanche-cli/pkg/localnet" + "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" "github.com/ava-labs/avalanche-cli/pkg/subnet" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanche-network-runner/client" - anrutils "github.com/ava-labs/avalanche-network-runner/utils" + "github.com/ava-labs/avalanche-network-runner/server" "github.com/spf13/cobra" ) @@ -31,6 +31,8 @@ var ( useEtnaDevnet bool ) +const snapshotName = "local_snapshot" + func newLocalCmd() *cobra.Command { cmd := &cobra.Command{ Use: "local", @@ -114,7 +116,7 @@ func preLocalChecks() error { if avalanchegoBinaryPath != "" && (useLatestAvalanchegoReleaseVersion || useLatestAvalanchegoPreReleaseVersion || useCustomAvalanchegoVersion != "") { return fmt.Errorf("specify either --avalanchego-path or --latest-avalanchego-version or --custom-avalanchego-version") } - if useEtnaDevnet && !globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji { + if useEtnaDevnet && (globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji) { return fmt.Errorf("etna devnet can only be used with devnet") } if useEtnaDevnet && genesisPath != "" { @@ -138,19 +140,28 @@ func preLocalChecks() error { return nil } -func localStartNode(cmd *cobra.Command, args []string) error { - network, err := networkoptions.GetNetworkFromCmdLineFlags( - app, - "", - globalNetworkFlags, - false, - true, - createSupportedNetworkOptions, - "", - ) - if err != nil { - return err +func localStartNode(_ *cobra.Command, _ []string) error { + network := models.UndefinedNetwork + networkID := uint32(0) + if useEtnaDevnet { + networkID = constants.EtnaDevnetNetworkID + } else { + var err error + network, err = networkoptions.GetNetworkFromCmdLineFlags( + app, + "", + globalNetworkFlags, + false, + true, + createSupportedNetworkOptions, + "", + ) + if err != nil { + return err + } + networkID = network.ID } + if err := preLocalChecks(); err != nil { return err } @@ -171,7 +182,9 @@ func localStartNode(cmd *cobra.Command, args []string) error { if _, err := genesisFile.Write(constants.EtnaDevnetGenesisData); err != nil { return fmt.Errorf("could not write Etna Devnet genesis data: %w", err) } - genesisFile.Close() + if err := genesisFile.Close(); err != nil { + return fmt.Errorf("could not close Etna Devnet genesis file: %w", err) + } genesisPath = genesisFile.Name() defer os.Remove(genesisPath) @@ -183,13 +196,21 @@ func localStartNode(cmd *cobra.Command, args []string) error { return fmt.Errorf("could not write Etna Devnet upgrade data: %w", err) } upgradePath = upgradeFile.Name() - upgradeFile.Close() + if err := upgradeFile.Close(); err != nil { + return fmt.Errorf("could not close Etna Devnet upgrade file: %w", err) + } defer os.Remove(upgradePath) } if err != nil { return fmt.Errorf("could not configure network: %w", err) } + // cleanup for Devnet + if network.Kind == models.Devnet { + if err := cleanupLocalNode(); err != nil { + return fmt.Errorf("could not make sure root directory is empty: %w", err) + } + } sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") if err := sd.StartServer(); err != nil { @@ -228,19 +249,20 @@ func localStartNode(cmd *cobra.Command, args []string) error { } rootDir := app.GetLocalDir() - //make sure rootDir exists + logDir := filepath.Join(rootDir, "logs") + // make sure rootDir exists if err := os.MkdirAll(rootDir, 0o700); err != nil { return fmt.Errorf("could not create root directory %s: %w", rootDir, err) } - ux.Logger.PrintToUser("Starting local avalanchego node using root: %s ...", rootDir) - logDir, err := anrutils.MkDirWithTimestamp(filepath.Join(app.GetRunDir(), "network")) - if err != nil { - return err + if err := os.MkdirAll(logDir, 0o700); err != nil { + return fmt.Errorf("could not create log directory %s: %w", logDir, err) } + + ux.Logger.PrintToUser("Starting local avalanchego node using root: %s ...", rootDir) pluginDir := app.GetPluginsDir() anrOpts := []client.OpOption{ client.WithNumNodes(1), - client.WithNetworkID(network.ID), + client.WithNetworkID(networkID), client.WithExecPath(avalancheGoBinPath), client.WithRootDataDir(rootDir), client.WithLogRootDir(logDir), @@ -279,28 +301,73 @@ func localStartNode(cmd *cobra.Command, args []string) error { saveSnapshotResp, err := cli.SaveSnapshot( ctx, - "local-snapshot", - true, + snapshotName, + true, // force ) if err != nil { return fmt.Errorf("failed to save avalanche state : %w \n %s", err, saveSnapshotResp) } - ux.Logger.PrintToUser("Node logs directory: %s/node/logs", startResp.ClusterInfo.LogRootDir) + // start it again by loading the saved state + ux.Logger.PrintToUser("Continue booting avalanchego using %s", rootDir) + // ready to load saved state and continue booting + loadSnapshotResp, err := cli.LoadSnapshot( + ctx, + snapshotName, + false, // in-place + anrOpts..., + ) + if err != nil { + return fmt.Errorf("failed to continue booting avalanchego : %w \n %s", err, loadSnapshotResp) + } + ux.Logger.GreenCheckmarkToUser("Avalanchego started and ready to use from %s", rootDir) + ux.Logger.PrintToUser("") + ux.Logger.PrintToUser("Node logs directory: %s/node1/logs", startResp.ClusterInfo.LogRootDir) ux.Logger.PrintToUser("") ux.Logger.PrintToUser("Network ready to use.") ux.Logger.PrintToUser("") - if err := localnet.PrintEndpoints(ux.Logger.PrintToUser, ""); err != nil { + return nil +} + +func localStopNode(_ *cobra.Command, _ []string) error { + cli, err := binutils.NewGRPCClient( + binutils.WithAvoidRPCVersionCheck(true), + binutils.WithDialTimeout(constants.FastGRPCDialTimeout), + ) + if err != nil { return err } + ctx, cancel := utils.GetANRContext() + defer cancel() + + if _, err := cli.Status(ctx); err != nil { + if server.IsServerError(err, server.ErrNotBootstrapped) { + ux.Logger.PrintToUser("avalanchego already stopped.") + return nil + } + return fmt.Errorf("failed to get avalanchego status: %w", err) + } + if _, err = cli.SaveSnapshot(ctx, snapshotName, true); err != nil { + return fmt.Errorf("failed to save avalanchego state: %w", err) + } + + if _, err = cli.Stop(ctx); err != nil { + return fmt.Errorf("failed to stop avalanchego: %w", err) + } + return nil } -func localStopNode(cmd *cobra.Command, args []string) error { +func localCleanupNode(_ *cobra.Command, _ []string) error { + if err := cleanupLocalNode(); err != nil { + return fmt.Errorf("failed to cleanup local node: %w", err) + } + ux.Logger.PrintToUser("Local node cleaned up.") return nil } -func localCleanupNode(cmd *cobra.Command, args []string) error { - return nil +func cleanupLocalNode() error { + rootDir := app.GetLocalDir() + return os.RemoveAll(rootDir) } diff --git a/go.mod b/go.mod index c598df96e..50cf8f044 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.7 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241001174645-5168904c806a + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a github.com/ava-labs/avalanchego v1.11.11 github.com/ava-labs/awm-relayer v1.4.1-0.20240910171125-3c2ae781fb32 github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 diff --git a/go.sum b/go.sum index b0a4b22eb..714c00bde 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241001174645-5168904c806a h1:rTiBqSDCCi8TgfjCwtxX1D90FcS6wEjRnt0/BOS1HjI= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241001174645-5168904c806a/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a h1:xd2RUTW9w34+V6yI7zWfByHZ8y5CeXhvHK+nAJ9FCbI= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.11.11 h1:MIQq8xRavRj4ZXHA4G+aMiymig7SOScGOG1SApmMvBc= github.com/ava-labs/avalanchego v1.11.11/go.mod h1:yFx3V31Jy9NFa8GZlgGnwiVf8KGjeF2+Uc99l9Scd/8= github.com/ava-labs/awm-relayer v1.4.1-0.20240910171125-3c2ae781fb32 h1:KcrFCyWU6A+GJ/E2fZSI6qGjU3M2NPl7QrzJ5fH3t2Q= diff --git a/pkg/constants/etna.go b/pkg/constants/etna.go index 8c6a3f7a9..359454843 100644 --- a/pkg/constants/etna.go +++ b/pkg/constants/etna.go @@ -13,7 +13,8 @@ var EtnaDevnetGenesisData []byte var EtnaDevnetUpgradeData []byte const ( - EtnaDevnetEndpoint = "https://etna.avax-dev.network" + EtnaDevnetEndpoint = "https://etna.avax-dev.network" + EtnaDevnetNetworkID = uint32(76) ) var ( From 3b1e6766b585a36eba48e6023ba4ac3e978795f6 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Thu, 3 Oct 2024 14:07:34 -0700 Subject: [PATCH 06/57] nits rm unused struct --- cmd/nodecmd/local.go | 14 +++++++++----- pkg/models/network.go | 14 -------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index f46c6c095..4f62b9572 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -141,12 +141,12 @@ func preLocalChecks() error { } func localStartNode(_ *cobra.Command, _ []string) error { + var err error network := models.UndefinedNetwork networkID := uint32(0) if useEtnaDevnet { networkID = constants.EtnaDevnetNetworkID } else { - var err error network, err = networkoptions.GetNetworkFromCmdLineFlags( app, "", @@ -165,11 +165,15 @@ func localStartNode(_ *cobra.Command, _ []string) error { if err := preLocalChecks(); err != nil { return err } - avalancheGoVersion, err := getAvalancheGoVersion() - if err != nil { - return err + avalancheGoVersion := "latest" + if avalanchegoBinaryPath == "" { + avalancheGoVersion, err = getAvalancheGoVersion() + if err != nil { + return err + } else { + ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) + } } - ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) if useEtnaDevnet { bootstrapIDs = constants.EtnaDevnetBootstrapNodeIDs diff --git a/pkg/models/network.go b/pkg/models/network.go index a1a4fd94a..97eda5526 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -9,8 +9,6 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanchego/genesis" - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/beacon" avagoconstants "github.com/ava-labs/avalanchego/utils/constants" ) @@ -48,18 +46,6 @@ type Network struct { ClusterName string } -type BootstrapConfig struct { - NodeIDs []ids.NodeID - NodeIPs beacon.Set -} - -type CustomNetwork struct { - Network - BootstrapConfig BootstrapConfig - GenesisData []byte - UpgradeData []byte -} - var UndefinedNetwork = Network{} func NewNetwork(kind NetworkKind, id uint32, endpoint string, clusterName string) Network { From 495d59ce41500189cdca894d06f1afa8fd3b03c5 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Fri, 4 Oct 2024 14:35:10 -0700 Subject: [PATCH 07/57] refactor - wip --- cmd/nodecmd/local.go | 32 ++++++++++++++++++++++++-------- pkg/application/app.go | 4 ++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 4f62b9572..0ed323623 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -53,7 +53,7 @@ The node local command suite provides a collection of commands related to local func newLocalStartCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "start", + Use: "start [clusterName]", Short: "(ALPHA Warning) Create a new validator on local machine", Long: `(ALPHA Warning) This command is currently in experimental mode. @@ -66,6 +66,7 @@ to finish bootstrapping on the primary network before running further commands on it, e.g. validating a Subnet. You can check the bootstrapping status by running avalanche node status local `, + Args: cobra.ExactArgs(1), RunE: localStartNode, PersistentPostRun: handlePostRun, } @@ -84,18 +85,20 @@ status by running avalanche node status local func newLocalStopCmd() *cobra.Command { return &cobra.Command{ - Use: "stop", + Use: "stop [clusterName]", Short: "(ALPHA Warning) Stop local node", Long: `Stop local node.`, + Args: cobra.ExactArgs(1), RunE: localStopNode, } } func newLocalCleanupCmd() *cobra.Command { return &cobra.Command{ - Use: "cleanup", + Use: "destroy [clusterName]", Short: "(ALPHA Warning) Cleanup local node", Long: `Cleanup local node.`, + Args: cobra.ExactArgs(1), RunE: localCleanupNode, } } @@ -140,8 +143,13 @@ func preLocalChecks() error { return nil } -func localStartNode(_ *cobra.Command, _ []string) error { +func localStartNode(_ *cobra.Command, args []string) error { var err error + + clusterName := args[0] + if err := checkCluster(clusterName); err != nil { + return err + } network := models.UndefinedNetwork networkID := uint32(0) if useEtnaDevnet { @@ -333,7 +341,11 @@ func localStartNode(_ *cobra.Command, _ []string) error { return nil } -func localStopNode(_ *cobra.Command, _ []string) error { +func localStopNode(_ *cobra.Command, args []string) error { + clusterName := args[0] + if err := checkCluster(clusterName); err != nil { + return err + } cli, err := binutils.NewGRPCClient( binutils.WithAvoidRPCVersionCheck(true), binutils.WithDialTimeout(constants.FastGRPCDialTimeout), @@ -363,15 +375,19 @@ func localStopNode(_ *cobra.Command, _ []string) error { return nil } -func localCleanupNode(_ *cobra.Command, _ []string) error { - if err := cleanupLocalNode(); err != nil { +func localDestroyNode(_ *cobra.Command, args []string) error { + clusterName := args[0] + if err := checkCluster(clusterName); err != nil { + return err + } + if err := cleanupLocalNode(clusterName); err != nil { return fmt.Errorf("failed to cleanup local node: %w", err) } ux.Logger.PrintToUser("Local node cleaned up.") return nil } -func cleanupLocalNode() error { +func cleanupLocalNode(clusterName string) error { rootDir := app.GetLocalDir() return os.RemoveAll(rootDir) } diff --git a/pkg/application/app.go b/pkg/application/app.go index e7a5030ad..43d869da5 100644 --- a/pkg/application/app.go +++ b/pkg/application/app.go @@ -89,8 +89,8 @@ func (app *Avalanche) GetPluginsDir() string { return filepath.Join(app.baseDir, constants.PluginDir) } -func (app *Avalanche) GetLocalDir() string { - return filepath.Join(app.baseDir, constants.LocalDir) +func (app *Avalanche) GetLocalDir(clusterName string) string { + return filepath.Join(app.baseDir, constants.LocalDir, clusterName) } // Remove all plugins from plugin dir From 1d52dd5ce7fbf599f488cd583a80684009ada88f Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Fri, 4 Oct 2024 17:03:56 -0700 Subject: [PATCH 08/57] make sure we can resume without prompts --- cmd/nodecmd/local.go | 327 +++++++++++++++++++++---------------------- 1 file changed, 156 insertions(+), 171 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 0ed323623..e5ec9a050 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -7,7 +7,6 @@ import ( "os" "path/filepath" - "github.com/ava-labs/avalanche-cli/cmd/networkcmd" "github.com/ava-labs/avalanche-cli/pkg/binutils" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/constants" @@ -31,8 +30,7 @@ var ( useEtnaDevnet bool ) -const snapshotName = "local_snapshot" - +// const snapshotName = "local_snapshot" func newLocalCmd() *cobra.Command { cmd := &cobra.Command{ Use: "local", @@ -46,8 +44,8 @@ The node local command suite provides a collection of commands related to local cmd.AddCommand(newLocalStartCmd()) // node local stop cmd.AddCommand(newLocalStopCmd()) - // node local cleanup - cmd.AddCommand(newLocalCleanupCmd()) + // node local destroy + cmd.AddCommand(newLocalDestroyCmd()) return cmd } @@ -93,18 +91,25 @@ func newLocalStopCmd() *cobra.Command { } } -func newLocalCleanupCmd() *cobra.Command { +func newLocalDestroyCmd() *cobra.Command { return &cobra.Command{ Use: "destroy [clusterName]", Short: "(ALPHA Warning) Cleanup local node", Long: `Cleanup local node.`, Args: cobra.ExactArgs(1), - RunE: localCleanupNode, + RunE: localDestroyNode, } } // stub for now -func preLocalChecks() error { +func preLocalChecks(clusterName string) error { + clusterExists, err := checkClusterExists(clusterName) + if err != nil { + return fmt.Errorf("error checking cluster: %w", err) + } + if clusterExists { + return fmt.Errorf("cluster %q already exists", clusterName) + } // expand passed paths if genesisPath != "" { genesisPath = utils.ExpandHome(genesisPath) @@ -143,197 +148,184 @@ func preLocalChecks() error { return nil } +func localClusterDataExists(clusterName string) bool { + return utils.FileExists(filepath.Join(app.GetLocalDir(clusterName), "state.json")) +} + +func localClusterSnapshotName(clusterName string) string { + return fmt.Sprintf("local-snapshot-%s", clusterName) +} + func localStartNode(_ *cobra.Command, args []string) error { var err error - clusterName := args[0] - if err := checkCluster(clusterName); err != nil { - return err - } network := models.UndefinedNetwork networkID := uint32(0) - if useEtnaDevnet { - networkID = constants.EtnaDevnetNetworkID + + // check if this is existing cluster + rootDir := app.GetLocalDir(clusterName) + logDir := filepath.Join(rootDir, "logs") + pluginDir := app.GetPluginsDir() + + cli, err := binutils.NewGRPCClient() + if err != nil { + return err + } + + ctx, cancel := utils.GetANRContext() + defer cancel() + + if localClusterDataExists(clusterName) { + ux.Logger.GreenCheckmarkToUser("Local cluster %s found. Booting up...", clusterName) } else { - network, err = networkoptions.GetNetworkFromCmdLineFlags( - app, - "", - globalNetworkFlags, - false, - true, - createSupportedNetworkOptions, - "", - ) - if err != nil { + ux.Logger.GreenCheckmarkToUser("Local cluster %s not found. Creating...", clusterName) + if useEtnaDevnet { + networkID = constants.EtnaDevnetNetworkID + } else { + network, err = networkoptions.GetNetworkFromCmdLineFlags( + app, + "", + globalNetworkFlags, + false, + true, + createSupportedNetworkOptions, + "", + ) + if err != nil { + return err + } + networkID = network.ID + } + avalancheGoVersion := "latest" + if avalanchegoBinaryPath == "" { + avalancheGoVersion, err = getAvalancheGoVersion() + if err != nil { + return err + } else { + ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) + } + } + if err := preLocalChecks(clusterName); err != nil { return err } - networkID = network.ID - } + if useEtnaDevnet { + bootstrapIDs = constants.EtnaDevnetBootstrapNodeIDs + bootstrapIPs = constants.EtnaDevnetBootstrapIPs + // prepare genesis and upgrade files for anr + genesisFile, err := os.CreateTemp("", "etna_devnet_genesis") + if err != nil { + return fmt.Errorf("could not create save Etna Devnet genesis file: %w", err) + } + if _, err := genesisFile.Write(constants.EtnaDevnetGenesisData); err != nil { + return fmt.Errorf("could not write Etna Devnet genesis data: %w", err) + } + if err := genesisFile.Close(); err != nil { + return fmt.Errorf("could not close Etna Devnet genesis file: %w", err) + } + genesisPath = genesisFile.Name() + defer os.Remove(genesisPath) + + upgradeFile, err := os.CreateTemp("", "etna_devnet_upgrade") + if err != nil { + return fmt.Errorf("could not create save Etna Devnet upgrade file: %w", err) + } + if _, err := upgradeFile.Write(constants.EtnaDevnetUpgradeData); err != nil { + return fmt.Errorf("could not write Etna Devnet upgrade data: %w", err) + } + upgradePath = upgradeFile.Name() + if err := upgradeFile.Close(); err != nil { + return fmt.Errorf("could not close Etna Devnet upgrade file: %w", err) + } + defer os.Remove(upgradePath) + } - if err := preLocalChecks(); err != nil { - return err - } - avalancheGoVersion := "latest" - if avalanchegoBinaryPath == "" { - avalancheGoVersion, err = getAvalancheGoVersion() - if err != nil { + sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") + + if err := sd.StartServer(); err != nil { return err - } else { - ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) } - } - if useEtnaDevnet { - bootstrapIDs = constants.EtnaDevnetBootstrapNodeIDs - bootstrapIPs = constants.EtnaDevnetBootstrapIPs - // prepare genesis and upgrade files for anr - genesisFile, err := os.CreateTemp("", "etna_devnet_genesis") + _, avalancheGoBinPath, err := sd.SetupLocalEnv() if err != nil { - return fmt.Errorf("could not create save Etna Devnet genesis file: %w", err) + return err } - if _, err := genesisFile.Write(constants.EtnaDevnetGenesisData); err != nil { - return fmt.Errorf("could not write Etna Devnet genesis data: %w", err) + + // make sure rootDir exists + if err := os.MkdirAll(rootDir, 0o700); err != nil { + return fmt.Errorf("could not create root directory %s: %w", rootDir, err) } - if err := genesisFile.Close(); err != nil { - return fmt.Errorf("could not close Etna Devnet genesis file: %w", err) + if err := os.MkdirAll(logDir, 0o700); err != nil { + return fmt.Errorf("could not create log directory %s: %w", logDir, err) } - genesisPath = genesisFile.Name() - defer os.Remove(genesisPath) - upgradeFile, err := os.CreateTemp("", "etna_devnet_upgrade") + ux.Logger.PrintToUser("Starting local avalanchego node using root: %s ...", rootDir) + + anrOpts := []client.OpOption{ + client.WithNumNodes(1), + client.WithNetworkID(networkID), + client.WithExecPath(avalancheGoBinPath), + client.WithRootDataDir(rootDir), + client.WithLogRootDir(logDir), + client.WithReassignPortsIfUsed(true), + client.WithPluginDir(pluginDir), + } + // load global node configs if they exist + configStr, err := app.Conf.LoadNodeConfig() if err != nil { - return fmt.Errorf("could not create save Etna Devnet upgrade file: %w", err) + return err } - if _, err := upgradeFile.Write(constants.EtnaDevnetUpgradeData); err != nil { - return fmt.Errorf("could not write Etna Devnet upgrade data: %w", err) + if configStr != "" { + anrOpts = append(anrOpts, client.WithGlobalNodeConfig(configStr)) } - upgradePath = upgradeFile.Name() - if err := upgradeFile.Close(); err != nil { - return fmt.Errorf("could not close Etna Devnet upgrade file: %w", err) + if genesisPath != "" && utils.FileExists(genesisPath) { + anrOpts = append(anrOpts, client.WithGenesisPath(genesisPath)) } - defer os.Remove(upgradePath) - } - if err != nil { - return fmt.Errorf("could not configure network: %w", err) - } - - // cleanup for Devnet - if network.Kind == models.Devnet { - if err := cleanupLocalNode(); err != nil { - return fmt.Errorf("could not make sure root directory is empty: %w", err) + if upgradePath != "" && utils.FileExists(upgradePath) { + anrOpts = append(anrOpts, client.WithUpgradePath(upgradePath)) + } + if bootstrapIDs != nil { + anrOpts = append(anrOpts, client.WithBootstrapNodeIDs(bootstrapIDs)) + } + if bootstrapIPs != nil { + anrOpts = append(anrOpts, client.WithBootstrapNodeIPPortPairs(bootstrapIPs)) } - } - sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") - - if err := sd.StartServer(); err != nil { - return err - } - - needsRestart, avalancheGoBinPath, err := sd.SetupLocalEnv() - if err != nil { - return err - } - - cli, err := binutils.NewGRPCClient() - if err != nil { - return err - } - - ctx, cancel := utils.GetANRContext() - defer cancel() - bootstrapped, err := networkcmd.CheckNetworkIsAlreadyBootstrapped(ctx, cli) - if err != nil { - return err - } + ux.Logger.PrintToUser("Booting Network. Wait until healthy...") - if bootstrapped { - if !needsRestart { - ux.Logger.PrintToUser("Network has already been booted.") - return nil - } - if _, err := cli.Stop(ctx); err != nil { - return err + startResp, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...) + if err != nil { + return fmt.Errorf("failed to start local avalanchego: %w \n %s", err, startResp) } - if err := app.ResetPluginsDir(); err != nil { - return err + // save snapshot after successful start + saveSnapshotResponse, err := cli.SaveSnapshot( + ctx, + localClusterSnapshotName(clusterName), + true, // force + ) + if err != nil { + return fmt.Errorf("failed to save snapshot: %w \n %s", err, saveSnapshotResponse) } } - rootDir := app.GetLocalDir() - logDir := filepath.Join(rootDir, "logs") - // make sure rootDir exists - if err := os.MkdirAll(rootDir, 0o700); err != nil { - return fmt.Errorf("could not create root directory %s: %w", rootDir, err) - } - if err := os.MkdirAll(logDir, 0o700); err != nil { - return fmt.Errorf("could not create log directory %s: %w", logDir, err) - } - - ux.Logger.PrintToUser("Starting local avalanchego node using root: %s ...", rootDir) - pluginDir := app.GetPluginsDir() - anrOpts := []client.OpOption{ - client.WithNumNodes(1), - client.WithNetworkID(networkID), - client.WithExecPath(avalancheGoBinPath), + loadSnapshotOpts := []client.OpOption{ client.WithRootDataDir(rootDir), client.WithLogRootDir(logDir), client.WithReassignPortsIfUsed(true), client.WithPluginDir(pluginDir), } - // load global node configs if they exist - configStr, err := app.Conf.LoadNodeConfig() - if err != nil { - return err - } - if configStr != "" { - anrOpts = append(anrOpts, client.WithGlobalNodeConfig(configStr)) - } - if genesisPath != "" && utils.FileExists(genesisPath) { - anrOpts = append(anrOpts, client.WithGenesisPath(genesisPath)) - } - if upgradePath != "" && utils.FileExists(upgradePath) { - anrOpts = append(anrOpts, client.WithUpgradePath(upgradePath)) - } - if bootstrapIDs != nil { - anrOpts = append(anrOpts, client.WithBootstrapNodeIDs(bootstrapIDs)) - } - if bootstrapIPs != nil { - anrOpts = append(anrOpts, client.WithBootstrapNodeIPPortPairs(bootstrapIPs)) - } - - ux.Logger.PrintToUser("Booting Network. Wait until healthy...") - - startResp, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...) - if err != nil { - return fmt.Errorf("failed to start local avalanchego: %w \n %s", err, startResp) - } - - ux.Logger.PrintToUser("Local Avalanchego started. Saving state to %s", rootDir) - - saveSnapshotResp, err := cli.SaveSnapshot( - ctx, - snapshotName, - true, // force - ) - if err != nil { - return fmt.Errorf("failed to save avalanche state : %w \n %s", err, saveSnapshotResp) - } - // start it again by loading the saved state - ux.Logger.PrintToUser("Continue booting avalanchego using %s", rootDir) - // ready to load saved state and continue booting - loadSnapshotResp, err := cli.LoadSnapshot( + // load snapshot for existing network + loadSnapshotResponse, err := cli.LoadSnapshot( ctx, - snapshotName, + localClusterSnapshotName(clusterName), false, // in-place - anrOpts..., - ) + loadSnapshotOpts...) if err != nil { - return fmt.Errorf("failed to continue booting avalanchego : %w \n %s", err, loadSnapshotResp) + return fmt.Errorf("failed to load snapshot: %w \n %s", err, loadSnapshotResponse) } + ux.Logger.GreenCheckmarkToUser("Avalanchego started and ready to use from %s", rootDir) ux.Logger.PrintToUser("") - ux.Logger.PrintToUser("Node logs directory: %s/node1/logs", startResp.ClusterInfo.LogRootDir) + ux.Logger.PrintToUser("Node logs directory: %s/node1/logs", logDir) ux.Logger.PrintToUser("") ux.Logger.PrintToUser("Network ready to use.") ux.Logger.PrintToUser("") @@ -341,11 +333,7 @@ func localStartNode(_ *cobra.Command, args []string) error { return nil } -func localStopNode(_ *cobra.Command, args []string) error { - clusterName := args[0] - if err := checkCluster(clusterName); err != nil { - return err - } +func localStopNode(_ *cobra.Command, _ []string) error { cli, err := binutils.NewGRPCClient( binutils.WithAvoidRPCVersionCheck(true), binutils.WithDialTimeout(constants.FastGRPCDialTimeout), @@ -364,10 +352,6 @@ func localStopNode(_ *cobra.Command, args []string) error { } return fmt.Errorf("failed to get avalanchego status: %w", err) } - if _, err = cli.SaveSnapshot(ctx, snapshotName, true); err != nil { - return fmt.Errorf("failed to save avalanchego state: %w", err) - } - if _, err = cli.Stop(ctx); err != nil { return fmt.Errorf("failed to stop avalanchego: %w", err) } @@ -377,9 +361,10 @@ func localStopNode(_ *cobra.Command, args []string) error { func localDestroyNode(_ *cobra.Command, args []string) error { clusterName := args[0] - if err := checkCluster(clusterName); err != nil { + /*if err := checkCluster(clusterName); err != nil { return err } + */ if err := cleanupLocalNode(clusterName); err != nil { return fmt.Errorf("failed to cleanup local node: %w", err) } @@ -388,6 +373,6 @@ func localDestroyNode(_ *cobra.Command, args []string) error { } func cleanupLocalNode(clusterName string) error { - rootDir := app.GetLocalDir() + rootDir := app.GetLocalDir(clusterName) return os.RemoveAll(rootDir) } From 1c1d061a59ba38ee69e93f6fa79e4df75ce45679 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Fri, 4 Oct 2024 17:36:47 -0700 Subject: [PATCH 09/57] add custom network and local cluster --- cmd/nodecmd/local.go | 82 +++++++++++++++++++++++++++-------- pkg/models/clusters_config.go | 1 + 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index e5ec9a050..3fba5de49 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -160,7 +160,6 @@ func localStartNode(_ *cobra.Command, args []string) error { var err error clusterName := args[0] network := models.UndefinedNetwork - networkID := uint32(0) // check if this is existing cluster rootDir := app.GetLocalDir(clusterName) @@ -180,7 +179,12 @@ func localStartNode(_ *cobra.Command, args []string) error { } else { ux.Logger.GreenCheckmarkToUser("Local cluster %s not found. Creating...", clusterName) if useEtnaDevnet { - networkID = constants.EtnaDevnetNetworkID + network = models.NewNetwork( + models.Custom, + constants.EtnaDevnetNetworkID, + constants.EtnaDevnetEndpoint, + clusterName, + ) } else { network, err = networkoptions.GetNetworkFromCmdLineFlags( app, @@ -194,7 +198,6 @@ func localStartNode(_ *cobra.Command, args []string) error { if err != nil { return err } - networkID = network.ID } avalancheGoVersion := "latest" if avalanchegoBinaryPath == "" { @@ -262,7 +265,7 @@ func localStartNode(_ *cobra.Command, args []string) error { anrOpts := []client.OpOption{ client.WithNumNodes(1), - client.WithNetworkID(networkID), + client.WithNetworkID(network.ID), client.WithExecPath(avalancheGoBinPath), client.WithRootDataDir(rootDir), client.WithLogRootDir(logDir), @@ -292,18 +295,20 @@ func localStartNode(_ *cobra.Command, args []string) error { ux.Logger.PrintToUser("Booting Network. Wait until healthy...") - startResp, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...) - if err != nil { - return fmt.Errorf("failed to start local avalanchego: %w \n %s", err, startResp) + if _, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...); err != nil { + return fmt.Errorf("failed to start local avalanchego: %w", err) } // save snapshot after successful start - saveSnapshotResponse, err := cli.SaveSnapshot( + if _, err := cli.SaveSnapshot( ctx, localClusterSnapshotName(clusterName), true, // force - ) - if err != nil { - return fmt.Errorf("failed to save snapshot: %w \n %s", err, saveSnapshotResponse) + ); err != nil { + return fmt.Errorf("failed to save local avalanchego state: %w", err) + } + // save cluster config for the new local cluster + if err := addLocalClusterConfig(network); err != nil { + return err } } @@ -314,13 +319,12 @@ func localStartNode(_ *cobra.Command, args []string) error { client.WithPluginDir(pluginDir), } // load snapshot for existing network - loadSnapshotResponse, err := cli.LoadSnapshot( + if _, err := cli.LoadSnapshot( ctx, localClusterSnapshotName(clusterName), false, // in-place - loadSnapshotOpts...) - if err != nil { - return fmt.Errorf("failed to load snapshot: %w \n %s", err, loadSnapshotResponse) + loadSnapshotOpts...); err != nil { + return fmt.Errorf("failed to load snapshot: %w", err) } ux.Logger.GreenCheckmarkToUser("Avalanchego started and ready to use from %s", rootDir) @@ -333,7 +337,11 @@ func localStartNode(_ *cobra.Command, args []string) error { return nil } -func localStopNode(_ *cobra.Command, _ []string) error { +func localStopNode(_ *cobra.Command, args []string) error { + clusterName := args[0] + if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { + return fmt.Errorf("failed to check if cluster %q is local: %w", clusterName, err) + } cli, err := binutils.NewGRPCClient( binutils.WithAvoidRPCVersionCheck(true), binutils.WithDialTimeout(constants.FastGRPCDialTimeout), @@ -352,6 +360,16 @@ func localStopNode(_ *cobra.Command, _ []string) error { } return fmt.Errorf("failed to get avalanchego status: %w", err) } + // save snapshot before stopping + if _, err := cli.SaveSnapshot( + ctx, + localClusterSnapshotName(clusterName), + true, // force + + ); err != nil { + return fmt.Errorf("failed to save state: %w", err) + } + if _, err = cli.Stop(ctx); err != nil { return fmt.Errorf("failed to stop avalanchego: %w", err) } @@ -361,10 +379,10 @@ func localStopNode(_ *cobra.Command, _ []string) error { func localDestroyNode(_ *cobra.Command, args []string) error { clusterName := args[0] - /*if err := checkCluster(clusterName); err != nil { - return err + if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { + return fmt.Errorf("failed to check if cluster %q is local: %w", clusterName, err) } - */ + if err := cleanupLocalNode(clusterName); err != nil { return fmt.Errorf("failed to cleanup local node: %w", err) } @@ -376,3 +394,29 @@ func cleanupLocalNode(clusterName string) error { rootDir := app.GetLocalDir(clusterName) return os.RemoveAll(rootDir) } + +func addLocalClusterConfig(network models.Network) error { + clusterName := network.ClusterName + clustersConfig, err := app.LoadClustersConfig() + if err != nil { + return err + } + clusterConfig := clustersConfig.Clusters[clusterName] + clusterConfig.Local = true + clusterConfig.Network = network + clustersConfig.Clusters[clusterName] = clusterConfig + return app.WriteClustersConfigFile(&clustersConfig) +} + +func checkClusterIsLocal(clusterName string) (bool, error) { + clustersConfig := models.ClustersConfig{} + if app.ClustersConfigExists() { + var err error + clustersConfig, err = app.LoadClustersConfig() + if err != nil { + return false, err + } + } + clusterConf, ok := clustersConfig.Clusters[clusterName] + return ok && clusterConf.Local, nil +} diff --git a/pkg/models/clusters_config.go b/pkg/models/clusters_config.go index cec654905..a789d4771 100644 --- a/pkg/models/clusters_config.go +++ b/pkg/models/clusters_config.go @@ -28,6 +28,7 @@ type ClusterConfig struct { ExtraNetworkData ExtraNetworkData Subnets []string External bool + Local bool HTTPAccess constants.HTTPAccess } From ac37dce604802f9aeb40f980cfa5948e240cb1aa Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Fri, 4 Oct 2024 17:39:08 -0700 Subject: [PATCH 10/57] devnet instead of custom network, rm custom --- cmd/nodecmd/local.go | 2 +- pkg/models/network.go | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 3fba5de49..e57cc26e7 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -180,7 +180,7 @@ func localStartNode(_ *cobra.Command, args []string) error { ux.Logger.GreenCheckmarkToUser("Local cluster %s not found. Creating...", clusterName) if useEtnaDevnet { network = models.NewNetwork( - models.Custom, + models.Devnet, constants.EtnaDevnetNetworkID, constants.EtnaDevnetEndpoint, clusterName, diff --git a/pkg/models/network.go b/pkg/models/network.go index 97eda5526..1d2539544 100644 --- a/pkg/models/network.go +++ b/pkg/models/network.go @@ -20,7 +20,6 @@ const ( Fuji Local Devnet - Custom ) func (nk NetworkKind) String() string { @@ -33,8 +32,6 @@ func (nk NetworkKind) String() string { return "Local Network" case Devnet: return "Devnet" - case Custom: - return "Custom Network" } return "invalid network" } From 64ba256a7c53f0ed0208e31e3fe7d1cca9d4a615 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 8 Oct 2024 13:49:22 -0700 Subject: [PATCH 11/57] go mod tidy --- go.mod | 7 ------- go.sum | 4 ---- 2 files changed, 11 deletions(-) diff --git a/go.mod b/go.mod index a0458ca89..f07dfa284 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,6 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a - github.com/ava-labs/avalanchego v1.11.11 - github.com/ava-labs/awm-relayer v1.4.1-0.20240910171125-3c2ae781fb32 - github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 - github.com/ava-labs/subnet-evm v0.6.9 - github.com/aws/aws-sdk-go-v2 v1.30.5 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344 github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f @@ -121,7 +115,6 @@ require ( github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect github.com/getsentry/sentry-go v0.18.0 // indirect github.com/gliderlabs/ssh v0.3.7 // indirect - github.com/go-cmd/cmd v1.4.1 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect github.com/go-logr/logr v1.4.2 // indirect diff --git a/go.sum b/go.sum index f7f98a76c..8124f430c 100644 --- a/go.sum +++ b/go.sum @@ -332,8 +332,6 @@ github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7 github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= -github.com/go-cmd/cmd v1.4.1 h1:JUcEIE84v8DSy02XTZpUDeGKExk2oW3DA10hTjbQwmc= -github.com/go-cmd/cmd v1.4.1/go.mod h1:tbBenttXtZU4c5djS1o7PWL5pd2xAr5sIqH1kGdNiRc= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= @@ -368,8 +366,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= -github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= -github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= From 71e313bf62740802717a98982a08c8d3aa67f11b Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Tue, 8 Oct 2024 15:09:17 -0700 Subject: [PATCH 12/57] upgrade.json for etna devnet --- pkg/constants/etnaDevnet/upgrade.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/constants/etnaDevnet/upgrade.json b/pkg/constants/etnaDevnet/upgrade.json index 914b8ba83..33cd0a5c9 100644 --- a/pkg/constants/etnaDevnet/upgrade.json +++ b/pkg/constants/etnaDevnet/upgrade.json @@ -12,5 +12,5 @@ "cortinaTime": "2020-12-05T05:00:00Z", "cortinaXChainStopVertexID": "11111111111111111111111111111111LpoYY", "durangoTime": "2020-12-05T05:00:00Z", - "etnaTime": "9999-12-01T00:00:00Z" + "etnaTime": "2024-10-09T20:00:00Z" } From 884043eb3bba041bd2b746175b1f1c065cb837da Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Wed, 9 Oct 2024 11:08:07 -0700 Subject: [PATCH 13/57] more local cluster --- cmd/nodecmd/destroy.go | 3 +++ cmd/nodecmd/list.go | 2 ++ cmd/nodecmd/local.go | 34 ++++++++++++++++++---------------- go.mod | 2 +- go.sum | 4 ++-- pkg/models/clusters_config.go | 7 +++++-- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/cmd/nodecmd/destroy.go b/cmd/nodecmd/destroy.go index 9153dc0f3..f62f11fa3 100644 --- a/cmd/nodecmd/destroy.go +++ b/cmd/nodecmd/destroy.go @@ -355,6 +355,9 @@ func getClusterNodes(clusterName string) ([]string, error) { 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) diff --git a/cmd/nodecmd/list.go b/cmd/nodecmd/list.go index 16588681d..130f70edf 100644 --- a/cmd/nodecmd/list.go +++ b/cmd/nodecmd/list.go @@ -61,6 +61,8 @@ func list(_ *cobra.Command, _ []string) error { } if clusterConf.External { ux.Logger.PrintToUser("cluster %q (%s) EXTERNAL", clusterName, clusterConf.Network.Kind.String()) + } else if clusterConf.Local { + ux.Logger.PrintToUser("cluster %q (%s) LOCAL", clusterName, clusterConf.Network.Kind.String()) } else { ux.Logger.PrintToUser("Cluster %q (%s)", clusterName, clusterConf.Network.Kind.String()) } diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index e57cc26e7..75213fc44 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -165,15 +165,8 @@ func localStartNode(_ *cobra.Command, args []string) error { rootDir := app.GetLocalDir(clusterName) logDir := filepath.Join(rootDir, "logs") pluginDir := app.GetPluginsDir() - - cli, err := binutils.NewGRPCClient() - if err != nil { - return err - } - ctx, cancel := utils.GetANRContext() defer cancel() - if localClusterDataExists(clusterName) { ux.Logger.GreenCheckmarkToUser("Local cluster %s found. Booting up...", clusterName) } else { @@ -243,16 +236,13 @@ func localStartNode(_ *cobra.Command, args []string) error { } sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") - if err := sd.StartServer(); err != nil { return err } - _, avalancheGoBinPath, err := sd.SetupLocalEnv() if err != nil { return err } - // make sure rootDir exists if err := os.MkdirAll(rootDir, 0o700); err != nil { return fmt.Errorf("could not create root directory %s: %w", rootDir, err) @@ -292,12 +282,19 @@ func localStartNode(_ *cobra.Command, args []string) error { if bootstrapIPs != nil { anrOpts = append(anrOpts, client.WithBootstrapNodeIPPortPairs(bootstrapIPs)) } - - ux.Logger.PrintToUser("Booting Network. Wait until healthy...") + spinSession := ux.NewUserSpinner() + spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...") + cli, err := binutils.NewGRPCClient() + if err != nil { + ux.SpinFailWithError(spinner, "", err) + return err + } if _, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...); err != nil { + ux.SpinFailWithError(spinner, "", err) return fmt.Errorf("failed to start local avalanchego: %w", err) } + ux.SpinComplete(spinner) // save snapshot after successful start if _, err := cli.SaveSnapshot( ctx, @@ -311,6 +308,10 @@ func localStartNode(_ *cobra.Command, args []string) error { return err } } + cli, err := binutils.NewGRPCClient() + if err != nil { + return err + } loadSnapshotOpts := []client.OpOption{ client.WithRootDataDir(rootDir), @@ -338,9 +339,10 @@ func localStartNode(_ *cobra.Command, args []string) error { } func localStopNode(_ *cobra.Command, args []string) error { + // todo: support only one local node and detect what cluster to stop clusterName := args[0] if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { - return fmt.Errorf("failed to check if cluster %q is local: %w", clusterName, err) + return fmt.Errorf("local node %q is not found", clusterName) } cli, err := binutils.NewGRPCClient( binutils.WithAvoidRPCVersionCheck(true), @@ -373,20 +375,20 @@ func localStopNode(_ *cobra.Command, args []string) error { if _, err = cli.Stop(ctx); err != nil { return fmt.Errorf("failed to stop avalanchego: %w", err) } - + ux.Logger.GreenCheckmarkToUser("avalanchego stopped. State saved for %s", clusterName) return nil } func localDestroyNode(_ *cobra.Command, args []string) error { clusterName := args[0] if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { - return fmt.Errorf("failed to check if cluster %q is local: %w", clusterName, err) + return fmt.Errorf("local cluster %q not found", clusterName) } if err := cleanupLocalNode(clusterName); err != nil { return fmt.Errorf("failed to cleanup local node: %w", err) } - ux.Logger.PrintToUser("Local node cleaned up.") + ux.Logger.GreenCheckmarkToUser("Local node %s cleaned up.", clusterName) return nil } diff --git a/go.mod b/go.mod index f07dfa284..72318018a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344 + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index 8124f430c..8c65a59dc 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344 h1:wD/rBr+QKztcKtRtBNqPjzMhwcxnVcuJ3GT62DdgS2Q= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a h1:xd2RUTW9w34+V6yI7zWfByHZ8y5CeXhvHK+nAJ9FCbI= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f h1:YUQF1wQJeEcTMC5W/OrwgSFTFMS4zeCM8O02rLeEDow= diff --git a/pkg/models/clusters_config.go b/pkg/models/clusters_config.go index a789d4771..02d5b11b2 100644 --- a/pkg/models/clusters_config.go +++ b/pkg/models/clusters_config.go @@ -54,14 +54,17 @@ func (cc *ClusterConfig) GetValidatorHosts(hosts []*Host) []*Host { } func (cc *ClusterConfig) IsAPIHost(hostCloudID string) bool { - return slices.Contains(cc.APINodes, hostCloudID) + return cc.Local || slices.Contains(cc.APINodes, hostCloudID) } func (cc *ClusterConfig) IsAvalancheGoHost(hostCloudID string) bool { - return slices.Contains(cc.Nodes, hostCloudID) + return cc.Local || slices.Contains(cc.Nodes, hostCloudID) } func (cc *ClusterConfig) GetCloudIDs() []string { + if cc.Local { + return nil + } r := cc.Nodes if cc.MonitoringInstance != "" { r = append(r, cc.MonitoringInstance) From 1f1358e89e7a65ada2728f2a94a732dd3a1bc9db Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Wed, 9 Oct 2024 18:09:52 -0300 Subject: [PATCH 14/57] partial work --- cmd/blockchaincmd/add_validator.go | 246 +++++++++++++++--- cmd/blockchaincmd/change_weight.go | 2 +- cmd/contractcmd/init_poa_validator_manager.go | 2 +- pkg/constants/constants.go | 6 +- pkg/evm/evm.go | 20 ++ pkg/subnet/public.go | 16 +- ...eployed_poa_validator_manager_bytecode.txt | 2 +- pkg/validatormanager/validatormanager.go | 130 +++++++++ 8 files changed, 380 insertions(+), 44 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index d6d92107f..9bf732e38 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -3,16 +3,19 @@ package blockchaincmd import ( + "encoding/hex" "errors" "fmt" "time" - "github.com/ava-labs/avalanchego/utils/formatting/address" + "github.com/ava-labs/avalanchego/api/info" warpPlatformVM "github.com/ava-labs/avalanchego/vms/platformvm/warp" - "github.com/ava-labs/avalanchego/vms/secp256k1fx" + "github.com/ethereum/go-ethereum/common" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/constants" + "github.com/ava-labs/avalanche-cli/pkg/contract" + "github.com/ava-labs/avalanche-cli/pkg/evm" "github.com/ava-labs/avalanche-cli/pkg/keychain" "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" @@ -21,9 +24,12 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/txutils" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" + "github.com/ava-labs/avalanche-cli/pkg/validatormanager" "github.com/ava-labs/avalanchego/ids" avagoconstants "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/vms/platformvm" + warpMessage "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" "github.com/spf13/cobra" ) @@ -36,6 +42,7 @@ var ( } nodeIDStr string + nodeEndpoint string balance uint64 weight uint64 startTimeStr string @@ -77,7 +84,7 @@ Testnet or Mainnet.`, networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, addValidatorSupportedNetworkOptions) cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet only]") - cmd.Flags().Uint64Var(&weight, "weight", constants.BootstrapValidatorWeight, "set the staking weight of the validator to add") + cmd.Flags().Uint64Var(&weight, "weight", constants.NonBootstrapValidatorWeight, "set the staking weight of the validator to add") cmd.Flags().Uint64Var(&balance, "balance", 0, "set the AVAX balance of the validator that will be used for continuous fee to P-Chain") cmd.Flags().BoolVarP(&useEwoq, "ewoq", "e", false, "use ewoq key [fuji/devnet only]") cmd.Flags().BoolVarP(&useLedger, "ledger", "g", false, "use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)") @@ -87,15 +94,33 @@ Testnet or Mainnet.`, cmd.Flags().StringVar(&publicKey, "bls-public-key", "", "set the BLS public key of the validator to add") cmd.Flags().StringVar(&pop, "bls-proof-of-possession", "", "set the BLS proof of possession of the validator to add") cmd.Flags().StringVar(&changeAddr, "change-address", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet") + cmd.Flags().StringVar(&nodeEndpoint, "node-endpoint", "", "gather node id/bls from publicly available avalanchego apis on the given endpoint") return cmd } func addValidator(_ *cobra.Command, args []string) error { - blockchainName := args[0] - err := prompts.ValidateNodeID(nodeIDStr) + if nodeEndpoint != "" { + infoClient := info.NewClient(nodeEndpoint) + ctx, cancel := utils.GetAPILargeContext() + defer cancel() + nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx) + if err != nil { + return err + } + nodeIDStr = nodeID.String() + publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:]) + pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:]) + } + nodeID, err := ids.NodeIDFromString(nodeIDStr) if err != nil { return err } + blsInfo, err := getBLSInfo(publicKey, pop) + if err != nil { + return fmt.Errorf("failure parsing BLS info: %w", err) + } + expiry := uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix()) + fmt.Println("Expiry:", expiry) network, err := networkoptions.GetNetworkFromCmdLineFlags( app, @@ -109,8 +134,167 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return err } - fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee + + chainSpec := contract.ChainSpec{ + BlockchainName: "poa", + } + rpcURL, _, err := contract.GetBlockchainEndpoints( + app, + network, + chainSpec, + false, + false, + ) + if err != nil { + return err + } + + for _, n := range []string{ + "NodeID-BJe9MSoteeNtrQkKnicKez1zoLiMXrPKq", + "NodeID-FeonWY2gTTTHTvu86BUU4zPYnTzjCrsiu", + "NodeID-HfTXNwnR8TFKe6Z3aTKm1Mufuvn6kNaob", + "NodeID-8THh1JB8D27gU4qaCLFZqWr4qqDk1xoup", + } { + nID, err := ids.NodeIDFromString(n) + if err != nil { + return err + } + validatorID, err := validatormanager.GetRegisteredValidator( + rpcURL, + common.HexToAddress(validatormanager.ValidatorContractAddress), + nID, + ) + if err != nil { + return err + } + fmt.Println(nID, validatorID) + } + + sc, err := app.LoadSidecar(chainSpec.BlockchainName) + if err != nil { + return fmt.Errorf("failed to load sidecar: %w", err) + } + balanceOwners := warpMessage.PChainOwner{} + disableOwners := warpMessage.PChainOwner{} + + ownerPrivateKeyFound, n, _, ownerPrivateKey, err := contract.SearchForManagedKey( + app, + network, + common.HexToAddress(sc.PoAValidatorManagerOwner), + true, + ) + if err != nil { + return err + } + fmt.Println(n) + if !ownerPrivateKeyFound { + return fmt.Errorf("not private key found for PoA manager owner %s", sc.PoAValidatorManagerOwner) + } + + fmt.Println("Initialize registration") + fmt.Println(rpcURL) + evmTx, receipt, err := validatormanager.PoAValidatorManagerInitializeValidatorRegistration( + rpcURL, + common.HexToAddress(validatormanager.ValidatorContractAddress), + ownerPrivateKey, + nodeID, + blsInfo.PublicKey[:], + expiry, + balanceOwners, + disableOwners, + weight, + ) + if err != nil { + if evmTx != nil { + fmt.Println(evmTx.Hash()) + } + fmt.Println(receipt) + return err + } + client, err := evm.GetClient(rpcURL) + if err != nil { + return err + } + defer client.Close() + ctx, cancel := utils.GetAPILargeContext() + defer cancel() + + fmt.Println("receipt:", receipt.BlockNumber, receipt.BlockHash) + unsignedMessage, err := evm.ExtractWarpMessageFromReceipt( + client, + ctx, + receipt, + ) + if err != nil { + return err + } + fmt.Println("unsigned warp message: ", unsignedMessage.ID()) + subnetID, err := contract.GetSubnetID( + app, + network, + chainSpec, + ) + fmt.Println("Get signed message") + signedMessage, err := validatormanager.PoaValidatorManagerGetSubnetValidatorRegistrationMessage( + network, + app.Log, + logging.Verbo, + 0, + subnetID, + common.HexToAddress(validatormanager.ValidatorContractAddress), + nodeID, + blsInfo.PublicKey, + expiry, + balanceOwners, + disableOwners, + weight, + ) + if err != nil { + return err + } + kc, err := keychain.GetKeychainFromCmdLineFlags( + app, + constants.PayTxsFeesMsg, + network, + keyName, + useEwoq, + useLedger, + ledgerAddresses, + 0, + ) + if err != nil { + return err + } + deployer := subnet.NewPublicDeployer(app, kc, network) + + fmt.Println("register validator on pchain") + _, err = deployer.RegisterL1Validator(balance, blsInfo, signedMessage) + if err != nil { + return err + } + return nil + + blockchainName := args[0] + err = prompts.ValidateNodeID(nodeIDStr) + if err != nil { + return err + } + + network, err = networkoptions.GetNetworkFromCmdLineFlags( + app, + "", + globalNetworkFlags, + true, + false, + addValidatorSupportedNetworkOptions, + "", + ) + if err != nil { + return err + } + fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee + kc, err = keychain.GetKeychainFromCmdLineFlags( app, constants.PayTxsFeesMsg, network, @@ -129,7 +313,7 @@ func addValidator(_ *cobra.Command, args []string) error { return err } } - deployer := subnet.NewPublicDeployer(app, kc, network) + deployer = subnet.NewPublicDeployer(app, kc, network) if !sovereign { return CallAddValidatorNonSOV(deployer, network, kc, useLedger, blockchainName, nodeIDStr, defaultValidatorParams, waitForTxAcceptance) } @@ -231,33 +415,27 @@ func CallAddValidator( ux.Logger.PrintToUser("Change Address: %s", changeAddr) ux.Logger.PrintToUser("Inputs complete, issuing transaction to add the provided validator information...") - blsInfo, err := getBLSInfo(publicKey, pop) - if err != nil { - return fmt.Errorf("failure parsing BLS info: %w", err) - } - addrs, err := address.ParseToIDs([]string{changeAddr}) - if err != nil { - return fmt.Errorf("failure parsing change owner address: %w", err) - } - changeOwner := &secp256k1fx.OutputOwners{ - Threshold: 1, - Addrs: addrs, - } - nodeID, err := ids.NodeIDFromString(nodeIDStrFormat) - if err != nil { - return err - } - // TODO: generate warp message - // expiry is set to 48 hours from time of transaction - message, err := generateWarpMessageAddValidator(subnetID, nodeID, weight, publicKey, uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix())) - if err != nil { - return err - } - tx, err := deployer.RegisterL1Validator(balance, blsInfo, changeOwner, message) - if err != nil { - return err - } - ux.Logger.GreenCheckmarkToUser("Register Subnet Validator Tx ID: %s", tx.ID()) + /* + blsInfo, err := getBLSInfo(publicKey, pop) + if err != nil { + return fmt.Errorf("failure parsing BLS info: %w", err) + } + nodeID, err := ids.NodeIDFromString(nodeIDStrFormat) + if err != nil { + return err + } + // TODO: generate warp message + // expiry is set to 48 hours from time of transaction + message, err := generateWarpMessageAddValidator(subnetID, nodeID, weight, publicKey, uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix())) + if err != nil { + return err + } + tx, err := deployer.RegisterL1Validator(balance, blsInfo, message) + if err != nil { + return err + } + ux.Logger.GreenCheckmarkToUser("Register Subnet Validator Tx ID: %s", tx.ID()) + */ return nil } diff --git a/cmd/blockchaincmd/change_weight.go b/cmd/blockchaincmd/change_weight.go index af1760ba6..65f700f63 100644 --- a/cmd/blockchaincmd/change_weight.go +++ b/cmd/blockchaincmd/change_weight.go @@ -33,7 +33,7 @@ The Subnet has to be a Proof of Authority Subnet-Only Validator Subnet.`, networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, addValidatorSupportedNetworkOptions) cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet only]") - cmd.Flags().Uint64Var(&weight, "weight", constants.BootstrapValidatorWeight, "set the new staking weight of the validator") + cmd.Flags().Uint64Var(&weight, "weight", constants.NonBootstrapValidatorWeight, "set the new staking weight of the validator") cmd.Flags().BoolVarP(&useEwoq, "ewoq", "e", false, "use ewoq key [fuji/devnet only]") cmd.Flags().StringVar(&nodeIDStr, "node-id", "", "node-id of the validator") cmd.Flags().BoolVarP(&useLedger, "ledger", "g", false, "use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)") diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index 940f56290..4512a8f9d 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -37,7 +37,7 @@ var ( // avalanche contract initpoamanager func newInitPOAManagerCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "initPoaManager", + Use: "initPoaManager blockchainName", Short: "Initializes a Proof of Authority Validator Manager on a given Network and Blockchain", Long: "Initializes Proof of Authority Validator Manager contract on a Blockchain and sets up initial validator set on the Blockchain. For more info on Validator Manager, please head to https://github.com/ava-labs/teleporter/tree/staking-contract/contracts/validator-manager", RunE: initPOAManager, diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 72edee75c..f9f882410 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -158,12 +158,14 @@ const ( // nAVAX BootstrapValidatorBalance = 1000000000 // Default weight when we prompt users for bootstrap validators - BootstrapValidatorWeight = 1000000 + BootstrapValidatorWeight = 100 + // Default weight when we prompt users for non bootstrap validators + NonBootstrapValidatorWeight = 20 DefaultStakeWeight = 20 AVAXSymbol = "AVAX" DefaultFujiStakeDuration = "48h" DefaultMainnetStakeDuration = "336h" - DefaultValidationIDExpiryDuration = 48 * time.Hour + DefaultValidationIDExpiryDuration = 24 * time.Hour // The absolute minimum is 25 seconds, but set to 1 minute to allow for // time to go through the command DevnetStakingStartLeadTime = 30 * time.Second diff --git a/pkg/evm/evm.go b/pkg/evm/evm.go index eb3aea977..dcdfda486 100644 --- a/pkg/evm/evm.go +++ b/pkg/evm/evm.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/subnet-evm/core/types" "github.com/ava-labs/subnet-evm/ethclient" "github.com/ava-labs/subnet-evm/interfaces" + subnetEvmInterfaces "github.com/ava-labs/subnet-evm/interfaces" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/precompile/contracts/warp" "github.com/ava-labs/subnet-evm/predicate" @@ -603,3 +604,22 @@ func WaitForNewBlock( } return fmt.Errorf("new block not produced in %f seconds", totalDuration.Seconds()) } + +func ExtractWarpMessageFromReceipt( + client ethclient.Client, + ctx context.Context, + receipt *types.Receipt, +) (*avalancheWarp.UnsignedMessage, error) { + logs, err := client.FilterLogs(ctx, subnetEvmInterfaces.FilterQuery{ + BlockHash: &receipt.BlockHash, + Addresses: []common.Address{warp.Module.Address}, + }) + if err != nil { + return nil, err + } + if len(logs) != 1 { + return nil, fmt.Errorf("expected block to contain 1 warp log, got %d", len(logs)) + } + txLog := logs[0] + return warp.UnpackSendWarpEventDataToMessage(txLog.Data) +} diff --git a/pkg/subnet/public.go b/pkg/subnet/public.go index 3f717f723..d801e10be 100644 --- a/pkg/subnet/public.go +++ b/pkg/subnet/public.go @@ -8,7 +8,6 @@ import ( "fmt" "time" - "github.com/ava-labs/avalanchego/vms/platformvm/fx" avagofee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee" "github.com/ava-labs/avalanchego/vms/platformvm/warp" @@ -127,11 +126,18 @@ func (d *PublicDeployer) SetL1ValidatorWeight( func (d *PublicDeployer) RegisterL1Validator( balance uint64, - signer signer.ProofOfPossession, - changeOwner fx.Owner, - message warp.Message, + pop signer.ProofOfPossession, + message *warp.Message, ) (*txs.Tx, error) { - return nil, nil + wallet, err := d.loadCacheWallet() + if err != nil { + return nil, err + } + return wallet.P().IssueRegisterSubnetValidatorTx( + balance, + pop.ProofOfPossession, + message.Bytes(), + ) } // change subnet owner for [subnetID] diff --git a/pkg/validatormanager/deployed_poa_validator_manager_bytecode.txt b/pkg/validatormanager/deployed_poa_validator_manager_bytecode.txt index 02cd97464..99a866e90 100644 --- a/pkg/validatormanager/deployed_poa_validator_manager_bytecode.txt +++ b/pkg/validatormanager/deployed_poa_validator_manager_bytecode.txt @@ -1 +1 @@ -0x608060405234801561000f575f80fd5b5060043610610132575f3560e01c8063a3a65e48116100b4578063c974d1b611610079578063c974d1b6146102a7578063d588c18f146102af578063d5f20ff6146102c2578063df93d8de146102e2578063f2fde38b146102ec578063fd7ac5e7146102ff575f80fd5b8063a3a65e481461024c578063b18f3f1a1461025f578063b771b3bc14610272578063bc5fbfec14610280578063bee0a03f14610294575f80fd5b8063715018a6116100fa578063715018a6146101be578063732214f8146101c65780638280a25a146101db5780638da5cb5b146101f557806397fb70d414610239575f80fd5b80630322ed981461013657806320d91b7a1461014b578063467ef06f1461015e57806360305d621461017157806366435abf14610193575b5f80fd5b610149610144366004612acf565b610312565b005b610149610159366004612afe565b610529565b61014961016c366004612b4c565b610a15565b610179601481565b60405163ffffffff90911681526020015b60405180910390f35b6101a66101a1366004612acf565b610a23565b6040516001600160401b03909116815260200161018a565b610149610a37565b6101cd5f81565b60405190815260200161018a565b6101e3603081565b60405160ff909116815260200161018a565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b03165b6040516001600160a01b03909116815260200161018a565b610149610247366004612acf565b610a4a565b61014961025a366004612b4c565b610a5f565b6101cd61026d366004612b7b565b610be8565b6102216005600160991b0181565b6101cd5f805160206136c983398151915281565b6101496102a2366004612acf565b610c04565b6101e3601481565b6101496102bd366004612bd4565b610d41565b6102d56102d0366004612acf565b610e4f565b60405161018a9190612c91565b6101a66202a30081565b6101496102fa366004612d11565b610f9e565b6101cd61030d366004612d33565b610fdb565b5f8181525f805160206136e98339815191526020526040808220815160e0810190925280545f805160206136c983398151915293929190829060ff16600581111561035f5761035f612c10565b600581111561037057610370612c10565b815260200160018201805461038490612d9e565b80601f01602080910402602001604051908101604052809291908181526020018280546103b090612d9e565b80156103fb5780601f106103d2576101008083540402835291602001916103fb565b820191905f5260205f20905b8154815290600101906020018083116103de57829003601f168201915b505050918352505060028201546001600160401b038082166020840152600160401b820481166040840152600160801b820481166060840152600160c01b909104811660808301526003928301541660a0909101529091508151600581111561046657610466612c10565b146104a2575f8381526007830160205260409081902054905163170cc93360e21b81526104999160ff1690600401612dd6565b60405180910390fd5b6005600160991b016001600160a01b031663ee5b48eb6104c78584606001515f611036565b6040518263ffffffff1660e01b81526004016104e39190612de4565b6020604051808303815f875af11580156104ff573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105239190612df6565b50505050565b7fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb09545f805160206136c98339815191529060ff161561057b57604051637fab81e560e01b815260040160405180910390fd5b6005600160991b016001600160a01b0316634213cf786040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105be573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105e29190612df6565b83602001351461060b576040516372b0a7e760e11b815260208401356004820152602401610499565b3061061c6060850160408601612d11565b6001600160a01b03161461065f5761063a6060840160408501612d11565b604051632f88120d60e21b81526001600160a01b039091166004820152602401610499565b5f61066d6060850185612e0d565b905090505f805b828163ffffffff161015610955575f6106906060880188612e0d565b8363ffffffff168181106106a6576106a6612e52565b90506020028101906106b89190612e66565b6106c190612f8a565b80516040519192505f9160088801916106d991613003565b9081526020016040518091039020541461070957805160405163a41f772f60e01b81526104999190600401612de4565b5f6002885f01358460405160200161073892919091825260e01b6001600160e01b031916602082015260240190565b60408051601f198184030181529082905261075291613003565b602060405180830381855afa15801561076d573d5f803e3d5ffd5b5050506040513d601f19601f820116820180604052508101906107909190612df6565b90508086600801835f01516040516107a89190613003565b90815260408051602092819003830181209390935560e0830181526002835284518284015284810180516001600160401b03908116858401525f60608601819052915181166080860152421660a085015260c0840181905284815260078a01909252902081518154829060ff1916600183600581111561082a5761082a612c10565b021790555060208201516001820190610843908261305f565b506040828101516002830180546060860151608087015160a08801516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909301516003909201805467ffffffffffffffff1916928416929092179091558301516108e8911685613132565b82516040519195506108f991613003565b60408051918290038220908401516001600160401b031682529082907f9d47fef9da077661546e646d61830bfcbda90506c2e5eed38195e82c4eb1cbdf9060200160405180910390a350508061094e90613145565b9050610674565b50600483018190555f61097361096a86611085565b6040015161119b565b90505f61097f87611310565b90505f6002826040516109929190613003565b602060405180830381855afa1580156109ad573d5f803e3d5ffd5b5050506040513d601f19601f820116820180604052508101906109d09190612df6565b90508281146109fc57604051631872fc8d60e01b81526004810182905260248101849052604401610499565b5050506009909201805460ff1916600117905550505050565b610a1e81611549565b505050565b5f610a2d82610e4f565b6080015192915050565b610a3f611887565b610a485f6118e2565b565b610a52611887565b610a5b81611952565b5050565b5f805160206136c98339815191525f80610a84610a7b85611085565b60400151611c36565b9150915080610aaa57604051632d07135360e01b81528115156004820152602401610499565b5f82815260068401602052604090208054610ac490612d9e565b90505f03610ae85760405163089938b360e11b815260048101839052602401610499565b60015f83815260078501602052604090205460ff166005811115610b0e57610b0e612c10565b14610b41575f8281526007840160205260409081902054905163170cc93360e21b81526104999160ff1690600401612dd6565b5f8281526006840160205260408120610b5991612a43565b5f828152600784016020908152604091829020805460ff1916600290811782550180546001600160401b0342818116600160c01b026001600160c01b0390931692909217928390558451600160801b9093041682529181019190915283917ff8fd1c90fb9cfa2ca2358fdf5806b086ad43315d92b221c929efc7f105ce7568910160405180910390a250505050565b5f610bf1611887565b610bfb8383611dda565b90505b92915050565b5f8181527fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb066020526040902080545f805160206136c98339815191529190610c4b90612d9e565b90505f03610c6f5760405163089938b360e11b815260048101839052602401610499565b60015f83815260078301602052604090205460ff166005811115610c9557610c95612c10565b14610cc8575f8281526007820160205260409081902054905163170cc93360e21b81526104999160ff1690600401612dd6565b5f82815260068201602052604090819020905163ee5b48eb60e01b81526005600160991b019163ee5b48eb91610d019190600401613167565b6020604051808303815f875af1158015610d1d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a1e9190612df6565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f81158015610d855750825b90505f826001600160401b03166001148015610da05750303b155b905081158015610dae575080155b15610dcc5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315610df657845460ff60401b1916600160401b1785555b610e00878761232b565b8315610e4657845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b610e57612a7a565b5f8281525f805160206136e9833981519152602052604090819020815160e0810190925280545f805160206136c9833981519152929190829060ff166005811115610ea457610ea4612c10565b6005811115610eb557610eb5612c10565b8152602001600182018054610ec990612d9e565b80601f0160208091040260200160405190810160405280929190818152602001828054610ef590612d9e565b8015610f405780601f10610f1757610100808354040283529160200191610f40565b820191905f5260205f20905b815481529060010190602001808311610f2357829003601f168201915b505050918352505060028201546001600160401b038082166020840152600160401b820481166040840152600160801b820481166060840152600160c01b9091048116608083015260039092015490911660a0909101529392505050565b610fa6611887565b6001600160a01b038116610fcf57604051631e4fbdf760e01b81525f6004820152602401610499565b610fd8816118e2565b50565b6040515f905f805160206136c9833981519152907fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb089061101e90869086906131f1565b90815260200160405180910390205491505092915050565b604080515f6020820152600360e01b602282015260268101949094526001600160c01b031960c093841b811660468601529190921b16604e830152805180830360360181526056909201905290565b60408051606080820183525f8083526020830152918101919091526040516306f8253560e41b815263ffffffff831660048201525f9081906005600160991b0190636f825350906024015f60405180830381865afa1580156110e9573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052611110919081019061320f565b915091508061113257604051636b2f19e960e01b815260040160405180910390fd5b815115611158578151604051636ba589a560e01b81526004810191909152602401610499565b60208201516001600160a01b031615611194576020820151604051624de75d60e31b81526001600160a01b039091166004820152602401610499565b5092915050565b5f81516026146111be57604051638d0242c960e01b815260040160405180910390fd5b5f805b600281101561120d576111d58160016132e1565b6111e09060086132f4565b61ffff168482815181106111f6576111f6612e52565b016020015160f81c901b91909117906001016111c1565b5061ffff8116156112315760405163059510e360e31b815260040160405180910390fd5b5f805b600481101561128c576112488160036132e1565b6112539060086132f4565b63ffffffff1685611265836002613132565b8151811061127557611275612e52565b016020015160f81c901b9190911790600101611234565b5063ffffffff8116156112b257604051635b60892f60e01b815260040160405180910390fd5b5f805b6020811015611307576112c981601f6132e1565b6112d49060086132f4565b866112e0836006613132565b815181106112f0576112f0612e52565b016020015160f81c901b91909117906001016112b5565b50949350505050565b60605f8083356020850135601461132c87870160408901612d11565b6113396060890189612e0d565b60405160f09790971b6001600160f01b0319166020880152602287019590955250604285019290925260e090811b6001600160e01b0319908116606286015260609290921b6bffffffffffffffffffffffff191660668501529190911b16607a820152607e0160405160208183030381529060405290505f5b6113bf6060850185612e0d565b9050811015611194576113d56060850185612e0d565b828181106113e5576113e5612e52565b90506020028101906113f79190612e66565b61140590602081019061330b565b905060301461142757604051634be6321b60e01b815260040160405180910390fd5b816114356060860186612e0d565b8381811061144557611445612e52565b90506020028101906114579190612e66565b611461908061330b565b90506114706060870187612e0d565b8481811061148057611480612e52565b90506020028101906114929190612e66565b61149c908061330b565b6114a96060890189612e0d565b868181106114b9576114b9612e52565b90506020028101906114cb9190612e66565b6114d990602081019061330b565b6114e660608b018b612e0d565b888181106114f6576114f6612e52565b90506020028101906115089190612e66565b61151990606081019060400161334d565b60405160200161152f9796959493929190613366565b60408051601f1981840301815291905291506001016113b2565b5f611552612a7a565b5f805160206136c98339815191525f8061156e610a7b87611085565b91509150801561159557604051632d07135360e01b81528115156004820152602401610499565b5f828152600784016020526040808220815160e081019092528054829060ff1660058111156115c6576115c6612c10565b60058111156115d7576115d7612c10565b81526020016001820180546115eb90612d9e565b80601f016020809104026020016040519081016040528092919081815260200182805461161790612d9e565b80156116625780601f1061163957610100808354040283529160200191611662565b820191905f5260205f20905b81548152906001019060200180831161164557829003601f168201915b505050918352505060028201546001600160401b038082166020840152600160401b820481166040840152600160801b820481166060840152600160c01b909104811660808301526003928301541660a090910152909150815160058111156116cd576116cd612c10565b141580156116ee57506001815160058111156116eb576116eb612c10565b14155b1561170f57805160405163170cc93360e21b81526104999190600401612dd6565b60038151600581111561172457611724612c10565b036117325760048152611737565b600581525b83600801816020015160405161174d9190613003565b90815260408051602092819003830190205f908190558581526007870190925290208151815483929190829060ff1916600183600581111561179157611791612c10565b0217905550602082015160018201906117aa908261305f565b5060408201516002820180546060850151608086015160a08701516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909201516003909101805467ffffffffffffffff1916919092161790558051600581111561185057611850612c10565b60405184907f1c08e59656f1a18dc2da76826cdc52805c43e897a17c50faefb8ab3c1526cc16905f90a39196919550909350505050565b336118b97f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b6001600160a01b031614610a485760405163118cdaa760e01b8152336004820152602401610499565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b61195a612a7a565b5f8281525f805160206136e98339815191526020526040808220815160e0810190925280545f805160206136c983398151915293929190829060ff1660058111156119a7576119a7612c10565b60058111156119b8576119b8612c10565b81526020016001820180546119cc90612d9e565b80601f01602080910402602001604051908101604052809291908181526020018280546119f890612d9e565b8015611a435780601f10611a1a57610100808354040283529160200191611a43565b820191905f5260205f20905b815481529060010190602001808311611a2657829003601f168201915b50505091835250506002828101546001600160401b038082166020850152600160401b820481166040850152600160801b820481166060850152600160c01b9091048116608084015260039093015490921660a09091015290915081516005811115611ab157611ab1612c10565b14611ae4575f8481526007830160205260409081902054905163170cc93360e21b81526104999160ff1690600401612dd6565b60038152426001600160401b031660c08201525f84815260078301602052604090208151815483929190829060ff19166001836005811115611b2857611b28612c10565b021790555060208201516001820190611b41908261305f565b5060408201516002820180546060850151608086015160a08701516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909201516003909101805467ffffffffffffffff1916919092161790555f611bdf8582612345565b6080840151604080516001600160401b03909216825242602083015291935083925087917f13d58394cf269d48bcf927959a29a5ffee7c9924dafff8927ecdf3c48ffa7c67910160405180910390a3509392505050565b5f808251602714611c5a57604051638d0242c960e01b815260040160405180910390fd5b5f805b6002811015611ca957611c718160016132e1565b611c7c9060086132f4565b61ffff16858281518110611c9257611c92612e52565b016020015160f81c901b9190911790600101611c5d565b5061ffff811615611ccd5760405163059510e360e31b815260040160405180910390fd5b5f805b6004811015611d2857611ce48160036132e1565b611cef9060086132f4565b63ffffffff1686611d01836002613132565b81518110611d1157611d11612e52565b016020015160f81c901b9190911790600101611cd0565b5063ffffffff8116600214611d5057604051635b60892f60e01b815260040160405180910390fd5b5f805b6020811015611da557611d6781601f6132e1565b611d729060086132f4565b87611d7e836006613132565b81518110611d8e57611d8e612e52565b016020015160f81c901b9190911790600101611d53565b505f86602681518110611dba57611dba612e52565b016020015191976001600160f81b03199092161515965090945050505050565b7fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb09545f9060ff16611e1e57604051637fab81e560e01b815260040160405180910390fd5b5f805160206136c983398151915242611e3d60a086016080870161334d565b6001600160401b0316111580611e775750611e5b6202a30042613132565b611e6b60a086016080870161334d565b6001600160401b031610155b15611eb157611e8c60a085016080860161334d565b604051635879da1360e11b81526001600160401b039091166004820152602401610499565b6030611ec0602086018661330b565b905014611ef257611ed4602085018561330b565b6040516326475b2f60e11b8152610499925060040190815260200190565b611efc848061330b565b90505f03611f2957611f0e848061330b565b604051633e08a12560e11b81526004016104999291906133cf565b5f60088201611f38868061330b565b604051611f469291906131f1565b90815260200160405180910390205414611f7f57611f64848061330b565b60405163a41f772f60e01b81526004016104999291906133cf565b611f89835f61249c565b6040805160e08101909152815481525f9081906120959060208101611fae898061330b565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250505090825250602090810190611ff6908a018a61330b565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525050509082525060200161203f60a08a0160808b0161334d565b6001600160401b0316815260200161205a60408a018a6133fd565b61206390613411565b815260200161207560608a018a6133fd565b61207e90613411565b8152602001876001600160401b0316815250612676565b5f828152600686016020526040902091935091506120b3828261305f565b5081600884016120c3888061330b565b6040516120d19291906131f1565b9081526040519081900360200181209190915563ee5b48eb60e01b81525f906005600160991b019063ee5b48eb9061210d908590600401612de4565b6020604051808303815f875af1158015612129573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061214d9190612df6565b6040805160e08101909152909150806001815260200161216d898061330b565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201829052509385525050506001600160401b0389166020808401829052604080850184905260608501929092526080840183905260a0909301829052868252600788019092522081518154829060ff191660018360058111156121fc576121fc612c10565b021790555060208201516001820190612215908261305f565b5060408201516002820180546060850151608086015160a08701516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909201516003909101805467ffffffffffffffff191691909216179055806122b3888061330b565b6040516122c19291906131f1565b604051908190039020847fb77297e3befc691bfc864a81e241f83e2ef722b6e7becaa2ecec250c6d52b430896122fd60a08d0160808e0161334d565b604080516001600160401b0393841681529290911660208301520160405180910390a4509095945050505050565b612333612863565b61233c826128ac565b610a5b816128c5565b5f8281525f805160206136e9833981519152602052604081206002015481905f805160206136c983398151915290600160801b90046001600160401b031661238d858261249c565b5f612397876128d6565b5f8881526007850160205260408120600201805467ffffffffffffffff60801b1916600160801b6001600160401b038b16021790559091506005600160991b0163ee5b48eb6123e78a858b611036565b6040518263ffffffff1660e01b81526004016124039190612de4565b6020604051808303815f875af115801561241f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124439190612df6565b604080516001600160401b038a811682526020820184905282519394508516928b927f07de5ff35a674a8005e661f3333c907ca6333462808762d19dc7b3abb1a8c1df928290030190a3909450925050505b9250929050565b5f805160206136c98339815191525f6001600160401b0380841690851611156124d0576124c983856134d8565b90506124dd565b6124da84846134d8565b90505b6040805160808101825260028401548082526003850154602083015260048501549282019290925260058401546001600160401b031660608201524291158061253f57506001840154815161253b916001600160401b031690613132565b8210155b15612565576001600160401b038316606082015281815260408101516020820152612584565b828160600181815161257791906134f8565b6001600160401b03169052505b6060810151612594906064613518565b602082015160018601546001600160401b0392909216916125bf9190600160401b900460ff166132f4565b10156125ef57606081015160405163dfae880160e01b81526001600160401b039091166004820152602401610499565b856001600160401b03168160400181815161260a9190613132565b9052506040810180516001600160401b038716919061262a9083906132e1565b905250805160028501556020810151600385015560408101516004850155606001516005909301805467ffffffffffffffff19166001600160401b039094169390931790925550505050565b5f606082604001515160301461269f57604051638d0242c960e01b815260040160405180910390fd5b82516020808501518051604080880151606089015160808a01518051908701515193515f986126e0988a986001989297929690959094909390929101613543565b60405160208183030381529060405290505f5b846080015160200151518110156127525781856080015160200151828151811061271f5761271f612e52565b60200260200101516040516020016127389291906135eb565b60408051601f1981840301815291905291506001016126f3565b5060a0840151805160209182015151604051612772938593929101613621565b60405160208183030381529060405290505f5b8460a0015160200151518110156127e457818560a001516020015182815181106127b1576127b1612e52565b60200260200101516040516020016127ca9291906135eb565b60408051601f198184030181529190529150600101612785565b5060c08401516040516127fb91839160200161365c565b604051602081830303815290604052905060028160405161281c9190613003565b602060405180830381855afa158015612837573d5f803e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061285a9190612df6565b94909350915050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16610a4857604051631afcd79f60e31b815260040160405180910390fd5b6128b4612863565b6128bc61294b565b610fd881612953565b6128cd612863565b610fd881612a3b565b5f8181525f805160206136e98339815191526020526040812060020180545f805160206136c9833981519152919060089061292090600160401b90046001600160401b031661368d565b91906101000a8154816001600160401b0302191690836001600160401b031602179055915050919050565b610a48612863565b61295b612863565b80355f805160206136c9833981519152908155601461298060608401604085016136a8565b60ff16118061299f575061299a60608301604084016136a8565b60ff16155b156129d3576129b460608301604084016136a8565b604051634a59bbff60e11b815260ff9091166004820152602401610499565b6129e360608301604084016136a8565b60018201805460ff92909216600160401b0260ff60401b19909216919091179055612a14604083016020840161334d565b600191909101805467ffffffffffffffff19166001600160401b0390921691909117905550565b610fa6612863565b508054612a4f90612d9e565b5f825580601f10612a5e575050565b601f0160209004905f5260205f2090810190610fd89190612ab7565b6040805160e08101909152805f81526060602082018190525f604083018190529082018190526080820181905260a0820181905260c09091015290565b5b80821115612acb575f8155600101612ab8565b5090565b5f60208284031215612adf575f80fd5b5035919050565b803563ffffffff81168114612af9575f80fd5b919050565b5f8060408385031215612b0f575f80fd5b82356001600160401b03811115612b24575f80fd5b830160808186031215612b35575f80fd5b9150612b4360208401612ae6565b90509250929050565b5f60208284031215612b5c575f80fd5b610bfb82612ae6565b80356001600160401b0381168114612af9575f80fd5b5f8060408385031215612b8c575f80fd5b82356001600160401b03811115612ba1575f80fd5b830160a08186031215612bb2575f80fd5b9150612b4360208401612b65565b6001600160a01b0381168114610fd8575f80fd5b5f808284036080811215612be6575f80fd5b6060811215612bf3575f80fd5b508291506060830135612c0581612bc0565b809150509250929050565b634e487b7160e01b5f52602160045260245ffd5b60068110612c4057634e487b7160e01b5f52602160045260245ffd5b9052565b5f5b83811015612c5e578181015183820152602001612c46565b50505f910152565b5f8151808452612c7d816020860160208601612c44565b601f01601f19169290920160200192915050565b60208152612ca3602082018351612c24565b5f602083015160e06040840152612cbe610100840182612c66565b905060408401516001600160401b0380821660608601528060608701511660808601528060808701511660a08601528060a08701511660c08601528060c08701511660e086015250508091505092915050565b5f60208284031215612d21575f80fd5b8135612d2c81612bc0565b9392505050565b5f8060208385031215612d44575f80fd5b82356001600160401b0380821115612d5a575f80fd5b818501915085601f830112612d6d575f80fd5b813581811115612d7b575f80fd5b866020828501011115612d8c575f80fd5b60209290920196919550909350505050565b600181811c90821680612db257607f821691505b602082108103612dd057634e487b7160e01b5f52602260045260245ffd5b50919050565b60208101610bfe8284612c24565b602081525f610bfb6020830184612c66565b5f60208284031215612e06575f80fd5b5051919050565b5f808335601e19843603018112612e22575f80fd5b8301803591506001600160401b03821115612e3b575f80fd5b6020019150600581901b3603821315612495575f80fd5b634e487b7160e01b5f52603260045260245ffd5b5f8235605e19833603018112612e7a575f80fd5b9190910192915050565b634e487b7160e01b5f52604160045260245ffd5b604051606081016001600160401b0381118282101715612eba57612eba612e84565b60405290565b604080519081016001600160401b0381118282101715612eba57612eba612e84565b604051601f8201601f191681016001600160401b0381118282101715612f0a57612f0a612e84565b604052919050565b5f6001600160401b03821115612f2a57612f2a612e84565b50601f01601f191660200190565b5f82601f830112612f47575f80fd5b8135612f5a612f5582612f12565b612ee2565b818152846020838601011115612f6e575f80fd5b816020850160208301375f918101602001919091529392505050565b5f60608236031215612f9a575f80fd5b612fa2612e98565b82356001600160401b0380821115612fb8575f80fd5b612fc436838701612f38565b83526020850135915080821115612fd9575f80fd5b50612fe636828601612f38565b602083015250612ff860408401612b65565b604082015292915050565b5f8251612e7a818460208701612c44565b601f821115610a1e57805f5260205f20601f840160051c810160208510156130395750805b601f840160051c820191505b81811015613058575f8155600101613045565b5050505050565b81516001600160401b0381111561307857613078612e84565b61308c816130868454612d9e565b84613014565b602080601f8311600181146130bf575f84156130a85750858301515b5f19600386901b1c1916600185901b178555613116565b5f85815260208120601f198616915b828110156130ed578886015182559484019460019091019084016130ce565b508582101561310a57878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610bfe57610bfe61311e565b5f63ffffffff80831681810361315d5761315d61311e565b6001019392505050565b5f60208083525f845461317981612d9e565b806020870152604060018084165f811461319a57600181146131b6576131e3565b60ff19851660408a0152604084151560051b8a010195506131e3565b895f5260205f205f5b858110156131da5781548b82018601529083019088016131bf565b8a016040019650505b509398975050505050505050565b818382375f9101908152919050565b80518015158114612af9575f80fd5b5f8060408385031215613220575f80fd5b82516001600160401b0380821115613236575f80fd5b9084019060608287031215613249575f80fd5b613251612e98565b8251815260208084015161326481612bc0565b82820152604084015183811115613279575f80fd5b80850194505087601f85011261328d575f80fd5b8351925061329d612f5584612f12565b83815288828587010111156132b0575f80fd5b6132bf84838301848801612c44565b806040840152508195506132d4818801613200565b9450505050509250929050565b81810381811115610bfe57610bfe61311e565b8082028115828204841417610bfe57610bfe61311e565b5f808335601e19843603018112613320575f80fd5b8301803591506001600160401b03821115613339575f80fd5b602001915036819003821315612495575f80fd5b5f6020828403121561335d575f80fd5b610bfb82612b65565b5f8851613377818460208d01612c44565b60e089901b6001600160e01b031916908301908152868860048301378681019050600481015f8152858782375060c09390931b6001600160c01b0319166004939094019283019390935250600c019695505050505050565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b5f8235603e19833603018112612e7a575f80fd5b5f60408236031215613421575f80fd5b613429612ec0565b61343283612ae6565b81526020808401356001600160401b038082111561344e575f80fd5b9085019036601f830112613460575f80fd5b81358181111561347257613472612e84565b8060051b9150613483848301612ee2565b818152918301840191848101903684111561349c575f80fd5b938501935b838510156134c657843592506134b683612bc0565b82825293850193908501906134a1565b94860194909452509295945050505050565b6001600160401b038281168282160390808211156111945761119461311e565b6001600160401b038181168382160190808211156111945761119461311e565b6001600160401b0381811683821602808216919082811461353b5761353b61311e565b505092915050565b61ffff60f01b8a60f01b1681525f63ffffffff60e01b808b60e01b1660028401528960068401528860268401528751613583816046860160208c01612c44565b87519084019061359a816046840160208c01612c44565b60c088901b6001600160c01b0319166046929091019182015260e086901b8216604e8201526135d8605282018660e01b6001600160e01b0319169052565b6056019c9b505050505050505050505050565b5f83516135fc818460208801612c44565b60609390931b6bffffffffffffffffffffffff19169190920190815260140192915050565b5f8451613632818460208901612c44565b6001600160e01b031960e095861b8116919093019081529290931b16600482015260080192915050565b5f835161366d818460208801612c44565b60c09390931b6001600160c01b0319169190920190815260080192915050565b5f6001600160401b0380831681810361315d5761315d61311e565b5f602082840312156136b8575f80fd5b813560ff81168114612d2c575f80fdfee92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb00e92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb07a164736f6c6343000819000a +0x608060405234801561000f575f80fd5b5060043610610132575f3560e01c80639ba96b86116100b4578063c974d1b611610079578063c974d1b6146102a7578063d588c18f146102af578063d5f20ff6146102c2578063df93d8de146102e2578063f2fde38b146102ec578063fd7ac5e7146102ff575f80fd5b80639ba96b861461024c578063a3a65e481461025f578063b771b3bc14610272578063bc5fbfec14610280578063bee0a03f14610294575f80fd5b8063715018a6116100fa578063715018a6146101be578063732214f8146101c65780638280a25a146101db5780638da5cb5b146101f557806397fb70d414610239575f80fd5b80630322ed981461013657806320d91b7a1461014b578063467ef06f1461015e57806360305d621461017157806366435abf14610193575b5f80fd5b610149610144366004612b01565b610312565b005b610149610159366004612b30565b610529565b61014961016c366004612b7e565b610a15565b610179601481565b60405163ffffffff90911681526020015b60405180910390f35b6101a66101a1366004612b01565b610a23565b6040516001600160401b03909116815260200161018a565b610149610a37565b6101cd5f81565b60405190815260200161018a565b6101e3603081565b60405160ff909116815260200161018a565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b03165b6040516001600160a01b03909116815260200161018a565b610149610247366004612b01565b610a4a565b6101cd61025a366004612bad565b610a5f565b61014961026d366004612b7e565b610a7b565b6102216005600160991b0181565b6101cd5f8051602061370d83398151915281565b6101496102a2366004612b01565b610c04565b6101e3601481565b6101496102bd366004612c06565b610d41565b6102d56102d0366004612b01565b610e4f565b60405161018a9190612cc3565b6101a66202a30081565b6101496102fa366004612d43565b610f9e565b6101cd61030d366004612d65565b610fdb565b5f8181525f8051602061372d8339815191526020526040808220815160e0810190925280545f8051602061370d83398151915293929190829060ff16600581111561035f5761035f612c42565b600581111561037057610370612c42565b815260200160018201805461038490612dd0565b80601f01602080910402602001604051908101604052809291908181526020018280546103b090612dd0565b80156103fb5780601f106103d2576101008083540402835291602001916103fb565b820191905f5260205f20905b8154815290600101906020018083116103de57829003601f168201915b505050918352505060028201546001600160401b038082166020840152600160401b820481166040840152600160801b820481166060840152600160c01b909104811660808301526003928301541660a0909101529091508151600581111561046657610466612c42565b146104a2575f8381526007830160205260409081902054905163170cc93360e21b81526104999160ff1690600401612e08565b60405180910390fd5b6005600160991b016001600160a01b031663ee5b48eb6104c78584606001515f611036565b6040518263ffffffff1660e01b81526004016104e39190612e16565b6020604051808303815f875af11580156104ff573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105239190612e28565b50505050565b7fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb09545f8051602061370d8339815191529060ff161561057b57604051637fab81e560e01b815260040160405180910390fd5b6005600160991b016001600160a01b0316634213cf786040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105be573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105e29190612e28565b83602001351461060b576040516372b0a7e760e11b815260208401356004820152602401610499565b3061061c6060850160408601612d43565b6001600160a01b03161461065f5761063a6060840160408501612d43565b604051632f88120d60e21b81526001600160a01b039091166004820152602401610499565b5f61066d6060850185612e3f565b905090505f805b828163ffffffff161015610955575f6106906060880188612e3f565b8363ffffffff168181106106a6576106a6612e84565b90506020028101906106b89190612e98565b6106c190612fbc565b80516040519192505f9160088801916106d991613035565b9081526020016040518091039020541461070957805160405163a41f772f60e01b81526104999190600401612e16565b5f6002885f01358460405160200161073892919091825260e01b6001600160e01b031916602082015260240190565b60408051601f198184030181529082905261075291613035565b602060405180830381855afa15801561076d573d5f803e3d5ffd5b5050506040513d601f19601f820116820180604052508101906107909190612e28565b90508086600801835f01516040516107a89190613035565b90815260408051602092819003830181209390935560e0830181526002835284518284015284810180516001600160401b03908116858401525f60608601819052915181166080860152421660a085015260c0840181905284815260078a01909252902081518154829060ff1916600183600581111561082a5761082a612c42565b0217905550602082015160018201906108439082613091565b506040828101516002830180546060860151608087015160a08801516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909301516003909201805467ffffffffffffffff1916928416929092179091558301516108e8911685613164565b82516040519195506108f991613035565b60408051918290038220908401516001600160401b031682529082907f9d47fef9da077661546e646d61830bfcbda90506c2e5eed38195e82c4eb1cbdf9060200160405180910390a350508061094e90613177565b9050610674565b50600483018190555f61097361096a86611085565b6040015161119b565b90505f61097f87611328565b90505f6002826040516109929190613035565b602060405180830381855afa1580156109ad573d5f803e3d5ffd5b5050506040513d601f19601f820116820180604052508101906109d09190612e28565b90508281146109fc57604051631872fc8d60e01b81526004810182905260248101849052604401610499565b5050506009909201805460ff1916600117905550505050565b610a1e81611561565b505050565b5f610a2d82610e4f565b6080015192915050565b610a3f61189f565b610a485f6118fa565b565b610a5261189f565b610a5b8161196a565b5050565b5f610a6861189f565b610a728383611c4e565b90505b92915050565b5f8051602061370d8339815191525f80610aa0610a9785611085565b604001516121a1565b9150915080610ac657604051632d07135360e01b81528115156004820152602401610499565b5f82815260068401602052604090208054610ae090612dd0565b90505f03610b045760405163089938b360e11b815260048101839052602401610499565b60015f83815260078501602052604090205460ff166005811115610b2a57610b2a612c42565b14610b5d575f8281526007840160205260409081902054905163170cc93360e21b81526104999160ff1690600401612e08565b5f8281526006840160205260408120610b7591612a75565b5f828152600784016020908152604091829020805460ff1916600290811782550180546001600160401b0342818116600160c01b026001600160c01b0390931692909217928390558451600160801b9093041682529181019190915283917ff8fd1c90fb9cfa2ca2358fdf5806b086ad43315d92b221c929efc7f105ce7568910160405180910390a250505050565b5f8181527fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb066020526040902080545f8051602061370d8339815191529190610c4b90612dd0565b90505f03610c6f5760405163089938b360e11b815260048101839052602401610499565b60015f83815260078301602052604090205460ff166005811115610c9557610c95612c42565b14610cc8575f8281526007820160205260409081902054905163170cc93360e21b81526104999160ff1690600401612e08565b5f82815260068201602052604090819020905163ee5b48eb60e01b81526005600160991b019163ee5b48eb91610d019190600401613199565b6020604051808303815f875af1158015610d1d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a1e9190612e28565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f81158015610d855750825b90505f826001600160401b03166001148015610da05750303b155b905081158015610dae575080155b15610dcc5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315610df657845460ff60401b1916600160401b1785555b610e00878761235d565b8315610e4657845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b610e57612aac565b5f8281525f8051602061372d833981519152602052604090819020815160e0810190925280545f8051602061370d833981519152929190829060ff166005811115610ea457610ea4612c42565b6005811115610eb557610eb5612c42565b8152602001600182018054610ec990612dd0565b80601f0160208091040260200160405190810160405280929190818152602001828054610ef590612dd0565b8015610f405780601f10610f1757610100808354040283529160200191610f40565b820191905f5260205f20905b815481529060010190602001808311610f2357829003601f168201915b505050918352505060028201546001600160401b038082166020840152600160401b820481166040840152600160801b820481166060840152600160c01b9091048116608083015260039092015490911660a0909101529392505050565b610fa661189f565b6001600160a01b038116610fcf57604051631e4fbdf760e01b81525f6004820152602401610499565b610fd8816118fa565b50565b6040515f905f8051602061370d833981519152907fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb089061101e9086908690613223565b90815260200160405180910390205491505092915050565b604080515f6020820152600360e01b602282015260268101949094526001600160c01b031960c093841b811660468601529190921b16604e830152805180830360360181526056909201905290565b60408051606080820183525f8083526020830152918101919091526040516306f8253560e41b815263ffffffff831660048201525f9081906005600160991b0190636f825350906024015f60405180830381865afa1580156110e9573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526111109190810190613241565b915091508061113257604051636b2f19e960e01b815260040160405180910390fd5b815115611158578151604051636ba589a560e01b81526004810191909152602401610499565b60208201516001600160a01b031615611194576020820151604051624de75d60e31b81526001600160a01b039091166004820152602401610499565b5092915050565b5f81516026146111d057815160405163cc92daa160e01b815263ffffffff909116600482015260266024820152604401610499565b5f805b600281101561121f576111e7816001613313565b6111f2906008613326565b61ffff1684828151811061120857611208612e84565b016020015160f81c901b91909117906001016111d3565b5061ffff8116156112495760405163407b587360e01b815261ffff82166004820152602401610499565b5f805b60048110156112a457611260816003613313565b61126b906008613326565b63ffffffff168561127d836002613164565b8151811061128d5761128d612e84565b016020015160f81c901b919091179060010161124c565b5063ffffffff8116156112ca57604051635b60892f60e01b815260040160405180910390fd5b5f805b602081101561131f576112e181601f613313565b6112ec906008613326565b866112f8836006613164565b8151811061130857611308612e84565b016020015160f81c901b91909117906001016112cd565b50949350505050565b60605f8083356020850135601461134487870160408901612d43565b6113516060890189612e3f565b60405160f09790971b6001600160f01b0319166020880152602287019590955250604285019290925260e090811b6001600160e01b0319908116606286015260609290921b6bffffffffffffffffffffffff191660668501529190911b16607a820152607e0160405160208183030381529060405290505f5b6113d76060850185612e3f565b9050811015611194576113ed6060850185612e3f565b828181106113fd576113fd612e84565b905060200281019061140f9190612e98565b61141d90602081019061333d565b905060301461143f5760405163180ffa0d60e01b815260040160405180910390fd5b8161144d6060860186612e3f565b8381811061145d5761145d612e84565b905060200281019061146f9190612e98565b611479908061333d565b90506114886060870187612e3f565b8481811061149857611498612e84565b90506020028101906114aa9190612e98565b6114b4908061333d565b6114c16060890189612e3f565b868181106114d1576114d1612e84565b90506020028101906114e39190612e98565b6114f190602081019061333d565b6114fe60608b018b612e3f565b8881811061150e5761150e612e84565b90506020028101906115209190612e98565b61153190606081019060400161337f565b6040516020016115479796959493929190613398565b60408051601f1981840301815291905291506001016113ca565b5f61156a612aac565b5f8051602061370d8339815191525f80611586610a9787611085565b9150915080156115ad57604051632d07135360e01b81528115156004820152602401610499565b5f828152600784016020526040808220815160e081019092528054829060ff1660058111156115de576115de612c42565b60058111156115ef576115ef612c42565b815260200160018201805461160390612dd0565b80601f016020809104026020016040519081016040528092919081815260200182805461162f90612dd0565b801561167a5780601f106116515761010080835404028352916020019161167a565b820191905f5260205f20905b81548152906001019060200180831161165d57829003601f168201915b505050918352505060028201546001600160401b038082166020840152600160401b820481166040840152600160801b820481166060840152600160c01b909104811660808301526003928301541660a090910152909150815160058111156116e5576116e5612c42565b14158015611706575060018151600581111561170357611703612c42565b14155b1561172757805160405163170cc93360e21b81526104999190600401612e08565b60038151600581111561173c5761173c612c42565b0361174a576004815261174f565b600581525b8360080181602001516040516117659190613035565b90815260408051602092819003830190205f908190558581526007870190925290208151815483929190829060ff191660018360058111156117a9576117a9612c42565b0217905550602082015160018201906117c29082613091565b5060408201516002820180546060850151608086015160a08701516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909201516003909101805467ffffffffffffffff1916919092161790558051600581111561186857611868612c42565b60405184907f1c08e59656f1a18dc2da76826cdc52805c43e897a17c50faefb8ab3c1526cc16905f90a39196919550909350505050565b336118d17f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b6001600160a01b031614610a485760405163118cdaa760e01b8152336004820152602401610499565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b611972612aac565b5f8281525f8051602061372d8339815191526020526040808220815160e0810190925280545f8051602061370d83398151915293929190829060ff1660058111156119bf576119bf612c42565b60058111156119d0576119d0612c42565b81526020016001820180546119e490612dd0565b80601f0160208091040260200160405190810160405280929190818152602001828054611a1090612dd0565b8015611a5b5780601f10611a3257610100808354040283529160200191611a5b565b820191905f5260205f20905b815481529060010190602001808311611a3e57829003601f168201915b50505091835250506002828101546001600160401b038082166020850152600160401b820481166040850152600160801b820481166060850152600160c01b9091048116608084015260039093015490921660a09091015290915081516005811115611ac957611ac9612c42565b14611afc575f8481526007830160205260409081902054905163170cc93360e21b81526104999160ff1690600401612e08565b60038152426001600160401b031660c08201525f84815260078301602052604090208151815483929190829060ff19166001836005811115611b4057611b40612c42565b021790555060208201516001820190611b599082613091565b5060408201516002820180546060850151608086015160a08701516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909201516003909101805467ffffffffffffffff1916919092161790555f611bf78582612377565b6080840151604080516001600160401b03909216825242602083015291935083925087917f13d58394cf269d48bcf927959a29a5ffee7c9924dafff8927ecdf3c48ffa7c67910160405180910390a3509392505050565b7fe92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb09545f9060ff16611c9257604051637fab81e560e01b815260040160405180910390fd5b5f8051602061370d83398151915242611cb1606086016040870161337f565b6001600160401b0316111580611ceb5750611ccf6202a30042613164565b611cdf606086016040870161337f565b6001600160401b031610155b15611d2557611d00606085016040860161337f565b604051635879da1360e11b81526001600160401b039091166004820152602401610499565b6030611d34602086018661333d565b905014611d6657611d48602085018561333d565b6040516326475b2f60e11b8152610499925060040190815260200190565b611d70848061333d565b90505f03611d9d57611d82848061333d565b604051633e08a12560e11b8152600401610499929190613401565b5f60088201611dac868061333d565b604051611dba929190613223565b90815260200160405180910390205414611df357611dd8848061333d565b60405163a41f772f60e01b8152600401610499929190613401565b611dfd835f6124ce565b6040805160e08101909152815481525f908190611f099060208101611e22898061333d565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250505090825250602090810190611e6a908a018a61333d565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250505090825250602001611eb360608a0160408b0161337f565b6001600160401b03168152602001611ece60608a018a61342f565b611ed790613443565b8152602001611ee960808a018a61342f565b611ef290613443565b8152602001876001600160401b03168152506126a8565b5f82815260068601602052604090209193509150611f278282613091565b508160088401611f37888061333d565b604051611f45929190613223565b9081526040519081900360200181209190915563ee5b48eb60e01b81525f906005600160991b019063ee5b48eb90611f81908590600401612e16565b6020604051808303815f875af1158015611f9d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fc19190612e28565b6040805160e081019091529091508060018152602001611fe1898061333d565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201829052509385525050506001600160401b0389166020808401829052604080850184905260608501929092526080840183905260a0909301829052868252600788019092522081518154829060ff1916600183600581111561207057612070612c42565b0217905550602082015160018201906120899082613091565b5060408201516002820180546060850151608086015160a08701516001600160401b039586166001600160801b031990941693909317600160401b92861692909202919091176001600160801b0316600160801b918516919091026001600160c01b031617600160c01b9184169190910217905560c0909201516003909101805467ffffffffffffffff19169190921617905580612127888061333d565b604051612135929190613223565b6040518091039020847fb77297e3befc691bfc864a81e241f83e2ef722b6e7becaa2ecec250c6d52b430898b6040016020810190612173919061337f565b604080516001600160401b0393841681529290911660208301520160405180910390a4509095945050505050565b5f8082516027146121d757825160405163cc92daa160e01b815263ffffffff909116600482015260276024820152604401610499565b5f805b6002811015612226576121ee816001613313565b6121f9906008613326565b61ffff1685828151811061220f5761220f612e84565b016020015160f81c901b91909117906001016121da565b5061ffff8116156122505760405163407b587360e01b815261ffff82166004820152602401610499565b5f805b60048110156122ab57612267816003613313565b612272906008613326565b63ffffffff1686612284836002613164565b8151811061229457612294612e84565b016020015160f81c901b9190911790600101612253565b5063ffffffff81166002146122d357604051635b60892f60e01b815260040160405180910390fd5b5f805b6020811015612328576122ea81601f613313565b6122f5906008613326565b87612301836006613164565b8151811061231157612311612e84565b016020015160f81c901b91909117906001016122d6565b505f8660268151811061233d5761233d612e84565b016020015191976001600160f81b03199092161515965090945050505050565b612365612895565b61236e826128de565b610a5b816128f7565b5f8281525f8051602061372d833981519152602052604081206002015481905f8051602061370d83398151915290600160801b90046001600160401b03166123bf85826124ce565b5f6123c987612908565b5f8881526007850160205260408120600201805467ffffffffffffffff60801b1916600160801b6001600160401b038b16021790559091506005600160991b0163ee5b48eb6124198a858b611036565b6040518263ffffffff1660e01b81526004016124359190612e16565b6020604051808303815f875af1158015612451573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124759190612e28565b604080516001600160401b038a811682526020820184905282519394508516928b927f07de5ff35a674a8005e661f3333c907ca6333462808762d19dc7b3abb1a8c1df928290030190a3909450925050505b9250929050565b5f8051602061370d8339815191525f6001600160401b038084169085161115612502576124fb838561350a565b905061250f565b61250c848461350a565b90505b6040805160808101825260028401548082526003850154602083015260048501549282019290925260058401546001600160401b031660608201524291158061257157506001840154815161256d916001600160401b031690613164565b8210155b15612597576001600160401b0383166060820152818152604081015160208201526125b6565b82816060018181516125a9919061352a565b6001600160401b03169052505b60608101516125c690606461354a565b602082015160018601546001600160401b0392909216916125f19190600160401b900460ff16613326565b101561262157606081015160405163dfae880160e01b81526001600160401b039091166004820152602401610499565b856001600160401b03168160400181815161263c9190613164565b9052506040810180516001600160401b038716919061265c908390613313565b905250805160028501556020810151600385015560408101516004850155606001516005909301805467ffffffffffffffff19166001600160401b039094169390931790925550505050565b5f60608260400151516030146126d15760405163180ffa0d60e01b815260040160405180910390fd5b82516020808501518051604080880151606089015160808a01518051908701515193515f98612712988a986001989297929690959094909390929101613575565b60405160208183030381529060405290505f5b846080015160200151518110156127845781856080015160200151828151811061275157612751612e84565b602002602001015160405160200161276a92919061362f565b60408051601f198184030181529190529150600101612725565b5060a08401518051602091820151516040516127a4938593929101613665565b60405160208183030381529060405290505f5b8460a00151602001515181101561281657818560a001516020015182815181106127e3576127e3612e84565b60200260200101516040516020016127fc92919061362f565b60408051601f1981840301815291905291506001016127b7565b5060c084015160405161282d9183916020016136a0565b604051602081830303815290604052905060028160405161284e9190613035565b602060405180830381855afa158015612869573d5f803e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061288c9190612e28565b94909350915050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16610a4857604051631afcd79f60e31b815260040160405180910390fd5b6128e6612895565b6128ee61297d565b610fd881612985565b6128ff612895565b610fd881612a6d565b5f8181525f8051602061372d8339815191526020526040812060020180545f8051602061370d833981519152919060089061295290600160401b90046001600160401b03166136d1565b91906101000a8154816001600160401b0302191690836001600160401b031602179055915050919050565b610a48612895565b61298d612895565b80355f8051602061370d83398151915290815560146129b260608401604085016136ec565b60ff1611806129d157506129cc60608301604084016136ec565b60ff16155b15612a05576129e660608301604084016136ec565b604051634a59bbff60e11b815260ff9091166004820152602401610499565b612a1560608301604084016136ec565b60018201805460ff92909216600160401b0260ff60401b19909216919091179055612a46604083016020840161337f565b600191909101805467ffffffffffffffff19166001600160401b0390921691909117905550565b610fa6612895565b508054612a8190612dd0565b5f825580601f10612a90575050565b601f0160209004905f5260205f2090810190610fd89190612ae9565b6040805160e08101909152805f81526060602082018190525f604083018190529082018190526080820181905260a0820181905260c09091015290565b5b80821115612afd575f8155600101612aea565b5090565b5f60208284031215612b11575f80fd5b5035919050565b803563ffffffff81168114612b2b575f80fd5b919050565b5f8060408385031215612b41575f80fd5b82356001600160401b03811115612b56575f80fd5b830160808186031215612b67575f80fd5b9150612b7560208401612b18565b90509250929050565b5f60208284031215612b8e575f80fd5b610a7282612b18565b80356001600160401b0381168114612b2b575f80fd5b5f8060408385031215612bbe575f80fd5b82356001600160401b03811115612bd3575f80fd5b830160a08186031215612be4575f80fd5b9150612b7560208401612b97565b6001600160a01b0381168114610fd8575f80fd5b5f808284036080811215612c18575f80fd5b6060811215612c25575f80fd5b508291506060830135612c3781612bf2565b809150509250929050565b634e487b7160e01b5f52602160045260245ffd5b60068110612c7257634e487b7160e01b5f52602160045260245ffd5b9052565b5f5b83811015612c90578181015183820152602001612c78565b50505f910152565b5f8151808452612caf816020860160208601612c76565b601f01601f19169290920160200192915050565b60208152612cd5602082018351612c56565b5f602083015160e06040840152612cf0610100840182612c98565b905060408401516001600160401b0380821660608601528060608701511660808601528060808701511660a08601528060a08701511660c08601528060c08701511660e086015250508091505092915050565b5f60208284031215612d53575f80fd5b8135612d5e81612bf2565b9392505050565b5f8060208385031215612d76575f80fd5b82356001600160401b0380821115612d8c575f80fd5b818501915085601f830112612d9f575f80fd5b813581811115612dad575f80fd5b866020828501011115612dbe575f80fd5b60209290920196919550909350505050565b600181811c90821680612de457607f821691505b602082108103612e0257634e487b7160e01b5f52602260045260245ffd5b50919050565b60208101610a758284612c56565b602081525f610a726020830184612c98565b5f60208284031215612e38575f80fd5b5051919050565b5f808335601e19843603018112612e54575f80fd5b8301803591506001600160401b03821115612e6d575f80fd5b6020019150600581901b36038213156124c7575f80fd5b634e487b7160e01b5f52603260045260245ffd5b5f8235605e19833603018112612eac575f80fd5b9190910192915050565b634e487b7160e01b5f52604160045260245ffd5b604051606081016001600160401b0381118282101715612eec57612eec612eb6565b60405290565b604080519081016001600160401b0381118282101715612eec57612eec612eb6565b604051601f8201601f191681016001600160401b0381118282101715612f3c57612f3c612eb6565b604052919050565b5f6001600160401b03821115612f5c57612f5c612eb6565b50601f01601f191660200190565b5f82601f830112612f79575f80fd5b8135612f8c612f8782612f44565b612f14565b818152846020838601011115612fa0575f80fd5b816020850160208301375f918101602001919091529392505050565b5f60608236031215612fcc575f80fd5b612fd4612eca565b82356001600160401b0380821115612fea575f80fd5b612ff636838701612f6a565b8352602085013591508082111561300b575f80fd5b5061301836828601612f6a565b60208301525061302a60408401612b97565b604082015292915050565b5f8251612eac818460208701612c76565b601f821115610a1e57805f5260205f20601f840160051c8101602085101561306b5750805b601f840160051c820191505b8181101561308a575f8155600101613077565b5050505050565b81516001600160401b038111156130aa576130aa612eb6565b6130be816130b88454612dd0565b84613046565b602080601f8311600181146130f1575f84156130da5750858301515b5f19600386901b1c1916600185901b178555613148565b5f85815260208120601f198616915b8281101561311f57888601518255948401946001909101908401613100565b508582101561313c57878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610a7557610a75613150565b5f63ffffffff80831681810361318f5761318f613150565b6001019392505050565b5f60208083525f84546131ab81612dd0565b806020870152604060018084165f81146131cc57600181146131e857613215565b60ff19851660408a0152604084151560051b8a01019550613215565b895f5260205f205f5b8581101561320c5781548b82018601529083019088016131f1565b8a016040019650505b509398975050505050505050565b818382375f9101908152919050565b80518015158114612b2b575f80fd5b5f8060408385031215613252575f80fd5b82516001600160401b0380821115613268575f80fd5b908401906060828703121561327b575f80fd5b613283612eca565b8251815260208084015161329681612bf2565b828201526040840151838111156132ab575f80fd5b80850194505087601f8501126132bf575f80fd5b835192506132cf612f8784612f44565b83815288828587010111156132e2575f80fd5b6132f184838301848801612c76565b80604084015250819550613306818801613232565b9450505050509250929050565b81810381811115610a7557610a75613150565b8082028115828204841417610a7557610a75613150565b5f808335601e19843603018112613352575f80fd5b8301803591506001600160401b0382111561336b575f80fd5b6020019150368190038213156124c7575f80fd5b5f6020828403121561338f575f80fd5b610a7282612b97565b5f88516133a9818460208d01612c76565b60e089901b6001600160e01b031916908301908152868860048301378681019050600481015f8152858782375060c09390931b6001600160c01b0319166004939094019283019390935250600c019695505050505050565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b5f8235603e19833603018112612eac575f80fd5b5f60408236031215613453575f80fd5b61345b612ef2565b61346483612b18565b81526020808401356001600160401b0380821115613480575f80fd5b9085019036601f830112613492575f80fd5b8135818111156134a4576134a4612eb6565b8060051b91506134b5848301612f14565b81815291830184019184810190368411156134ce575f80fd5b938501935b838510156134f857843592506134e883612bf2565b82825293850193908501906134d3565b94860194909452509295945050505050565b6001600160401b0382811682821603908082111561119457611194613150565b6001600160401b0381811683821601908082111561119457611194613150565b6001600160401b0381811683821602808216919082811461356d5761356d613150565b505092915050565b61ffff60f01b8a60f01b1681525f63ffffffff60e01b808b60e01b166002840152896006840152808960e01b1660268401525086516135bb81602a850160208b01612c76565b8651908301906135d281602a840160208b01612c76565b60c087901b6001600160c01b031916602a9290910191820152613604603282018660e01b6001600160e01b0319169052565b61361d603682018560e01b6001600160e01b0319169052565b603a019b9a5050505050505050505050565b5f8351613640818460208801612c76565b60609390931b6bffffffffffffffffffffffff19169190920190815260140192915050565b5f8451613676818460208901612c76565b6001600160e01b031960e095861b8116919093019081529290931b16600482015260080192915050565b5f83516136b1818460208801612c76565b60c09390931b6001600160c01b0319169190920190815260080192915050565b5f6001600160401b0380831681810361318f5761318f613150565b5f602082840312156136fc575f80fd5b813560ff81168114612d5e575f80fdfee92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb00e92546d698950ddd38910d2e15ed1d923cd0a7b3dde9e2a6a3f380565559cb07a164736f6c6343000819000a diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index 05f61f80b..fdebb1b57 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -12,6 +12,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/contract" "github.com/ava-labs/avalanche-cli/pkg/evm" "github.com/ava-labs/avalanche-cli/pkg/models" + "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/sdk/interchain" "github.com/ava-labs/avalanchego/ids" avagoconstants "github.com/ava-labs/avalanchego/utils/constants" @@ -277,3 +278,132 @@ func SetupPoA( } return nil } + +// step 1 of flow for adding a new validator +func PoAValidatorManagerInitializeValidatorRegistration( + rpcURL string, + managerAddress common.Address, + managerOwnerPrivateKey string, + nodeID ids.NodeID, + blsPublicKey []byte, + expiry uint64, + balanceOwners warpMessage.PChainOwner, + disableOwners warpMessage.PChainOwner, + weight uint64, +) (*types.Transaction, *types.Receipt, error) { + type PChainOwner struct { + Threshold uint32 + Addresses []common.Address + } + type ValidatorRegistrationInput struct { + NodeID []byte + BlsPublicKey []byte + RegistrationExpiry uint64 + RemainingBalanceOwner PChainOwner + DisableOwner PChainOwner + } + balanceOwnersAux := PChainOwner{ + Threshold: balanceOwners.Threshold, + Addresses: utils.Map(balanceOwners.Addresses, func(addr ids.ShortID) common.Address { + return common.BytesToAddress(addr[:]) + }), + } + disableOwnersAux := PChainOwner{ + Threshold: disableOwners.Threshold, + Addresses: utils.Map(disableOwners.Addresses, func(addr ids.ShortID) common.Address { + return common.BytesToAddress(addr[:]) + }), + } + validatorRegistrationInput := ValidatorRegistrationInput{ + NodeID: nodeID[:], + BlsPublicKey: blsPublicKey, + RegistrationExpiry: expiry, + RemainingBalanceOwner: balanceOwnersAux, + DisableOwner: disableOwnersAux, + } + return contract.TxToMethod( + rpcURL, + managerOwnerPrivateKey, + managerAddress, + big.NewInt(0), + "initializeValidatorRegistration((bytes,bytes,uint64,(uint32,[address]),(uint32,[address])),uint64)", + validatorRegistrationInput, + weight, + ) +} + +func PoaValidatorManagerGetSubnetValidatorRegistrationMessage( + network models.Network, + aggregatorLogger logging.Logger, + aggregatorLogLevel logging.Level, + aggregatorQuorumPercentage uint64, + subnetID ids.ID, + managerAddress common.Address, + nodeID ids.NodeID, + blsPublicKey [48]byte, + expiry uint64, + balanceOwners warpMessage.PChainOwner, + disableOwners warpMessage.PChainOwner, + weight uint64, +) (*warp.Message, error) { + addressedCallPayload, err := warpMessage.NewRegisterSubnetValidator( + subnetID, + nodeID, + blsPublicKey, + expiry, + balanceOwners, + disableOwners, + weight, + ) + if err != nil { + return nil, err + } + registerSubnetValidatorAddressedCall, err := warpPayload.NewAddressedCall( + managerAddress.Bytes(), + addressedCallPayload.Bytes(), + ) + if err != nil { + return nil, err + } + registerSubnetValidatorUnsignedMessage, err := warp.NewUnsignedMessage( + network.ID, + subnetID, + registerSubnetValidatorAddressedCall.Bytes(), + ) + if err != nil { + return nil, err + } + fmt.Println("check", registerSubnetValidatorUnsignedMessage.ID()) + signatureAggregator, err := interchain.NewSignatureAggregator( + network, + aggregatorLogger, + aggregatorLogLevel, + subnetID, + aggregatorQuorumPercentage, + ) + if err != nil { + return nil, err + } + return signatureAggregator.Sign(registerSubnetValidatorUnsignedMessage, nil) +} + +func GetRegisteredValidator( + rpcURL string, + managerAddress common.Address, + nodeID ids.NodeID, +) (ids.ID, error) { + out, err := contract.CallToMethod( + rpcURL, + managerAddress, + "registeredValidators(bytes)->(bytes32)", + nodeID[:], + ) + if err != nil { + return ids.Empty, err + } + validatorID, b := out[0].([32]byte) + if !b { + return ids.Empty, fmt.Errorf("error at registeredValidators call, expected [32]byte, got %T", out[0]) + } + return validatorID, nil +} From 74b9a7cb14a39eea54961f984149d44fe00d2396 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Wed, 9 Oct 2024 21:20:46 -0300 Subject: [PATCH 15/57] separate between local network and local cluster --- cmd/backendcmd/spawn_server.go | 15 +++++-- cmd/blockchaincmd/deploy.go | 24 +++++++----- cmd/networkcmd/clean.go | 2 +- cmd/networkcmd/start.go | 6 ++- cmd/networkcmd/stop.go | 2 +- cmd/nodecmd/local.go | 67 ++++++++++++++++++++++++++++++-- pkg/application/app.go | 4 +- pkg/binutils/constants.go | 11 ++++-- pkg/binutils/processes.go | 71 +++++++++++++++++++++++++--------- pkg/constants/constants.go | 5 ++- pkg/subnet/local.go | 29 ++++++++++---- pkg/ux/spinner.go | 1 + 12 files changed, 186 insertions(+), 51 deletions(-) diff --git a/cmd/backendcmd/spawn_server.go b/cmd/backendcmd/spawn_server.go index f01ee6960..c44b2ebf2 100644 --- a/cmd/backendcmd/spawn_server.go +++ b/cmd/backendcmd/spawn_server.go @@ -13,12 +13,16 @@ import ( "github.com/spf13/cobra" ) -var app *application.Avalanche +var ( + app *application.Avalanche + serverPort string + gatewayPort string +) // backendCmd is the command to run the backend gRPC process func NewCmd(injectedApp *application.Avalanche) *cobra.Command { app = injectedApp - return &cobra.Command{ + cmd := &cobra.Command{ Use: constants.BackendCmd, Short: "Run the backend server", Long: "This tool requires a backend process to run; this command starts it", @@ -26,10 +30,15 @@ func NewCmd(injectedApp *application.Avalanche) *cobra.Command { Args: cobrautils.ExactArgs(0), Hidden: true, } + cmd.Flags().StringVar(&serverPort, "server-port", binutils.LocalNetworkGRPCServerPort, "server port to use") + cmd.Flags().StringVar(&gatewayPort, "gateway-port", binutils.LocalNetworkGRPCGatewayPort, "gateway port to use") + return cmd } func startBackend(_ *cobra.Command, _ []string) error { - s, err := binutils.NewGRPCServer(app.GetSnapshotsDir()) + fmt.Println(serverPort) + fmt.Println(gatewayPort) + s, err := binutils.NewGRPCServer(serverPort, gatewayPort, app.GetSnapshotsDir()) if err != nil { return err } diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 78e19cf7a..71363a479 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -392,13 +392,6 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { } } - if sidecar.Sovereign && bootstrapValidatorsJSONFilePath == "" { - bootstrapValidators, err = promptBootstrapValidators(network) - if err != nil { - return err - } - } - ux.Logger.PrintToUser("Deploying %s to %s", chains, network.Name()) if network.Kind == models.Local { @@ -431,10 +424,16 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { } deployer := subnet.NewLocalDeployer(app, userProvidedAvagoVersion, avagoBinaryPath, vmBin) - deployInfo, err := deployer.DeployToLocalNetwork(chain, genesisPath, icmSpec, subnetIDStr) + deployInfo, err := deployer.DeployToLocalNetwork( + chain, + genesisPath, + icmSpec, + subnetIDStr, + constants.ServerRunFileLocalNetworkPrefix, + ) if err != nil { if deployer.BackendStartedHere() { - if innerErr := binutils.KillgRPCServerProcess(app); innerErr != nil { + if innerErr := binutils.KillgRPCServerProcess(app, constants.ServerRunFileLocalNetworkPrefix); innerErr != nil { app.Log.Warn("tried to kill the gRPC server process but it failed", zap.Error(innerErr)) } } @@ -457,6 +456,13 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { return PrintSubnetInfo(blockchainName, true) } + if sidecar.Sovereign && bootstrapValidatorsJSONFilePath == "" { + bootstrapValidators, err = promptBootstrapValidators(network) + if err != nil { + return err + } + } + // from here on we are assuming a public deploy if subnetOnly && subnetIDStr != "" { return errMutuallyExlusiveSubnetFlags diff --git a/cmd/networkcmd/clean.go b/cmd/networkcmd/clean.go index fbe556b4f..a196c28fb 100644 --- a/cmd/networkcmd/clean.go +++ b/cmd/networkcmd/clean.go @@ -51,7 +51,7 @@ func clean(*cobra.Command, []string) error { app.Log.Warn("failed resetting default snapshot", zap.Error(err)) } - if err := binutils.KillgRPCServerProcess(app); err != nil { + if err := binutils.KillgRPCServerProcess(app, constants.ServerRunFileLocalNetworkPrefix); err != nil { app.Log.Warn("failed killing server process", zap.Error(err)) } else { ux.Logger.PrintToUser("Process terminated.") diff --git a/cmd/networkcmd/start.go b/cmd/networkcmd/start.go index aca86c4a8..da8f56f16 100644 --- a/cmd/networkcmd/start.go +++ b/cmd/networkcmd/start.go @@ -68,7 +68,11 @@ func StartNetwork(*cobra.Command, []string) error { } sd := subnet.NewLocalDeployer(app, avagoVersion, avagoBinaryPath, "") - if err := sd.StartServer(); err != nil { + if err := sd.StartServer( + constants.ServerRunFileLocalNetworkPrefix, + binutils.LocalNetworkGRPCServerPort, + binutils.LocalNetworkGRPCGatewayPort, + ); err != nil { return err } diff --git a/cmd/networkcmd/stop.go b/cmd/networkcmd/stop.go index 69e23f33a..0975274aa 100644 --- a/cmd/networkcmd/stop.go +++ b/cmd/networkcmd/stop.go @@ -51,7 +51,7 @@ func StopNetwork(*cobra.Command, []string) error { } var err error - if err = binutils.KillgRPCServerProcess(app); err != nil { + if err = binutils.KillgRPCServerProcess(app, constants.ServerRunFileLocalNetworkPrefix); err != nil { app.Log.Warn("failed killing server process", zap.Error(err)) fmt.Println(err) } else { diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 75213fc44..fa89f5019 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -46,6 +46,8 @@ The node local command suite provides a collection of commands related to local cmd.AddCommand(newLocalStopCmd()) // node local destroy cmd.AddCommand(newLocalDestroyCmd()) + // node local track + cmd.AddCommand(newLocalTrackCmd()) return cmd } @@ -91,6 +93,16 @@ func newLocalStopCmd() *cobra.Command { } } +func newLocalTrackCmd() *cobra.Command { + return &cobra.Command{ + Use: "track [clusterName] [blockchainName]", + Short: "(ALPHA Warning) make the local node at the cluster to track given blockchain", + Long: "(ALPHA Warning) make the local node at the cluster to track given blockchain", + Args: cobra.ExactArgs(2), + RunE: localTrackSubnet, + } +} + func newLocalDestroyCmd() *cobra.Command { return &cobra.Command{ Use: "destroy [clusterName]", @@ -236,7 +248,11 @@ func localStartNode(_ *cobra.Command, args []string) error { } sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") - if err := sd.StartServer(); err != nil { + if err := sd.StartServer( + constants.ServerRunFileLocalClusterPrefix, + binutils.LocalClusterGRPCServerPort, + binutils.LocalClusterGRPCGatewayPort, + ); err != nil { return err } _, avalancheGoBinPath, err := sd.SetupLocalEnv() @@ -284,7 +300,7 @@ func localStartNode(_ *cobra.Command, args []string) error { } spinSession := ux.NewUserSpinner() spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...") - cli, err := binutils.NewGRPCClient() + cli, err := binutils.NewGRPCClientWithEndpoint(binutils.LocalClusterGRPCServerEndpoint) if err != nil { ux.SpinFailWithError(spinner, "", err) return err @@ -308,7 +324,7 @@ func localStartNode(_ *cobra.Command, args []string) error { return err } } - cli, err := binutils.NewGRPCClient() + cli, err := binutils.NewGRPCClientWithEndpoint(binutils.LocalClusterGRPCServerEndpoint) if err != nil { return err } @@ -344,7 +360,8 @@ func localStopNode(_ *cobra.Command, args []string) error { if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { return fmt.Errorf("local node %q is not found", clusterName) } - cli, err := binutils.NewGRPCClient( + cli, err := binutils.NewGRPCClientWithEndpoint( + binutils.LocalClusterGRPCServerEndpoint, binutils.WithAvoidRPCVersionCheck(true), binutils.WithDialTimeout(constants.FastGRPCDialTimeout), ) @@ -422,3 +439,45 @@ func checkClusterIsLocal(clusterName string) (bool, error) { clusterConf, ok := clustersConfig.Clusters[clusterName] return ok && clusterConf.Local, nil } + +func localTrackSubnet(_ *cobra.Command, args []string) error { + // todo: support only one local node and detect what cluster to stop + clusterName := args[0] + if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { + return fmt.Errorf("local node %q is not found", clusterName) + } + cli, err := binutils.NewGRPCClientWithEndpoint( + binutils.LocalClusterGRPCServerEndpoint, + binutils.WithAvoidRPCVersionCheck(true), + binutils.WithDialTimeout(constants.FastGRPCDialTimeout), + ) + if err != nil { + return err + } + + ctx, cancel := utils.GetANRContext() + defer cancel() + + if _, err := cli.Status(ctx); err != nil { + if server.IsServerError(err, server.ErrNotBootstrapped) { + ux.Logger.PrintToUser("avalanchego already stopped.") + return nil + } + return fmt.Errorf("failed to get avalanchego status: %w", err) + } + // save snapshot before stopping + if _, err := cli.SaveSnapshot( + ctx, + localClusterSnapshotName(clusterName), + true, // force + + ); err != nil { + return fmt.Errorf("failed to save state: %w", err) + } + + if _, err = cli.Stop(ctx); err != nil { + return fmt.Errorf("failed to stop avalanchego: %w", err) + } + ux.Logger.GreenCheckmarkToUser("avalanchego stopped. State saved for %s", clusterName) + return nil +} diff --git a/pkg/application/app.go b/pkg/application/app.go index d10f31884..22dc227c1 100644 --- a/pkg/application/app.go +++ b/pkg/application/app.go @@ -46,8 +46,8 @@ func (app *Avalanche) Setup(baseDir string, log logging.Logger, conf *config.Con app.Downloader = downloader } -func (app *Avalanche) GetRunFile() string { - return filepath.Join(app.GetRunDir(), constants.ServerRunFile) +func (app *Avalanche) GetRunFile(prefix string) string { + return filepath.Join(app.GetRunDir(), prefix+constants.ServerRunFile) } func (app *Avalanche) GetSnapshotsDir() string { diff --git a/pkg/binutils/constants.go b/pkg/binutils/constants.go index 8c8cdb4cd..9116a8d52 100644 --- a/pkg/binutils/constants.go +++ b/pkg/binutils/constants.go @@ -6,12 +6,17 @@ import "time" const ( gRPCClientLogLevel = "error" - gRPCServerPort = ":8097" - gRPCGatewayPort = ":8098" - gRPCServerEndpoint = "localhost" + gRPCServerPort gRPCDialTimeout = 10 * time.Second avalanchegoBinPrefix = "avalanchego-" subnetEVMBinPrefix = "subnet-evm-" maxCopy = 2147483648 // 2 GB + + LocalNetworkGRPCServerPort = ":8097" + LocalNetworkGRPCGatewayPort = ":8098" + LocalNetworkGRPCServerEndpoint = "localhost" + LocalNetworkGRPCServerPort + + LocalClusterGRPCServerPort = ":8090" + LocalClusterGRPCGatewayPort = ":8091" + LocalClusterGRPCServerEndpoint = "localhost" + LocalClusterGRPCServerPort ) diff --git a/pkg/binutils/processes.go b/pkg/binutils/processes.go index 71ee77e4e..7dc4c209e 100644 --- a/pkg/binutils/processes.go +++ b/pkg/binutils/processes.go @@ -35,7 +35,7 @@ var ErrGRPCTimeout = errors.New("timed out trying to contact backend controller, type ProcessChecker interface { // IsServerProcessRunning returns true if the gRPC server is running, // or false if not - IsServerProcessRunning(app *application.Avalanche) (bool, error) + IsServerProcessRunning(app *application.Avalanche, prefix string) (bool, error) } type realProcessRunner struct{} @@ -72,6 +72,13 @@ func WithDialTimeout(dialTimeout time.Duration) GRPCClientOpOption { // NewGRPCClient hides away the details (params) of creating a gRPC server connection func NewGRPCClient(opts ...GRPCClientOpOption) (client.Client, error) { + return NewGRPCClientWithEndpoint(LocalNetworkGRPCServerEndpoint, opts...) +} + +func NewGRPCClientWithEndpoint( + serverEndpoint string, + opts ...GRPCClientOpOption, +) (client.Client, error) { op := GRPCClientOp{ dialTimeout: gRPCDialTimeout, } @@ -89,7 +96,7 @@ func NewGRPCClient(opts ...GRPCClientOpOption) (client.Client, error) { return nil, err } client, err := client.New(client.Config{ - Endpoint: gRPCServerEndpoint, + Endpoint: serverEndpoint, DialTimeout: op.dialTimeout, }, log) if errors.Is(err, context.DeadlineExceeded) { @@ -116,7 +123,11 @@ func NewGRPCClient(opts ...GRPCClientOpOption) (client.Client, error) { } // NewGRPCServer hides away the details (params) of creating a gRPC server -func NewGRPCServer(snapshotsDir string) (server.Server, error) { +func NewGRPCServer( + serverPort string, + gatewayPort string, + snapshotsDir string, +) (server.Server, error) { logFactory := logging.NewFactory(logging.Config{ DisplayLevel: logging.Info, LogLevel: logging.Off, @@ -126,8 +137,8 @@ func NewGRPCServer(snapshotsDir string) (server.Server, error) { return nil, err } return server.New(server.Config{ - Port: gRPCServerPort, - GwPort: gRPCGatewayPort, + Port: serverPort, + GwPort: gatewayPort, DialTimeout: gRPCDialTimeout, SnapshotsDir: snapshotsDir, RedirectNodesOutput: false, @@ -137,8 +148,11 @@ func NewGRPCServer(snapshotsDir string) (server.Server, error) { // IsServerProcessRunning returns true if the gRPC server is running, // or false if not -func (*realProcessRunner) IsServerProcessRunning(app *application.Avalanche) (bool, error) { - pid, err := GetServerPID(app) +func (*realProcessRunner) IsServerProcessRunning( + app *application.Avalanche, + prefix string, +) (bool, error) { + pid, err := GetServerPID(app, prefix) if err != nil { if !errors.Is(err, os.ErrNotExist) { return false, err @@ -167,9 +181,12 @@ type runFile struct { GRPCserverFileName string `json:"gRPCserverFileName"` } -func GetBackendLogFile(app *application.Avalanche) (string, error) { +func GetBackendLogFile( + app *application.Avalanche, + prefix string, +) (string, error) { var rf runFile - serverRunFilePath := app.GetRunFile() + serverRunFilePath := app.GetRunFile(prefix) run, err := os.ReadFile(serverRunFilePath) if err != nil { return "", fmt.Errorf("failed reading process info file at %s: %w", serverRunFilePath, err) @@ -177,13 +194,15 @@ func GetBackendLogFile(app *application.Avalanche) (string, error) { if err := json.Unmarshal(run, &rf); err != nil { return "", fmt.Errorf("failed unmarshalling server run file at %s: %w", serverRunFilePath, err) } - return rf.GRPCserverFileName, nil } -func GetServerPID(app *application.Avalanche) (int, error) { +func GetServerPID( + app *application.Avalanche, + prefix string, +) (int, error) { var rf runFile - serverRunFilePath := app.GetRunFile() + serverRunFilePath := app.GetRunFile(prefix) run, err := os.ReadFile(serverRunFilePath) if err != nil { return 0, fmt.Errorf("failed reading process info file at %s: %w", serverRunFilePath, err) @@ -200,13 +219,24 @@ func GetServerPID(app *application.Avalanche) (int, error) { // StartServerProcess starts the gRPC server as a reentrant process of this binary // it just executes `avalanche-cli backend start` -func StartServerProcess(app *application.Avalanche) error { +func StartServerProcess( + app *application.Avalanche, + prefix string, + serverPort string, + gatewayPort string, +) error { thisBin := reexec.Self() - args := []string{constants.BackendCmd} + args := []string{ + constants.BackendCmd, + "--server-port", + serverPort, + "--gateway-port", + gatewayPort, + } cmd := exec.Command(thisBin, args...) - outputDirPrefix := path.Join(app.GetRunDir(), "server") + outputDirPrefix := path.Join(app.GetRunDir(), prefix+"server") outputDir, err := anrutils.MkDirWithTimestamp(outputDirPrefix) if err != nil { return err @@ -236,13 +266,16 @@ func StartServerProcess(app *application.Avalanche) error { return err } - if err := os.WriteFile(app.GetRunFile(), rfBytes, perms.ReadWrite); err != nil { + if err := os.WriteFile(app.GetRunFile(prefix), rfBytes, perms.ReadWrite); err != nil { app.Log.Warn("could not write gRPC process info to file", zap.Error(err)) } return nil } -func KillgRPCServerProcess(app *application.Avalanche) error { +func KillgRPCServerProcess( + app *application.Avalanche, + prefix string, +) error { cli, err := NewGRPCClient( WithAvoidRPCVersionCheck(true), WithDialTimeout(constants.FastGRPCDialTimeout), @@ -262,7 +295,7 @@ func KillgRPCServerProcess(app *application.Avalanche) error { } } - pid, err := GetServerPID(app) + pid, err := GetServerPID(app, prefix) if err != nil { return fmt.Errorf("failed getting PID from run file: %w", err) } @@ -274,7 +307,7 @@ func KillgRPCServerProcess(app *application.Avalanche) error { return fmt.Errorf("failed killing process with pid %d: %w", pid, err) } - serverRunFilePath := app.GetRunFile() + serverRunFilePath := app.GetRunFile(prefix) if err := os.Remove(serverRunFilePath); err != nil { return fmt.Errorf("failed removing run file %s: %w", serverRunFilePath, err) } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 96bab6600..d4eaa9fb3 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -18,7 +18,10 @@ const ( BaseDirName = ".avalanche-cli" LogDir = "logs" - ServerRunFile = "gRPCserver.run" + ServerRunFile = "gRPCserver.run" + ServerRunFileLocalNetworkPrefix = "" + ServerRunFileLocalClusterPrefix = "localcluster_" + AvalancheCliBinDir = "bin" RunDir = "runs" ServicesDir = "services" diff --git a/pkg/subnet/local.go b/pkg/subnet/local.go index 0e420d3c1..d489c80fd 100644 --- a/pkg/subnet/local.go +++ b/pkg/subnet/local.go @@ -105,21 +105,30 @@ func (d *LocalDeployer) DeployToLocalNetwork( genesisPath string, icmSpec ICMSpec, subnetIDStr string, + prefix string, ) (*DeployInfo, error) { - if err := d.StartServer(); err != nil { + if err := d.StartServer( + constants.ServerRunFileLocalNetworkPrefix, + binutils.LocalNetworkGRPCServerPort, + binutils.LocalNetworkGRPCGatewayPort, + ); err != nil { return nil, err } - return d.doDeploy(blockchainName, genesisPath, icmSpec, subnetIDStr) + return d.doDeploy(blockchainName, genesisPath, icmSpec, subnetIDStr, prefix) } -func (d *LocalDeployer) StartServer() error { - isRunning, err := d.procChecker.IsServerProcessRunning(d.app) +func (d *LocalDeployer) StartServer( + prefix string, + serverPort string, + gatewayPort string, +) error { + isRunning, err := d.procChecker.IsServerProcessRunning(d.app, prefix) if err != nil { return fmt.Errorf("failed querying if server process is running: %w", err) } if !isRunning { d.app.Log.Debug("gRPC server is not running") - if err := binutils.StartServerProcess(d.app); err != nil { + if err := binutils.StartServerProcess(d.app, prefix, serverPort, gatewayPort); err != nil { return fmt.Errorf("failed starting gRPC server process: %w", err) } d.backendStartedHere = true @@ -153,13 +162,19 @@ func (d *LocalDeployer) BackendStartedHere() bool { // - deploy a new blockchain for the given VM ID, genesis, and available subnet ID // - waits completion of operation // - show status -func (d *LocalDeployer) doDeploy(blockchainName string, genesisPath string, icmSpec ICMSpec, subnetIDStr string) (*DeployInfo, error) { +func (d *LocalDeployer) doDeploy( + blockchainName string, + genesisPath string, + icmSpec ICMSpec, + subnetIDStr string, + prefix string, +) (*DeployInfo, error) { needsRestart, avalancheGoBinPath, err := d.SetupLocalEnv() if err != nil { return nil, err } - backendLogFile, err := binutils.GetBackendLogFile(d.app) + backendLogFile, err := binutils.GetBackendLogFile(d.app, prefix) var backendLogDir string if err == nil { // TODO should we do something if there _was_ an error? diff --git a/pkg/ux/spinner.go b/pkg/ux/spinner.go index c9cf17f33..5c5e28a34 100644 --- a/pkg/ux/spinner.go +++ b/pkg/ux/spinner.go @@ -66,6 +66,7 @@ func SpinFailWithError(s *ysmrr.Spinner, txt string, err error) { } func SpinComplete(s *ysmrr.Spinner) { + ansi.CursorShow() if s.IsComplete() { return } From 23b4e865e51604cfe3eaa2ec65f884fbb751db6c Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 10 Oct 2024 10:01:59 -0300 Subject: [PATCH 16/57] working --- cmd/blockchaincmd/add_validator.go | 2 +- cmd/blockchaincmd/deploy.go | 71 +++++++++++++++++- cmd/blockchaincmd/prompt_genesis_input.go | 2 +- cmd/blockchaincmd/prompt_owners.go | 7 +- cmd/contractcmd/init_poa_validator_manager.go | 5 ++ cmd/nodecmd/local.go | 75 +++++++++++++------ go.mod | 2 +- go.sum | 2 + pkg/contract/chain.go | 27 ++++--- pkg/evm/evm.go | 6 +- pkg/validatormanager/validatormanager.go | 6 +- sdk/interchain/signature-aggregator.go | 10 ++- 12 files changed, 168 insertions(+), 47 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index d6d92107f..26ea32ee9 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -218,7 +218,7 @@ func CallAddValidator( } if changeAddr == "" { - changeAddr, err = getKeyForChangeOwner("", network) + changeAddr, err = getKeyForChangeOwner(nodeIDStrFormat, "", network) if err != nil { return err } diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 71363a479..cd6b71618 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -3,6 +3,7 @@ package blockchaincmd import ( + "encoding/hex" "encoding/json" "errors" "fmt" @@ -11,6 +12,7 @@ import ( "strings" "time" + "github.com/ava-labs/avalanchego/api/info" "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" "github.com/ethereum/go-ethereum/common" @@ -72,6 +74,7 @@ var ( generateNodeID bool bootstrapValidatorsJSONFilePath string privateKeyFlags contract.PrivateKeyFlags + bootstrapEndpoints []string errMutuallyExlusiveControlKeys = errors.New("--control-keys and --same-control-key are mutually exclusive") ErrMutuallyExlusiveKeyLedger = errors.New("key source flags --key, --ledger/--ledger-addrs are mutually exclusive") @@ -126,6 +129,7 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`, cmd.Flags().StringVar(&icmSpec.RegistryBydecodePath, "teleporter-registry-bytecode-path", "", "path to an interchain messenger registry bytecode file") cmd.Flags().StringVar(&bootstrapValidatorsJSONFilePath, "bootstrap-filepath", "", "JSON file path that provides details about bootstrap validators, leave Node-ID and BLS values empty if using --generate-node-id=true") cmd.Flags().BoolVar(&generateNodeID, "generate-node-id", false, "whether to create new node id for bootstrap validators (Node-ID and BLS values in bootstrap JSON file will be overridden if --bootstrap-filepath flag is used)") + cmd.Flags().StringSliceVar(&bootstrapEndpoints, "bootstrap-endpoints", nil, "take validator node info from the given endpoints") return cmd } @@ -449,14 +453,41 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { deployInfo.BlockchainID, deployInfo.ICMMessengerAddress, deployInfo.ICMRegistryAddress, - bootstrapValidators, + nil, ); err != nil { return err } return PrintSubnetInfo(blockchainName, true) } - if sidecar.Sovereign && bootstrapValidatorsJSONFilePath == "" { + if len(bootstrapEndpoints) > 0 { + var changeAddr string + for _, endpoint := range bootstrapEndpoints { + infoClient := info.NewClient(endpoint) + ctx, cancel := utils.GetAPILargeContext() + defer cancel() + nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx) + if err != nil { + return err + } + publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:]) + pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:]) + changeAddr, err = getKeyForChangeOwner(nodeID.String(), changeAddr, network) + if err != nil { + return err + } + bootstrapValidators = append(bootstrapValidators, models.SubnetValidator{ + NodeID: nodeID.String(), + Weight: constants.BootstrapValidatorWeight, + Balance: constants.BootstrapValidatorBalance, + BLSPublicKey: publicKey, + BLSProofOfPossession: pop, + ChangeOwnerAddr: changeAddr, + }) + } + } + + if sidecar.Sovereign && len(bootstrapValidators) == 0 { bootstrapValidators, err = promptBootstrapValidators(network) if err != nil { return err @@ -729,6 +760,10 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { if err != nil { return err } + aggregatorExtraPeerEndpoints, err := GetAggregatorExtraPeerEndpoints(network) + if err != nil { + return err + } if err := validatormanager.SetupPoA( app, network, @@ -739,6 +774,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { privateKey, common.HexToAddress(sidecar.PoAValidatorManagerOwner), avaGoBootstrapValidators, + aggregatorExtraPeerEndpoints, ); err != nil { return err } @@ -1003,3 +1039,34 @@ func LoadBootstrapValidator(filepath string) ([]models.SubnetValidator, error) { } return subnetValidators, nil } + +func GetAggregatorExtraPeerEndpoints(network models.Network) ([]string, error) { + aggregatorExtraPeerEndpoints := []string{} + if network.ClusterName != "" { + clustersConfig, err := app.LoadClustersConfig() + if err != nil { + return nil, err + } + clusterConfig := clustersConfig.Clusters[network.ClusterName] + if clusterConfig.Local { + cli, err := binutils.NewGRPCClientWithEndpoint( + binutils.LocalClusterGRPCServerEndpoint, + binutils.WithAvoidRPCVersionCheck(true), + binutils.WithDialTimeout(constants.FastGRPCDialTimeout), + ) + if err != nil { + return nil, err + } + ctx, cancel := utils.GetANRContext() + defer cancel() + status, err := cli.Status(ctx) + if err != nil { + return nil, err + } + for _, nodeInfo := range status.ClusterInfo.NodeInfos { + aggregatorExtraPeerEndpoints = append(aggregatorExtraPeerEndpoints, nodeInfo.Uri) + } + } + } + return aggregatorExtraPeerEndpoints, nil +} diff --git a/cmd/blockchaincmd/prompt_genesis_input.go b/cmd/blockchaincmd/prompt_genesis_input.go index 842a2cc45..ea3d2bb44 100644 --- a/cmd/blockchaincmd/prompt_genesis_input.go +++ b/cmd/blockchaincmd/prompt_genesis_input.go @@ -160,7 +160,7 @@ func promptBootstrapValidators(network models.Network) ([]models.SubnetValidator return nil, err } } - changeAddr, err := getKeyForChangeOwner(previousAddr, network) + changeAddr, err := getKeyForChangeOwner(nodeIDStr, previousAddr, network) if err != nil { return nil, err } diff --git a/cmd/blockchaincmd/prompt_owners.go b/cmd/blockchaincmd/prompt_owners.go index 1dbbad28d..42eb87d7d 100644 --- a/cmd/blockchaincmd/prompt_owners.go +++ b/cmd/blockchaincmd/prompt_owners.go @@ -290,8 +290,11 @@ func getThreshold(maxLen int) (uint32, error) { return uint32(intTh), err } -func getKeyForChangeOwner(previouslyUsedAddr string, network models.Network) (string, error) { - changeAddrPrompt := "Which key would you like to set as change owner for leftover AVAX if the node is removed from validator set?" +func getKeyForChangeOwner(nodeID string, previouslyUsedAddr string, network models.Network) (string, error) { + changeAddrPrompt := fmt.Sprintf( + "Which key would you like to set as change owner for leftover AVAX if the node %s is removed from validator set?", + nodeID, + ) const ( getFromStored = "Get address from an existing stored key (created from avalanche key create or avalanche key import)" diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index 940f56290..3bd5adc2b 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -116,6 +116,10 @@ func initPOAManager(_ *cobra.Command, args []string) error { if err != nil { return err } + aggregatorExtraPeerEndpoints, err := blockchaincmd.GetAggregatorExtraPeerEndpoints(network) + if err != nil { + return err + } if err := validatormanager.SetupPoA( app, network, @@ -124,6 +128,7 @@ func initPOAManager(_ *cobra.Command, args []string) error { privateKey, common.HexToAddress(sc.PoAValidatorManagerOwner), avaGoBootstrapValidators, + aggregatorExtraPeerEndpoints, ); err != nil { return err } diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index fa89f5019..d6ef2fa11 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -17,6 +17,8 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanche-network-runner/client" "github.com/ava-labs/avalanche-network-runner/server" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/set" "github.com/spf13/cobra" ) @@ -99,7 +101,7 @@ func newLocalTrackCmd() *cobra.Command { Short: "(ALPHA Warning) make the local node at the cluster to track given blockchain", Long: "(ALPHA Warning) make the local node at the cluster to track given blockchain", Args: cobra.ExactArgs(2), - RunE: localTrackSubnet, + RunE: localTrack, } } @@ -351,6 +353,15 @@ func localStartNode(_ *cobra.Command, args []string) error { ux.Logger.PrintToUser("Network ready to use.") ux.Logger.PrintToUser("") + status, err := cli.Status(ctx) + if err != nil { + return err + } + for _, nodeInfo := range status.ClusterInfo.NodeInfos { + ux.Logger.PrintToUser("Node %s URI: %s", nodeInfo.Name, nodeInfo.Uri) + } + ux.Logger.PrintToUser("") + return nil } @@ -440,12 +451,26 @@ func checkClusterIsLocal(clusterName string) (bool, error) { return ok && clusterConf.Local, nil } -func localTrackSubnet(_ *cobra.Command, args []string) error { - // todo: support only one local node and detect what cluster to stop +func localTrack(_ *cobra.Command, args []string) error { clusterName := args[0] + blockchainName := args[1] if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { return fmt.Errorf("local node %q is not found", clusterName) } + sc, err := app.LoadSidecar(blockchainName) + if err != nil { + return err + } + clustersConfig, err := app.LoadClustersConfig() + if err != nil { + return err + } + clusterConfig := clustersConfig.Clusters[clusterName] + network := clusterConfig.Network + if sc.Networks[network.Name()].BlockchainID == ids.Empty { + return fmt.Errorf("blockchain %s has not been deployed to %s", blockchainName, network.Name()) + } + subnetID := sc.Networks[network.Name()].SubnetID cli, err := binutils.NewGRPCClientWithEndpoint( binutils.LocalClusterGRPCServerEndpoint, binutils.WithAvoidRPCVersionCheck(true), @@ -454,30 +479,32 @@ func localTrackSubnet(_ *cobra.Command, args []string) error { if err != nil { return err } - ctx, cancel := utils.GetANRContext() defer cancel() - - if _, err := cli.Status(ctx); err != nil { - if server.IsServerError(err, server.ErrNotBootstrapped) { - ux.Logger.PrintToUser("avalanchego already stopped.") - return nil - } - return fmt.Errorf("failed to get avalanchego status: %w", err) - } - // save snapshot before stopping - if _, err := cli.SaveSnapshot( - ctx, - localClusterSnapshotName(clusterName), - true, // force - - ); err != nil { - return fmt.Errorf("failed to save state: %w", err) + status, err := cli.Status(ctx) + if err != nil { + return err } - - if _, err = cli.Stop(ctx); err != nil { - return fmt.Errorf("failed to stop avalanchego: %w", err) + publicEndpoints := []string{} + for _, nodeInfo := range status.ClusterInfo.NodeInfos { + if _, err := cli.RestartNode(ctx, nodeInfo.Name, client.WithWhitelistedSubnets(subnetID.String())); err != nil { + return err + } + publicEndpoints = append(publicEndpoints, nodeInfo.Uri) + } + networkInfo := sc.Networks[network.Name()] + rpcEndpoints := set.Of(networkInfo.RPCEndpoints...) + wsEndpoints := set.Of(networkInfo.WSEndpoints...) + for _, publicEndpoint := range publicEndpoints { + rpcEndpoints.Add(getRPCEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) + wsEndpoints.Add(getWSEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) + } + networkInfo.RPCEndpoints = rpcEndpoints.List() + networkInfo.WSEndpoints = wsEndpoints.List() + sc.Networks[clusterConfig.Network.Name()] = networkInfo + if err := app.UpdateSidecar(&sc); err != nil { + return err } - ux.Logger.GreenCheckmarkToUser("avalanchego stopped. State saved for %s", clusterName) + ux.Logger.GreenCheckmarkToUser("%s successfully tracking %s", clusterName, blockchainName) return nil } diff --git a/go.mod b/go.mod index 72318018a..1ad258660 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/ava-labs/apm v1.0.0 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 - github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f + github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 github.com/ava-labs/subnet-evm v0.6.10 github.com/aws/aws-sdk-go-v2 v1.31.0 diff --git a/go.sum b/go.sum index 8c65a59dc..c94f71c21 100644 --- a/go.sum +++ b/go.sum @@ -89,6 +89,8 @@ github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2 github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f h1:YUQF1wQJeEcTMC5W/OrwgSFTFMS4zeCM8O02rLeEDow= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= +github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 h1:M58jcqAG51RrKKVCfhAZpPqCFdkqRzahEgkFqQA5EME= +github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c= diff --git a/pkg/contract/chain.go b/pkg/contract/chain.go index 3b423d3dc..9631aa717 100644 --- a/pkg/contract/chain.go +++ b/pkg/contract/chain.go @@ -99,18 +99,7 @@ func GetBlockchainEndpoints( rpcEndpoint string wsEndpoint string ) - switch { - case chainSpec.CChain: - rpcEndpoint = network.CChainEndpoint() - wsEndpoint = network.CChainWSEndpoint() - case network.Kind == models.Local || network.Kind == models.Devnet: - blockchainID, err := GetBlockchainID(app, network, chainSpec) - if err != nil { - return "", "", err - } - rpcEndpoint = network.BlockchainEndpoint(blockchainID.String()) - wsEndpoint = network.BlockchainWSEndpoint(blockchainID.String()) - case chainSpec.BlockchainName != "": + if chainSpec.BlockchainName != "" { sc, err := app.LoadSidecar(chainSpec.BlockchainName) if err != nil { return "", "", fmt.Errorf("failed to load sidecar: %w", err) @@ -125,6 +114,20 @@ func GetBlockchainEndpoints( wsEndpoint = sc.Networks[network.Name()].WSEndpoints[0] } } + if rpcEndpoint == "" { + switch { + case chainSpec.CChain: + rpcEndpoint = network.CChainEndpoint() + wsEndpoint = network.CChainWSEndpoint() + case network.Kind == models.Local || network.Kind == models.Devnet: + blockchainID, err := GetBlockchainID(app, network, chainSpec) + if err != nil { + return "", "", err + } + rpcEndpoint = network.BlockchainEndpoint(blockchainID.String()) + wsEndpoint = network.BlockchainWSEndpoint(blockchainID.String()) + } + } blockchainDesc, err := GetBlockchainDesc(chainSpec) if err != nil { return "", "", err diff --git a/pkg/evm/evm.go b/pkg/evm/evm.go index eb3aea977..8269fd6c6 100644 --- a/pkg/evm/evm.go +++ b/pkg/evm/evm.go @@ -257,6 +257,7 @@ func GetSignedTxToMethodWithWarpMessage( callData []byte, value *big.Int, ) (*types.Transaction, error) { + const defaultGasLimit = 2_000_000 privateKey, err := crypto.HexToECDSA(privateKeyStr) if err != nil { return nil, err @@ -288,7 +289,10 @@ func GetSignedTxToMethodWithWarpMessage( } gasLimit, err := EstimateGasLimit(client, msg) if err != nil { - return nil, err + // assuming this is related to the tx itself. + // just using default gas limit, and let the user debug the + // tx if needed so + gasLimit = defaultGasLimit } tx := types.NewTx(&types.DynamicFeeTx{ ChainID: chainID, diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index 05f61f80b..63cf4796a 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -98,6 +98,7 @@ func PoaValidatorManagerGetPChainSubnetConversionWarpMessage( aggregatorLogger logging.Logger, aggregatorLogLevel logging.Level, aggregatorQuorumPercentage uint64, + aggregatorExtraPeerEndpoints []string, subnetID ids.ID, managerBlockchainID ids.ID, managerAddress common.Address, @@ -146,6 +147,7 @@ func PoaValidatorManagerGetPChainSubnetConversionWarpMessage( aggregatorLogLevel, subnetID, aggregatorQuorumPercentage, + aggregatorExtraPeerEndpoints, ) if err != nil { return nil, err @@ -216,6 +218,7 @@ func SetupPoA( privateKey string, ownerAddress common.Address, convertSubnetValidators []*txs.ConvertSubnetValidator, + aggregatorExtraPeerEndpoints []string, ) error { if err := evm.SetupProposerVM( rpcURL, @@ -253,8 +256,9 @@ func SetupPoA( subnetConversionSignedMessage, err := PoaValidatorManagerGetPChainSubnetConversionWarpMessage( network, app.Log, - logging.Info, + logging.Trace, 0, + aggregatorExtraPeerEndpoints, subnetID, blockchainID, managerAddress, diff --git a/sdk/interchain/signature-aggregator.go b/sdk/interchain/signature-aggregator.go index 00d8840dc..405d5bff7 100644 --- a/sdk/interchain/signature-aggregator.go +++ b/sdk/interchain/signature-aggregator.go @@ -45,11 +45,16 @@ type SignatureAggregator struct { // Returns: // - peers.AppRequestNetwork: The created AppRequestNetwork, or nil if an error occurred. // - error: An error if the creation of the AppRequestNetwork failed. -func createAppRequestNetwork(network models.Network, logLevel logging.Level) (peers.AppRequestNetwork, error) { +func createAppRequestNetwork( + network models.Network, + logLevel logging.Level, + extraPeerEndpoints []string, +) (peers.AppRequestNetwork, error) { peerNetwork, err := peers.NewNetwork( logLevel, prometheus.DefaultRegisterer, nil, + extraPeerEndpoints, &config.Config{ PChainAPI: &apiConfig.APIConfig{ BaseURL: network.Endpoint, @@ -130,8 +135,9 @@ func NewSignatureAggregator( logLevel logging.Level, subnetID ids.ID, quorumPercentage uint64, + extraPeerEndpoints []string, ) (*SignatureAggregator, error) { - peerNetwork, err := createAppRequestNetwork(network, logLevel) + peerNetwork, err := createAppRequestNetwork(network, logLevel, extraPeerEndpoints) if err != nil { return nil, err } From b8f20cafce03ee3e5fda6d5fb2dc25076997d5b1 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 10 Oct 2024 11:31:38 -0300 Subject: [PATCH 17/57] nit --- cmd/nodecmd/local.go | 45 +++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index d6ef2fa11..b6168cdae 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -181,6 +181,30 @@ func localStartNode(_ *cobra.Command, args []string) error { pluginDir := app.GetPluginsDir() ctx, cancel := utils.GetANRContext() defer cancel() + + // starts server + avalancheGoVersion := "latest" + if avalanchegoBinaryPath == "" { + avalancheGoVersion, err = getAvalancheGoVersion() + if err != nil { + return err + } else { + ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) + } + } + sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") + if err := sd.StartServer( + constants.ServerRunFileLocalClusterPrefix, + binutils.LocalClusterGRPCServerPort, + binutils.LocalClusterGRPCGatewayPort, + ); err != nil { + return err + } + _, avalancheGoBinPath, err := sd.SetupLocalEnv() + if err != nil { + return err + } + if localClusterDataExists(clusterName) { ux.Logger.GreenCheckmarkToUser("Local cluster %s found. Booting up...", clusterName) } else { @@ -206,15 +230,6 @@ func localStartNode(_ *cobra.Command, args []string) error { return err } } - avalancheGoVersion := "latest" - if avalanchegoBinaryPath == "" { - avalancheGoVersion, err = getAvalancheGoVersion() - if err != nil { - return err - } else { - ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) - } - } if err := preLocalChecks(clusterName); err != nil { return err } @@ -249,18 +264,6 @@ func localStartNode(_ *cobra.Command, args []string) error { defer os.Remove(upgradePath) } - sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") - if err := sd.StartServer( - constants.ServerRunFileLocalClusterPrefix, - binutils.LocalClusterGRPCServerPort, - binutils.LocalClusterGRPCGatewayPort, - ); err != nil { - return err - } - _, avalancheGoBinPath, err := sd.SetupLocalEnv() - if err != nil { - return err - } // make sure rootDir exists if err := os.MkdirAll(rootDir, 0o700); err != nil { return fmt.Errorf("could not create root directory %s: %w", rootDir, err) From e225ed552525587ba7e8ba6935c1de3f829659cf Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 10 Oct 2024 13:19:44 -0300 Subject: [PATCH 18/57] fix plugin --- cmd/nodecmd/local.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index b6168cdae..5a8c22a76 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanche-network-runner/client" "github.com/ava-labs/avalanche-network-runner/server" + anrutils "github.com/ava-labs/avalanche-network-runner/utils" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/set" "github.com/spf13/cobra" @@ -474,6 +475,26 @@ func localTrack(_ *cobra.Command, args []string) error { return fmt.Errorf("blockchain %s has not been deployed to %s", blockchainName, network.Name()) } subnetID := sc.Networks[network.Name()].SubnetID + chainVMID, err := anrutils.VMID(blockchainName) + if err != nil { + return fmt.Errorf("failed to create VM ID from %s: %w", blockchainName, err) + } + var vmBin string + switch sc.VM { + case models.SubnetEvm: + _, vmBin, err = binutils.SetupSubnetEVM(app, sc.VMVersion) + if err != nil { + return fmt.Errorf("failed to install subnet-evm: %w", err) + } + case models.CustomVM: + vmBin = binutils.SetupCustomBin(app, blockchainName) + default: + return fmt.Errorf("unknown vm: %s", sc.VM) + } + binaryDownloader := binutils.NewPluginBinaryDownloader(app) + if err := binaryDownloader.InstallVM(chainVMID.String(), vmBin); err != nil { + return err + } cli, err := binutils.NewGRPCClientWithEndpoint( binutils.LocalClusterGRPCServerEndpoint, binutils.WithAvoidRPCVersionCheck(true), From 7a12d7894470c572c85bf5c2ecc1cb71a870ed7f Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 10 Oct 2024 14:59:40 -0300 Subject: [PATCH 19/57] nit --- cmd/networkcmd/start.go | 15 +-------------- cmd/nodecmd/local.go | 20 +++++++++++++++----- pkg/localnet/localnet.go | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/cmd/networkcmd/start.go b/cmd/networkcmd/start.go index da8f56f16..bcc2c7b29 100644 --- a/cmd/networkcmd/start.go +++ b/cmd/networkcmd/start.go @@ -3,7 +3,6 @@ package networkcmd import ( - "context" "fmt" "path/filepath" @@ -18,7 +17,6 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanche-cli/pkg/vm" "github.com/ava-labs/avalanche-network-runner/client" - "github.com/ava-labs/avalanche-network-runner/server" anrutils "github.com/ava-labs/avalanche-network-runner/utils" "github.com/spf13/cobra" ) @@ -89,7 +87,7 @@ func StartNetwork(*cobra.Command, []string) error { ctx, cancel := utils.GetANRContext() defer cancel() - bootstrapped, err := CheckNetworkIsAlreadyBootstrapped(ctx, cli) + bootstrapped, err := localnet.CheckNetworkIsAlreadyBootstrapped(ctx, cli) if err != nil { return err } @@ -246,14 +244,3 @@ func determineAvagoVersion(userProvidedAvagoVersion string) (string, error) { constants.AvalancheGoCompatibilityURL, ) } - -func CheckNetworkIsAlreadyBootstrapped(ctx context.Context, cli client.Client) (bool, error) { - _, err := cli.Status(ctx) - if err != nil { - if server.IsServerError(err, server.ErrNotBootstrapped) { - return false, nil - } - return false, fmt.Errorf("failed trying to get network status: %w", err) - } - return true, nil -} diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 5a8c22a76..932bbf21e 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -10,6 +10,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/binutils" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/constants" + "github.com/ava-labs/avalanche-cli/pkg/localnet" "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" "github.com/ava-labs/avalanche-cli/pkg/subnet" @@ -273,8 +274,6 @@ func localStartNode(_ *cobra.Command, args []string) error { return fmt.Errorf("could not create log directory %s: %w", logDir, err) } - ux.Logger.PrintToUser("Starting local avalanchego node using root: %s ...", rootDir) - anrOpts := []client.OpOption{ client.WithNumNodes(1), client.WithNetworkID(network.ID), @@ -304,14 +303,25 @@ func localStartNode(_ *cobra.Command, args []string) error { if bootstrapIPs != nil { anrOpts = append(anrOpts, client.WithBootstrapNodeIPPortPairs(bootstrapIPs)) } - spinSession := ux.NewUserSpinner() - spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...") + cli, err := binutils.NewGRPCClientWithEndpoint(binutils.LocalClusterGRPCServerEndpoint) if err != nil { - ux.SpinFailWithError(spinner, "", err) return err } + alreadyBootstrapped, err := localnet.CheckNetworkIsAlreadyBootstrapped(ctx, cli) + if err != nil { + return err + } + if alreadyBootstrapped { + ux.Logger.PrintToUser("") + ux.Logger.PrintToUser("A local cluster is already executing") + ux.Logger.PrintToUser("please stop it by calling `node local stop`") + return nil + } + ux.Logger.PrintToUser("Starting local avalanchego node using root: %s ...", rootDir) + spinSession := ux.NewUserSpinner() + spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...") if _, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...); err != nil { ux.SpinFailWithError(spinner, "", err) return fmt.Errorf("failed to start local avalanchego: %w", err) diff --git a/pkg/localnet/localnet.go b/pkg/localnet/localnet.go index e86f3ddd1..1ebcf57a2 100644 --- a/pkg/localnet/localnet.go +++ b/pkg/localnet/localnet.go @@ -3,7 +3,9 @@ package localnet import ( + "context" "encoding/json" + "fmt" "os" "path/filepath" "strings" @@ -12,7 +14,9 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/utils" + "github.com/ava-labs/avalanche-network-runner/client" "github.com/ava-labs/avalanche-network-runner/rpcpb" + "github.com/ava-labs/avalanche-network-runner/server" ) func GetClusterInfo() (*rpcpb.ClusterInfo, error) { @@ -92,3 +96,14 @@ func Deployed(subnetName string) (bool, error) { } return true, nil } + +func CheckNetworkIsAlreadyBootstrapped(ctx context.Context, cli client.Client) (bool, error) { + _, err := cli.Status(ctx) + if err != nil { + if server.IsServerError(err, server.ErrNotBootstrapped) { + return false, nil + } + return false, fmt.Errorf("failed trying to get network status: %w", err) + } + return true, nil +} From 93a3cfe3597fb9ec98960d9f20ea25b5d67f9495 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 10 Oct 2024 17:30:12 -0300 Subject: [PATCH 20/57] improve snapshot management --- cmd/backendcmd/spawn_server.go | 15 ++-- cmd/blockchaincmd/deploy.go | 6 +- cmd/networkcmd/clean.go | 6 +- cmd/networkcmd/start.go | 1 + cmd/networkcmd/stop.go | 6 +- cmd/nodecmd/local.go | 151 ++++++++++++++------------------- go.mod | 2 + pkg/binutils/processes.go | 7 +- pkg/subnet/local.go | 4 +- 9 files changed, 98 insertions(+), 100 deletions(-) diff --git a/cmd/backendcmd/spawn_server.go b/cmd/backendcmd/spawn_server.go index c44b2ebf2..81a9c7dda 100644 --- a/cmd/backendcmd/spawn_server.go +++ b/cmd/backendcmd/spawn_server.go @@ -14,9 +14,10 @@ import ( ) var ( - app *application.Avalanche - serverPort string - gatewayPort string + app *application.Avalanche + serverPort string + gatewayPort string + snapshotsDir string ) // backendCmd is the command to run the backend gRPC process @@ -32,13 +33,15 @@ func NewCmd(injectedApp *application.Avalanche) *cobra.Command { } cmd.Flags().StringVar(&serverPort, "server-port", binutils.LocalNetworkGRPCServerPort, "server port to use") cmd.Flags().StringVar(&gatewayPort, "gateway-port", binutils.LocalNetworkGRPCGatewayPort, "gateway port to use") + cmd.Flags().StringVar(&snapshotsDir, "snapshots-dir", "", "snapshots dir to use") return cmd } func startBackend(_ *cobra.Command, _ []string) error { - fmt.Println(serverPort) - fmt.Println(gatewayPort) - s, err := binutils.NewGRPCServer(serverPort, gatewayPort, app.GetSnapshotsDir()) + if snapshotsDir == "" { + snapshotsDir = app.GetSnapshotsDir() + } + s, err := binutils.NewGRPCServer(serverPort, gatewayPort, snapshotsDir) if err != nil { return err } diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index cd6b71618..aa7707f6e 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -437,7 +437,11 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { ) if err != nil { if deployer.BackendStartedHere() { - if innerErr := binutils.KillgRPCServerProcess(app, constants.ServerRunFileLocalNetworkPrefix); innerErr != nil { + if innerErr := binutils.KillgRPCServerProcess( + app, + binutils.LocalNetworkGRPCServerEndpoint, + constants.ServerRunFileLocalNetworkPrefix, + ); innerErr != nil { app.Log.Warn("tried to kill the gRPC server process but it failed", zap.Error(innerErr)) } } diff --git a/cmd/networkcmd/clean.go b/cmd/networkcmd/clean.go index a196c28fb..d6e998e46 100644 --- a/cmd/networkcmd/clean.go +++ b/cmd/networkcmd/clean.go @@ -51,7 +51,11 @@ func clean(*cobra.Command, []string) error { app.Log.Warn("failed resetting default snapshot", zap.Error(err)) } - if err := binutils.KillgRPCServerProcess(app, constants.ServerRunFileLocalNetworkPrefix); err != nil { + if err := binutils.KillgRPCServerProcess( + app, + binutils.LocalNetworkGRPCServerEndpoint, + constants.ServerRunFileLocalNetworkPrefix, + ); err != nil { app.Log.Warn("failed killing server process", zap.Error(err)) } else { ux.Logger.PrintToUser("Process terminated.") diff --git a/cmd/networkcmd/start.go b/cmd/networkcmd/start.go index bcc2c7b29..6d9f1bf81 100644 --- a/cmd/networkcmd/start.go +++ b/cmd/networkcmd/start.go @@ -70,6 +70,7 @@ func StartNetwork(*cobra.Command, []string) error { constants.ServerRunFileLocalNetworkPrefix, binutils.LocalNetworkGRPCServerPort, binutils.LocalNetworkGRPCGatewayPort, + app.GetSnapshotsDir(), ); err != nil { return err } diff --git a/cmd/networkcmd/stop.go b/cmd/networkcmd/stop.go index 0975274aa..ff0180350 100644 --- a/cmd/networkcmd/stop.go +++ b/cmd/networkcmd/stop.go @@ -51,7 +51,11 @@ func StopNetwork(*cobra.Command, []string) error { } var err error - if err = binutils.KillgRPCServerProcess(app, constants.ServerRunFileLocalNetworkPrefix); err != nil { + if err = binutils.KillgRPCServerProcess( + app, + binutils.LocalNetworkGRPCServerEndpoint, + constants.ServerRunFileLocalNetworkPrefix, + ); err != nil { app.Log.Warn("failed killing server process", zap.Error(err)) fmt.Println(err) } else { diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 932bbf21e..b627f41b0 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -17,7 +17,6 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanche-network-runner/client" - "github.com/ava-labs/avalanche-network-runner/server" anrutils "github.com/ava-labs/avalanche-network-runner/utils" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/set" @@ -89,10 +88,10 @@ status by running avalanche node status local func newLocalStopCmd() *cobra.Command { return &cobra.Command{ - Use: "stop [clusterName]", + Use: "stop", Short: "(ALPHA Warning) Stop local node", Long: `Stop local node.`, - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(0), RunE: localStopNode, } } @@ -165,11 +164,7 @@ func preLocalChecks(clusterName string) error { } func localClusterDataExists(clusterName string) bool { - return utils.FileExists(filepath.Join(app.GetLocalDir(clusterName), "state.json")) -} - -func localClusterSnapshotName(clusterName string) string { - return fmt.Sprintf("local-snapshot-%s", clusterName) + return utils.FileExists(filepath.Join(app.GetLocalDir(clusterName), "anr-snapshot-"+clusterName, "state.json")) } func localStartNode(_ *cobra.Command, args []string) error { @@ -179,7 +174,6 @@ func localStartNode(_ *cobra.Command, args []string) error { // check if this is existing cluster rootDir := app.GetLocalDir(clusterName) - logDir := filepath.Join(rootDir, "logs") pluginDir := app.GetPluginsDir() ctx, cancel := utils.GetANRContext() defer cancel() @@ -199,6 +193,7 @@ func localStartNode(_ *cobra.Command, args []string) error { constants.ServerRunFileLocalClusterPrefix, binutils.LocalClusterGRPCServerPort, binutils.LocalClusterGRPCGatewayPort, + rootDir, ); err != nil { return err } @@ -206,9 +201,35 @@ func localStartNode(_ *cobra.Command, args []string) error { if err != nil { return err } + cli, err := binutils.NewGRPCClientWithEndpoint(binutils.LocalClusterGRPCServerEndpoint) + if err != nil { + return err + } + alreadyBootstrapped, err := localnet.CheckNetworkIsAlreadyBootstrapped(ctx, cli) + if err != nil { + return err + } + if alreadyBootstrapped { + ux.Logger.PrintToUser("") + ux.Logger.PrintToUser("A local cluster is already executing") + ux.Logger.PrintToUser("please stop it by calling 'node local stop'") + return nil + } if localClusterDataExists(clusterName) { ux.Logger.GreenCheckmarkToUser("Local cluster %s found. Booting up...", clusterName) + loadSnapshotOpts := []client.OpOption{ + client.WithReassignPortsIfUsed(true), + client.WithPluginDir(pluginDir), + } + // load snapshot for existing network + if _, err := cli.LoadSnapshot( + ctx, + clusterName, + true, // in-place + loadSnapshotOpts...); err != nil { + return fmt.Errorf("failed to load snapshot: %w", err) + } } else { ux.Logger.GreenCheckmarkToUser("Local cluster %s not found. Creating...", clusterName) if useEtnaDevnet { @@ -270,16 +291,12 @@ func localStartNode(_ *cobra.Command, args []string) error { if err := os.MkdirAll(rootDir, 0o700); err != nil { return fmt.Errorf("could not create root directory %s: %w", rootDir, err) } - if err := os.MkdirAll(logDir, 0o700); err != nil { - return fmt.Errorf("could not create log directory %s: %w", logDir, err) - } anrOpts := []client.OpOption{ client.WithNumNodes(1), client.WithNetworkID(network.ID), client.WithExecPath(avalancheGoBinPath), - client.WithRootDataDir(rootDir), - client.WithLogRootDir(logDir), + client.WithRootDataDir(rootDir + "anr-snapshot-" + clusterName), client.WithReassignPortsIfUsed(true), client.WithPluginDir(pluginDir), } @@ -304,21 +321,6 @@ func localStartNode(_ *cobra.Command, args []string) error { anrOpts = append(anrOpts, client.WithBootstrapNodeIPPortPairs(bootstrapIPs)) } - cli, err := binutils.NewGRPCClientWithEndpoint(binutils.LocalClusterGRPCServerEndpoint) - if err != nil { - return err - } - alreadyBootstrapped, err := localnet.CheckNetworkIsAlreadyBootstrapped(ctx, cli) - if err != nil { - return err - } - if alreadyBootstrapped { - ux.Logger.PrintToUser("") - ux.Logger.PrintToUser("A local cluster is already executing") - ux.Logger.PrintToUser("please stop it by calling `node local stop`") - return nil - } - ux.Logger.PrintToUser("Starting local avalanchego node using root: %s ...", rootDir) spinSession := ux.NewUserSpinner() spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...") @@ -327,42 +329,15 @@ func localStartNode(_ *cobra.Command, args []string) error { return fmt.Errorf("failed to start local avalanchego: %w", err) } ux.SpinComplete(spinner) - // save snapshot after successful start - if _, err := cli.SaveSnapshot( - ctx, - localClusterSnapshotName(clusterName), - true, // force - ); err != nil { - return fmt.Errorf("failed to save local avalanchego state: %w", err) - } // save cluster config for the new local cluster if err := addLocalClusterConfig(network); err != nil { return err } } - cli, err := binutils.NewGRPCClientWithEndpoint(binutils.LocalClusterGRPCServerEndpoint) - if err != nil { - return err - } - - loadSnapshotOpts := []client.OpOption{ - client.WithRootDataDir(rootDir), - client.WithLogRootDir(logDir), - client.WithReassignPortsIfUsed(true), - client.WithPluginDir(pluginDir), - } - // load snapshot for existing network - if _, err := cli.LoadSnapshot( - ctx, - localClusterSnapshotName(clusterName), - false, // in-place - loadSnapshotOpts...); err != nil { - return fmt.Errorf("failed to load snapshot: %w", err) - } ux.Logger.GreenCheckmarkToUser("Avalanchego started and ready to use from %s", rootDir) ux.Logger.PrintToUser("") - ux.Logger.PrintToUser("Node logs directory: %s/node1/logs", logDir) + ux.Logger.PrintToUser("Node logs directory: %s/anr-snapshot-%s/node1/logs", rootDir, clusterName) ux.Logger.PrintToUser("") ux.Logger.PrintToUser("Network ready to use.") ux.Logger.PrintToUser("") @@ -379,12 +354,7 @@ func localStartNode(_ *cobra.Command, args []string) error { return nil } -func localStopNode(_ *cobra.Command, args []string) error { - // todo: support only one local node and detect what cluster to stop - clusterName := args[0] - if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { - return fmt.Errorf("local node %q is not found", clusterName) - } +func localStopNode(_ *cobra.Command, _ []string) error { cli, err := binutils.NewGRPCClientWithEndpoint( binutils.LocalClusterGRPCServerEndpoint, binutils.WithAvoidRPCVersionCheck(true), @@ -393,52 +363,55 @@ func localStopNode(_ *cobra.Command, args []string) error { if err != nil { return err } - ctx, cancel := utils.GetANRContext() defer cancel() - - if _, err := cli.Status(ctx); err != nil { - if server.IsServerError(err, server.ErrNotBootstrapped) { - ux.Logger.PrintToUser("avalanchego already stopped.") - return nil + bootstrapped, err := localnet.CheckNetworkIsAlreadyBootstrapped(ctx, cli) + if err != nil { + return err + } + if bootstrapped { + if _, err = cli.Stop(ctx); err != nil { + return fmt.Errorf("failed to stop avalanchego: %w", err) } - return fmt.Errorf("failed to get avalanchego status: %w", err) } - // save snapshot before stopping - if _, err := cli.SaveSnapshot( - ctx, - localClusterSnapshotName(clusterName), - true, // force - + if err := binutils.KillgRPCServerProcess( + app, + binutils.LocalClusterGRPCServerEndpoint, + constants.ServerRunFileLocalClusterPrefix, ); err != nil { - return fmt.Errorf("failed to save state: %w", err) - } - - if _, err = cli.Stop(ctx); err != nil { - return fmt.Errorf("failed to stop avalanchego: %w", err) + return err } - ux.Logger.GreenCheckmarkToUser("avalanchego stopped. State saved for %s", clusterName) + ux.Logger.GreenCheckmarkToUser("avalanchego stopped") return nil } func localDestroyNode(_ *cobra.Command, args []string) error { clusterName := args[0] + + localStopNode(nil, nil) + + rootDir := app.GetLocalDir(clusterName) + if err := os.RemoveAll(rootDir); err != nil { + return err + } + if ok, err := checkClusterIsLocal(clusterName); err != nil || !ok { return fmt.Errorf("local cluster %q not found", clusterName) } - if err := cleanupLocalNode(clusterName); err != nil { - return fmt.Errorf("failed to cleanup local node: %w", err) + clustersConfig, err := app.LoadClustersConfig() + if err != nil { + return err + } + delete(clustersConfig.Clusters, clusterName) + if err := app.WriteClustersConfigFile(&clustersConfig); err != nil { + return err } + ux.Logger.GreenCheckmarkToUser("Local node %s cleaned up.", clusterName) return nil } -func cleanupLocalNode(clusterName string) error { - rootDir := app.GetLocalDir(clusterName) - return os.RemoveAll(rootDir) -} - func addLocalClusterConfig(network models.Network) error { clusterName := network.ClusterName clustersConfig, err := app.LoadClustersConfig() diff --git a/go.mod b/go.mod index 1ad258660..2e46e0e8e 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/ava-labs/avalanche-cli go 1.22.8 +replace github.com/ava-labs/avalanche-network-runner => ../avalanche-network-runner + require ( github.com/ava-labs/apm v1.0.0 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a diff --git a/pkg/binutils/processes.go b/pkg/binutils/processes.go index 7dc4c209e..0fc5a7163 100644 --- a/pkg/binutils/processes.go +++ b/pkg/binutils/processes.go @@ -224,6 +224,7 @@ func StartServerProcess( prefix string, serverPort string, gatewayPort string, + snapshotsDir string, ) error { thisBin := reexec.Self() @@ -233,6 +234,8 @@ func StartServerProcess( serverPort, "--gateway-port", gatewayPort, + "--snapshots-dir", + snapshotsDir, } cmd := exec.Command(thisBin, args...) @@ -274,9 +277,11 @@ func StartServerProcess( func KillgRPCServerProcess( app *application.Avalanche, + serverEndpoint string, prefix string, ) error { - cli, err := NewGRPCClient( + cli, err := NewGRPCClientWithEndpoint( + serverEndpoint, WithAvoidRPCVersionCheck(true), WithDialTimeout(constants.FastGRPCDialTimeout), ) diff --git a/pkg/subnet/local.go b/pkg/subnet/local.go index d489c80fd..cd94f0547 100644 --- a/pkg/subnet/local.go +++ b/pkg/subnet/local.go @@ -111,6 +111,7 @@ func (d *LocalDeployer) DeployToLocalNetwork( constants.ServerRunFileLocalNetworkPrefix, binutils.LocalNetworkGRPCServerPort, binutils.LocalNetworkGRPCGatewayPort, + d.app.GetSnapshotsDir(), ); err != nil { return nil, err } @@ -121,6 +122,7 @@ func (d *LocalDeployer) StartServer( prefix string, serverPort string, gatewayPort string, + snapshotsDir string, ) error { isRunning, err := d.procChecker.IsServerProcessRunning(d.app, prefix) if err != nil { @@ -128,7 +130,7 @@ func (d *LocalDeployer) StartServer( } if !isRunning { d.app.Log.Debug("gRPC server is not running") - if err := binutils.StartServerProcess(d.app, prefix, serverPort, gatewayPort); err != nil { + if err := binutils.StartServerProcess(d.app, prefix, serverPort, gatewayPort, snapshotsDir); err != nil { return fmt.Errorf("failed starting gRPC server process: %w", err) } d.backendStartedHere = true From c617154961eaac08dcbae17e195d20f3bd383144 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 10 Oct 2024 17:38:59 -0300 Subject: [PATCH 21/57] fix bug --- cmd/blockchaincmd/describe.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/blockchaincmd/describe.go b/cmd/blockchaincmd/describe.go index 7bbaed6cf..8b55c4ceb 100644 --- a/cmd/blockchaincmd/describe.go +++ b/cmd/blockchaincmd/describe.go @@ -119,7 +119,9 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error { for net, data := range sc.Networks { network, err := networkoptions.GetNetworkFromSidecarNetworkName(app, net) if err != nil { - return err + ux.Logger.RedXToUser("%s is supposed to be deployed to network %s: %s ", blockchainName, network.Name(), err) + ux.Logger.PrintToUser("") + continue } if network.Kind == models.Local && !locallyDeployed { continue @@ -191,7 +193,7 @@ func PrintSubnetInfo(blockchainName string, onlyLocalnetInfo bool) error { for net, data := range sc.Networks { network, err := networkoptions.GetNetworkFromSidecarNetworkName(app, net) if err != nil { - return err + continue } if network.Kind == models.Local && !locallyDeployed { continue From c6ed5531c0d90326f6b827ebbd63dfe914cc7ff0 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 10 Oct 2024 17:50:32 -0300 Subject: [PATCH 22/57] nit --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index 2e46e0e8e..1ad258660 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/ava-labs/avalanche-cli go 1.22.8 -replace github.com/ava-labs/avalanche-network-runner => ../avalanche-network-runner - require ( github.com/ava-labs/apm v1.0.0 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a From afb44a14f152a58f6354b976ef161eae9e7123fd Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Thu, 10 Oct 2024 14:06:54 -0700 Subject: [PATCH 23/57] proper etna devnet boostrappers --- pkg/constants/etna.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pkg/constants/etna.go b/pkg/constants/etna.go index 359454843..531e5e2c8 100644 --- a/pkg/constants/etna.go +++ b/pkg/constants/etna.go @@ -24,11 +24,6 @@ var ( "NodeID-8LbTmmGsDC991SbD8Nkx88VULT3XYzYXC", "NodeID-DDhXtFm6Q9tCq2yiFRmcSMKvHgUgh8yQC", "NodeID-QDYnWDQd6g4cQ5H6yiWNqSmfRMBqEH9AG", - "NodeID-P5QGH4EXddrcyNAzkqyZKHXgEpVX6HExL", - "NodeID-78ibWpjtZz5ZGT6EyTEdu8VKmboUHTuGT", - "NodeID-7eRvnfs2a2PvrPHUuCRRpPVAoVjbWxaFG", - "NodeID-gpXWBExQSZXqJPQt6L6MnveUfgr7HJ4q", - "NodeID-L4CY8B5uVSDe4cnN1BpeDsHacMp4q4q8q", } EtnaDevnetBootstrapIPs = []string{ "107.21.11.213:9651", @@ -36,10 +31,5 @@ var ( "52.201.126.172:9651", "35.170.144.5:9651", "98.82.41.186:9651", - "34.228.34.127:9651", - "44.205.136.166:9651", - "52.6.31.40:9651", - "54.197.98.148:9651", - "18.211.108.228:9651", } ) From f2653d86c5b29208d2de654e226cb65b9354d6f9 Mon Sep 17 00:00:00 2001 From: Artur Reznikov Date: Thu, 10 Oct 2024 20:13:09 -0700 Subject: [PATCH 24/57] fix bug with local rootdir --- cmd/nodecmd/local.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index b627f41b0..ee88b7324 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -164,7 +164,8 @@ func preLocalChecks(clusterName string) error { } func localClusterDataExists(clusterName string) bool { - return utils.FileExists(filepath.Join(app.GetLocalDir(clusterName), "anr-snapshot-"+clusterName, "state.json")) + rootDir := app.GetLocalDir(clusterName) + return utils.FileExists(filepath.Join(rootDir, "anr-snapshot-"+clusterName, "state.json")) } func localStartNode(_ *cobra.Command, args []string) error { @@ -296,7 +297,7 @@ func localStartNode(_ *cobra.Command, args []string) error { client.WithNumNodes(1), client.WithNetworkID(network.ID), client.WithExecPath(avalancheGoBinPath), - client.WithRootDataDir(rootDir + "anr-snapshot-" + clusterName), + client.WithRootDataDir(filepath.Join(rootDir, fmt.Sprintf("anr-snapshot-%s", clusterName))), client.WithReassignPortsIfUsed(true), client.WithPluginDir(pluginDir), } From 3b3d6996991800b208146445b5636d4c4913d6dc Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Fri, 11 Oct 2024 04:46:33 -0300 Subject: [PATCH 25/57] remove global node config stuff --- cmd/nodecmd/local.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index ee88b7324..73d4e4517 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -301,14 +301,6 @@ func localStartNode(_ *cobra.Command, args []string) error { client.WithReassignPortsIfUsed(true), client.WithPluginDir(pluginDir), } - // load global node configs if they exist - configStr, err := app.Conf.LoadNodeConfig() - if err != nil { - return err - } - if configStr != "" { - anrOpts = append(anrOpts, client.WithGlobalNodeConfig(configStr)) - } if genesisPath != "" && utils.FileExists(genesisPath) { anrOpts = append(anrOpts, client.WithGenesisPath(genesisPath)) } From 3b4cdfe53d5d21d0cb2b527683ddcf82fdc20d91 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Fri, 11 Oct 2024 05:03:52 -0300 Subject: [PATCH 26/57] destroy node data and processes if bad start --- cmd/nodecmd/local.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 73d4e4517..1d141679c 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -228,7 +228,8 @@ func localStartNode(_ *cobra.Command, args []string) error { ctx, clusterName, true, // in-place - loadSnapshotOpts...); err != nil { + loadSnapshotOpts..., + ); err != nil { return fmt.Errorf("failed to load snapshot: %w", err) } } else { @@ -319,6 +320,7 @@ func localStartNode(_ *cobra.Command, args []string) error { spinner := spinSession.SpinToUser("Booting Network. Wait until healthy...") if _, err := cli.Start(ctx, avalancheGoBinPath, anrOpts...); err != nil { ux.SpinFailWithError(spinner, "", err) + localDestroyNode(nil, []string{clusterName}) return fmt.Errorf("failed to start local avalanchego: %w", err) } ux.SpinComplete(spinner) From 61eb94d1224f8a7fbf5dcac62be2d92d306a8754 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Fri, 11 Oct 2024 15:49:33 -0300 Subject: [PATCH 27/57] nit --- cmd/nodecmd/local.go | 8 +++++--- go.mod | 2 ++ pkg/constants/constants.go | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 1d141679c..dbf98978e 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -165,7 +165,7 @@ func preLocalChecks(clusterName string) error { func localClusterDataExists(clusterName string) bool { rootDir := app.GetLocalDir(clusterName) - return utils.FileExists(filepath.Join(rootDir, "anr-snapshot-"+clusterName, "state.json")) + return utils.FileExists(filepath.Join(rootDir, "state.json")) } func localStartNode(_ *cobra.Command, args []string) error { @@ -222,6 +222,7 @@ func localStartNode(_ *cobra.Command, args []string) error { loadSnapshotOpts := []client.OpOption{ client.WithReassignPortsIfUsed(true), client.WithPluginDir(pluginDir), + client.WithSnapshotPath(rootDir), } // load snapshot for existing network if _, err := cli.LoadSnapshot( @@ -298,9 +299,10 @@ func localStartNode(_ *cobra.Command, args []string) error { client.WithNumNodes(1), client.WithNetworkID(network.ID), client.WithExecPath(avalancheGoBinPath), - client.WithRootDataDir(filepath.Join(rootDir, fmt.Sprintf("anr-snapshot-%s", clusterName))), + client.WithRootDataDir(rootDir), client.WithReassignPortsIfUsed(true), client.WithPluginDir(pluginDir), + client.WithAlwaysLoopbackURL(true), } if genesisPath != "" && utils.FileExists(genesisPath) { anrOpts = append(anrOpts, client.WithGenesisPath(genesisPath)) @@ -332,7 +334,7 @@ func localStartNode(_ *cobra.Command, args []string) error { ux.Logger.GreenCheckmarkToUser("Avalanchego started and ready to use from %s", rootDir) ux.Logger.PrintToUser("") - ux.Logger.PrintToUser("Node logs directory: %s/anr-snapshot-%s/node1/logs", rootDir, clusterName) + ux.Logger.PrintToUser("Node logs directory: %s/node1/logs", rootDir) ux.Logger.PrintToUser("") ux.Logger.PrintToUser("Network ready to use.") ux.Logger.PrintToUser("") diff --git a/go.mod b/go.mod index 1ad258660..2e46e0e8e 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/ava-labs/avalanche-cli go 1.22.8 +replace github.com/ava-labs/avalanche-network-runner => ../avalanche-network-runner + require ( github.com/ava-labs/apm v1.0.0 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index d4eaa9fb3..0d300e94b 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -55,8 +55,8 @@ const ( CloudOperationTimeout = 2 * time.Minute ANRRequestTimeout = 3 * time.Minute - APIRequestTimeout = 30 * time.Second - APIRequestLargeTimeout = 2 * time.Minute + APIRequestTimeout = 5 * time.Second + APIRequestLargeTimeout = 5 * time.Second FastGRPCDialTimeout = 100 * time.Millisecond SSHServerStartTimeout = 1 * time.Minute From 46fa068ef07d7cab384d21e01006c75e60f8e4ee Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Fri, 11 Oct 2024 16:21:46 -0300 Subject: [PATCH 28/57] always use fresh staking keys --- cmd/nodecmd/local.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 1d141679c..a81940d64 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -301,6 +301,7 @@ func localStartNode(_ *cobra.Command, args []string) error { client.WithRootDataDir(filepath.Join(rootDir, fmt.Sprintf("anr-snapshot-%s", clusterName))), client.WithReassignPortsIfUsed(true), client.WithPluginDir(pluginDir), + client.WithFreshStakingIds(true), } if genesisPath != "" && utils.FileExists(genesisPath) { anrOpts = append(anrOpts, client.WithGenesisPath(genesisPath)) @@ -342,7 +343,7 @@ func localStartNode(_ *cobra.Command, args []string) error { return err } for _, nodeInfo := range status.ClusterInfo.NodeInfos { - ux.Logger.PrintToUser("Node %s URI: %s", nodeInfo.Name, nodeInfo.Uri) + ux.Logger.PrintToUser("Node %s URI: %s NodeID: %s", nodeInfo.Name, nodeInfo.Uri, nodeInfo.Id) } ux.Logger.PrintToUser("") From ac2bdc3fcf5e29b4e593ffa64f6fb8fc23658204 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Fri, 11 Oct 2024 16:24:42 -0300 Subject: [PATCH 29/57] nit --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 1ad258660..c22df2ec7 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011192344-249709ce7115 github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index c94f71c21..4a848a54d 100644 --- a/go.sum +++ b/go.sum @@ -85,6 +85,8 @@ github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a h1:xd2RUTW9w34+V6yI7zWfByHZ8y5CeXhvHK+nAJ9FCbI= github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011192344-249709ce7115 h1:cgEHfZ1UFdVpFxv6zkJOt3pKXjLJceXYPM3pjBoxk0w= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011192344-249709ce7115/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f h1:YUQF1wQJeEcTMC5W/OrwgSFTFMS4zeCM8O02rLeEDow= From ea9d1b976d3b1ea4647bf8d1d55f0e15291fe21e Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Fri, 11 Oct 2024 16:51:09 -0300 Subject: [PATCH 30/57] so less flags --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c22df2ec7..748c6e56f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011192344-249709ce7115 + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011195013-51e7833ea2da github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index 4a848a54d..6cc97d446 100644 --- a/go.sum +++ b/go.sum @@ -87,6 +87,8 @@ github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011192344-249709ce7115 h1:cgEHfZ1UFdVpFxv6zkJOt3pKXjLJceXYPM3pjBoxk0w= github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011192344-249709ce7115/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011195013-51e7833ea2da h1:goZVOXxAu47xw2zasimAA0tuAWdiABtjlSwsImDeTL8= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011195013-51e7833ea2da/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f h1:YUQF1wQJeEcTMC5W/OrwgSFTFMS4zeCM8O02rLeEDow= From 02f02abcb4da4f4e503200c0ed543ee477b27939 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Fri, 11 Oct 2024 18:28:35 -0300 Subject: [PATCH 31/57] add back fast boot time --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 748c6e56f..593f8cee6 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011195013-51e7833ea2da + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011212742-1488ec257737 github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index 6cc97d446..5240f93f3 100644 --- a/go.sum +++ b/go.sum @@ -89,6 +89,8 @@ github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011192344-249709ce711 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011192344-249709ce7115/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011195013-51e7833ea2da h1:goZVOXxAu47xw2zasimAA0tuAWdiABtjlSwsImDeTL8= github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011195013-51e7833ea2da/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011212742-1488ec257737 h1:CtUvsh0cUk72KutaVSVAphg/AYdeVJnptj2Ze1REY54= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011212742-1488ec257737/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f h1:YUQF1wQJeEcTMC5W/OrwgSFTFMS4zeCM8O02rLeEDow= From 27ecc41de3b4bcbd2aaceb4387ad2d6e3b7e7f09 Mon Sep 17 00:00:00 2001 From: arturrez <56270896+arturrez@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:12:08 -0700 Subject: [PATCH 32/57] add checks for local cluster. minor refactor (#2239) * add checks for local cluster minor refactoring * fix test * addressed Felipe feedback --------- Signed-off-by: arturrez <56270896+arturrez@users.noreply.github.com> --- cmd/nodecmd/add_dashboard.go | 7 +++++ cmd/nodecmd/create.go | 46 ++++++++++++++--------------- cmd/nodecmd/create_gcp.go | 27 +++++++---------- cmd/nodecmd/deploy.go | 7 +++-- cmd/nodecmd/destroy.go | 48 ++++++++++++------------------- cmd/nodecmd/import.go | 11 ++++--- cmd/nodecmd/list.go | 11 ++----- cmd/nodecmd/load_test_start.go | 16 +++++------ cmd/nodecmd/load_test_stop.go | 30 ++++++------------- cmd/nodecmd/local.go | 16 ++++++----- cmd/nodecmd/resize.go | 7 +++++ cmd/nodecmd/scp.go | 29 ++++++++++--------- cmd/nodecmd/ssh.go | 16 ++++++----- cmd/nodecmd/status.go | 5 ++++ cmd/nodecmd/update_subnet.go | 3 ++ cmd/nodecmd/upgrade.go | 3 ++ cmd/nodecmd/validate_primary.go | 3 ++ cmd/nodecmd/validate_subnet.go | 3 ++ cmd/nodecmd/whitelist.go | 8 ++++++ internal/mocks/process_checker.go | 2 +- pkg/application/app.go | 17 ++++++----- pkg/subnet/local_test.go | 2 +- 22 files changed, 163 insertions(+), 154 deletions(-) diff --git a/cmd/nodecmd/add_dashboard.go b/cmd/nodecmd/add_dashboard.go index a683e8928..6de90bf64 100644 --- a/cmd/nodecmd/add_dashboard.go +++ b/cmd/nodecmd/add_dashboard.go @@ -28,6 +28,13 @@ cluster.`, func addDashboard(_ *cobra.Command, args []string) error { clusterName := args[0] + clusterConfig, err := app.GetClusterConfig(clusterName) + if err != nil { + return err + } + if clusterConfig.Local { + return notImplementedForLocal("addDashboard") + } if customGrafanaDashboardPath != "" { if err := addCustomDashboard(clusterName, blockchainName); err != nil { return err diff --git a/cmd/nodecmd/create.go b/cmd/nodecmd/create.go index 2782cb0ca..10e911909 100644 --- a/cmd/nodecmd/create.go +++ b/cmd/nodecmd/create.go @@ -199,7 +199,14 @@ func preCreateChecks(clusterName string) error { if err := failForExternal(clusterName); err != nil { return err } - + // check for local + clusterConfig, err := app.GetClusterConfig(clusterName) + if err != nil { + return err + } + if clusterConfig.Local { + return notImplementedForLocal("addDashboard") + } return nil } @@ -833,28 +840,21 @@ func saveExternalHostConfig(externalHostConfig models.RegionConfig, hostRegion, } func getExistingMonitoringInstance(clusterName string) (string, error) { - if app.ClustersConfigExists() { - clustersConfig, err := app.LoadClustersConfig() - if err != nil { - return "", err - } - if _, ok := clustersConfig.Clusters[clusterName]; ok { - if clustersConfig.Clusters[clusterName].MonitoringInstance != "" { - return clustersConfig.Clusters[clusterName].MonitoringInstance, nil - } - } + // check for local + clusterConfig, err := app.GetClusterConfig(clusterName) + if err != nil { + return "", err + } + if clusterConfig.MonitoringInstance != "" { + return clusterConfig.MonitoringInstance, nil } return "", nil } func updateKeyPairClustersConfig(cloudConfig models.NodeConfig) error { - clustersConfig := models.ClustersConfig{} - var err error - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } if clustersConfig.KeyPair == nil { clustersConfig.KeyPair = make(map[string]string) @@ -887,13 +887,9 @@ func getNodeCloudConfig(node string) (models.RegionConfig, string, error) { } func addNodeToClustersConfig(network models.Network, nodeID, clusterName string, isAPIInstance bool, isExternalHost bool, nodeRole, loadTestName string) error { - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - var err error - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } if clustersConfig.Clusters == nil { clustersConfig.Clusters = make(map[string]models.ClusterConfig) diff --git a/cmd/nodecmd/create_gcp.go b/cmd/nodecmd/create_gcp.go index 9bbad62bf..6db5241b3 100644 --- a/cmd/nodecmd/create_gcp.go +++ b/cmd/nodecmd/create_gcp.go @@ -53,16 +53,13 @@ func getGCPCloudCredentials() (*compute.Service, string, string, error) { var err error var gcpCredentialsPath string var gcpProjectName string - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return nil, "", "", err - } - if clustersConfig.GCPConfig != (models.GCPConfig{}) { - gcpProjectName = clustersConfig.GCPConfig.ProjectName - gcpCredentialsPath = clustersConfig.GCPConfig.ServiceAccFilePath - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return nil, "", "", err + } + if clustersConfig.GCPConfig != (models.GCPConfig{}) { + gcpProjectName = clustersConfig.GCPConfig.ProjectName + gcpCredentialsPath = clustersConfig.GCPConfig.ServiceAccFilePath } if gcpProjectName == "" { if cmdLineGCPProjectName != "" { @@ -380,13 +377,9 @@ func createGCPInstance( } func updateClustersConfigGCPKeyFilepath(projectName, serviceAccountKeyFilepath string) error { - clustersConfig := models.ClustersConfig{} - var err error - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } if projectName != "" { clustersConfig.GCPConfig.ProjectName = projectName diff --git a/cmd/nodecmd/deploy.go b/cmd/nodecmd/deploy.go index 1ba839e58..41275c8fe 100644 --- a/cmd/nodecmd/deploy.go +++ b/cmd/nodecmd/deploy.go @@ -47,11 +47,14 @@ func deploySubnet(cmd *cobra.Command, args []string) error { if _, err := blockchaincmd.ValidateSubnetNameAndGetChains([]string{subnetName}); err != nil { return err } - clustersConfig, err := app.LoadClustersConfig() + clusterConfig, err := app.GetClusterConfig(clusterName) if err != nil { return err } - if clustersConfig.Clusters[clusterName].Network.Kind != models.Devnet { + if clusterConfig.Local { + return notImplementedForLocal("deploy") + } + if clusterConfig.Network.Kind != models.Devnet { return fmt.Errorf("node deploy command must be applied to devnet clusters") } hosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName)) diff --git a/cmd/nodecmd/destroy.go b/cmd/nodecmd/destroy.go index f62f11fa3..b7e58f9db 100644 --- a/cmd/nodecmd/destroy.go +++ b/cmd/nodecmd/destroy.go @@ -12,7 +12,6 @@ import ( gcpAPI "github.com/ava-labs/avalanche-cli/pkg/cloud/gcp" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/constants" - "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" "golang.org/x/exp/maps" @@ -49,13 +48,9 @@ If there is a static IP address attached, it will be released.`, } func removeNodeFromClustersConfig(clusterName string) error { - clustersConfig := models.ClustersConfig{} - var err error - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } if clustersConfig.Clusters != nil { delete(clustersConfig.Clusters, clusterName) @@ -124,13 +119,9 @@ func getFirstAvailableNode(nodesToStop []string) (string, bool) { } func Cleanup() error { - var err error - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } clusterNames := maps.Keys(clustersConfig.Clusters) for _, clusterName := range clusterNames { @@ -158,6 +149,13 @@ func destroyNodes(_ *cobra.Command, args []string) error { if err := checkCluster(clusterName); err != nil { return err } + clusterConfig, err := app.GetClusterConfig(clusterName) + if err != nil { + return err + } + if clusterConfig.Local { + return notImplementedForLocal("destroy") + } isExternalCluster, err := checkClusterExternal(clusterName) if err != nil { return err @@ -315,13 +313,9 @@ func destroyNodes(_ *cobra.Command, args []string) error { } func getClusterMonitoringNode(clusterName string) (string, error) { - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - var err error - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return "", err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return "", err } if _, ok := clustersConfig.Clusters[clusterName]; !ok { return "", fmt.Errorf("cluster %q does not exist", clusterName) @@ -335,13 +329,9 @@ func checkCluster(clusterName string) error { } func checkClusterExists(clusterName string) (bool, error) { - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - var err error - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return false, err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return false, err } _, ok := clustersConfig.Clusters[clusterName] return ok, nil diff --git a/cmd/nodecmd/import.go b/cmd/nodecmd/import.go index e3c397653..e5b0975f2 100644 --- a/cmd/nodecmd/import.go +++ b/cmd/nodecmd/import.go @@ -109,13 +109,12 @@ func importFile(_ *cobra.Command, args []string) error { // add cluster clustersConfig := models.ClustersConfig{} clustersConfig.Clusters = make(map[string]models.ClusterConfig) - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - ux.Logger.RedXToUser("error loading clusters config: %v", err) - return err - } + clustersConfig, err = app.GetClustersConfig() + if err != nil { + ux.Logger.RedXToUser("error loading clusters config: %v", err) + return err } + importCluster.ClusterConfig.Network.ClusterName = clusterName clustersConfig.Clusters[clusterName] = importCluster.ClusterConfig if err := app.WriteClustersConfigFile(&clustersConfig); err != nil { diff --git a/cmd/nodecmd/list.go b/cmd/nodecmd/list.go index 130f70edf..0a4902b58 100644 --- a/cmd/nodecmd/list.go +++ b/cmd/nodecmd/list.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" - "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/spf13/cobra" @@ -29,13 +28,9 @@ The node list command lists all clusters together with their nodes.`, } func list(_ *cobra.Command, _ []string) error { - var err error - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } if len(clustersConfig.Clusters) == 0 { ux.Logger.PrintToUser("There are no clusters defined.") diff --git a/cmd/nodecmd/load_test_start.go b/cmd/nodecmd/load_test_start.go index dea2296d1..35c5f8d0d 100644 --- a/cmd/nodecmd/load_test_start.go +++ b/cmd/nodecmd/load_test_start.go @@ -522,15 +522,13 @@ func GetLoadTestScript(app *application.Avalanche) error { } func getExistingLoadTestInstance(clusterName, loadTestName string) (string, error) { - if app.ClustersConfigExists() { - clustersConfig, err := app.LoadClustersConfig() - if err != nil { - return "", err - } - if _, ok := clustersConfig.Clusters[clusterName]; ok { - if _, loadTestExists := clustersConfig.Clusters[clusterName].LoadTestInstance[loadTestName]; loadTestExists { - return clustersConfig.Clusters[clusterName].LoadTestInstance[loadTestName], nil - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return "", err + } + if _, ok := clustersConfig.Clusters[clusterName]; ok { + if _, loadTestExists := clustersConfig.Clusters[clusterName].LoadTestInstance[loadTestName]; loadTestExists { + return clustersConfig.Clusters[clusterName].LoadTestInstance[loadTestName], nil } } return "", nil diff --git a/cmd/nodecmd/load_test_stop.go b/cmd/nodecmd/load_test_stop.go index 8c5f42fbb..62ab1b8f4 100644 --- a/cmd/nodecmd/load_test_stop.go +++ b/cmd/nodecmd/load_test_stop.go @@ -40,13 +40,9 @@ separate cloud server created to host the load test.`, } func getLoadTestInstancesInCluster(clusterName string) ([]string, error) { - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - var err error - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return nil, err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return nil, err } if _, ok := clustersConfig.Clusters[clusterName]; !ok { return nil, fmt.Errorf("cluster %s doesn't exist", clusterName) @@ -58,13 +54,9 @@ func getLoadTestInstancesInCluster(clusterName string) ([]string, error) { } func checkLoadTestExists(clusterName, loadTestName string) (bool, error) { - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - var err error - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return false, err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return false, err } if _, ok := clustersConfig.Clusters[clusterName]; !ok { return false, fmt.Errorf("cluster %s doesn't exist", clusterName) @@ -252,13 +244,9 @@ func destroyNode(node, clusterName, loadTestName string, ec2Svc *awsAPI.AwsCloud } func removeLoadTestNodeFromClustersConfig(clusterName, loadTestName string) error { - clustersConfig := models.ClustersConfig{} - var err error - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } if clustersConfig.Clusters != nil { if _, ok := clustersConfig.Clusters[clusterName]; !ok { diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 6a6d02d7b..bbdd4d4cd 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -19,6 +19,7 @@ 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" "github.com/spf13/cobra" ) @@ -446,13 +447,9 @@ func addLocalClusterConfig(network models.Network) error { } func checkClusterIsLocal(clusterName string) (bool, error) { - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - var err error - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return false, err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return false, err } clusterConf, ok := clustersConfig.Clusters[clusterName] return ok && clusterConf.Local, nil @@ -535,3 +532,8 @@ func localTrack(_ *cobra.Command, args []string) error { ux.Logger.GreenCheckmarkToUser("%s successfully tracking %s", clusterName, blockchainName) return nil } + +func notImplementedForLocal(what string) error { + ux.Logger.PrintToUser("Unsupported cmd: %s is not supported by local clusters", logging.LightBlue.Wrap(what)) + return nil +} diff --git a/cmd/nodecmd/resize.go b/cmd/nodecmd/resize.go index fe67b1557..a486d0f82 100644 --- a/cmd/nodecmd/resize.go +++ b/cmd/nodecmd/resize.go @@ -56,6 +56,13 @@ func preResizeChecks(clusterName string) error { if err := failForExternal(clusterName); err != nil { return fmt.Errorf("cannot resize external cluster %s", clusterName) } + clusterConfig, err := app.GetClusterConfig(clusterName) + if err != nil { + return err + } + if clusterConfig.Local { + return notImplementedForLocal("resize") + } return nil } diff --git a/cmd/nodecmd/scp.go b/cmd/nodecmd/scp.go index 44f6fc55b..3149d0314 100644 --- a/cmd/nodecmd/scp.go +++ b/cmd/nodecmd/scp.go @@ -55,13 +55,9 @@ $ avalanche node scp node1:/tmp/file.txt NodeID-XXXX:/tmp/file.txt } func scpNode(_ *cobra.Command, args []string) error { - var err error - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } if len(clustersConfig.Clusters) == 0 { ux.Logger.PrintToUser("There are no clusters defined.") @@ -84,6 +80,15 @@ func scpNode(_ *cobra.Command, args []string) error { if sourceClusterExists && destClusterExists { return fmt.Errorf("both source and destination cannot be clusters") } + sourceClusterConfig := clustersConfig.Clusters[sourceClusterNameOrNodeID] + if sourceClusterExists && sourceClusterConfig.Local { + return notImplementedForLocal("scp") + } + + destClusterConfig := clustersConfig.Clusters[destClusterNameOrNodeID] + if destClusterExists && destClusterConfig.Local { + return notImplementedForLocal("scp") + } switch { case sourceClusterExists: @@ -245,13 +250,9 @@ func prepareSCPTarget(op ClusterOp, host *models.Host, clusterName string, dest // getHostClusterPair returns the host and cluster name for the given node or cloudID func getHostClusterPair(nodeOrCloudIDOrIP string) (*models.Host, string) { - var err error - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return nil, "" - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return nil, "" } for clusterName := range clustersConfig.Clusters { clusterHosts, err := GetAllClusterHosts(clusterName) diff --git a/cmd/nodecmd/ssh.go b/cmd/nodecmd/ssh.go index b3b8d33b5..6d6dd8278 100644 --- a/cmd/nodecmd/ssh.go +++ b/cmd/nodecmd/ssh.go @@ -48,13 +48,9 @@ If no [cmd] is provided for the node, it will open ssh shell there. } func sshNode(_ *cobra.Command, args []string) error { - var err error - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return err } if len(clustersConfig.Clusters) == 0 { ux.Logger.PrintToUser("There are no clusters defined.") @@ -63,6 +59,9 @@ func sshNode(_ *cobra.Command, args []string) error { if len(args) == 0 { // provide ssh connection string for all clusters for clusterName, clusterConfig := range clustersConfig.Clusters { + if clusterConfig.Local { + continue + } err := printClusterConnectionString(clusterName, clusterConfig.Network.Kind.String()) if err != nil { return err @@ -77,6 +76,9 @@ func sshNode(_ *cobra.Command, args []string) error { if len(args[1:]) == 0 { return printClusterConnectionString(clusterNameOrNodeID, clustersConfig.Clusters[clusterNameOrNodeID].Network.Kind.String()) } else { + if clustersConfig.Clusters[clusterNameOrNodeID].Local { + return notImplementedForLocal("ssh") + } clusterHosts, err := GetAllClusterHosts(clusterNameOrNodeID) if err != nil { return err diff --git a/cmd/nodecmd/status.go b/cmd/nodecmd/status.go index dc499cc18..47273d4ca 100644 --- a/cmd/nodecmd/status.go +++ b/cmd/nodecmd/status.go @@ -57,6 +57,10 @@ func statusNode(_ *cobra.Command, args []string) error { if err != nil { return err } + // local cluster doesn't have nodes + if clusterConf.Local { + return notImplementedForLocal("status") + } var blockchainID ids.ID if blockchainName != "" { sc, err := app.LoadSidecar(blockchainName) @@ -68,6 +72,7 @@ func statusNode(_ *cobra.Command, args []string) error { return ErrNoBlockchainID } } + hostIDs := utils.Filter(clusterConf.GetCloudIDs(), clusterConf.IsAvalancheGoHost) nodeIDs, err := utils.MapWithError(hostIDs, func(s string) (string, error) { n, err := getNodeID(app.GetNodeInstanceDirPath(s)) diff --git a/cmd/nodecmd/update_subnet.go b/cmd/nodecmd/update_subnet.go index 810aaf5c0..0590bacaf 100644 --- a/cmd/nodecmd/update_subnet.go +++ b/cmd/nodecmd/update_subnet.go @@ -41,6 +41,9 @@ func updateSubnet(_ *cobra.Command, args []string) error { if err != nil { return err } + if clusterConfig.Local { + return notImplementedForLocal("update") + } if _, err := blockchaincmd.ValidateSubnetNameAndGetChains([]string{subnetName}); err != nil { return err } diff --git a/cmd/nodecmd/upgrade.go b/cmd/nodecmd/upgrade.go index 0a8d3200a..9600c57c3 100644 --- a/cmd/nodecmd/upgrade.go +++ b/cmd/nodecmd/upgrade.go @@ -54,6 +54,9 @@ func upgrade(_ *cobra.Command, args []string) error { if err != nil { return err } + if clusterConfig.Local { + return notImplementedForLocal("upgrade") + } network := clusterConfig.Network hosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName)) if err != nil { diff --git a/cmd/nodecmd/validate_primary.go b/cmd/nodecmd/validate_primary.go index 44f1f8fec..ff8555f95 100644 --- a/cmd/nodecmd/validate_primary.go +++ b/cmd/nodecmd/validate_primary.go @@ -295,6 +295,9 @@ func validatePrimaryNetwork(_ *cobra.Command, args []string) error { if err != nil { return err } + if clusterConfig.Local { + return notImplementedForLocal("validate primary") + } network := clusterConfig.Network allHosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName)) diff --git a/cmd/nodecmd/validate_subnet.go b/cmd/nodecmd/validate_subnet.go index 552115426..3a200a30d 100644 --- a/cmd/nodecmd/validate_subnet.go +++ b/cmd/nodecmd/validate_subnet.go @@ -184,6 +184,9 @@ func validateSubnet(_ *cobra.Command, args []string) error { if err != nil { return err } + if clusterConfig.Local { + return notImplementedForLocal("validate subnet") + } network := clusterConfig.Network allHosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName)) diff --git a/cmd/nodecmd/whitelist.go b/cmd/nodecmd/whitelist.go index d7ec66172..d3b954224 100644 --- a/cmd/nodecmd/whitelist.go +++ b/cmd/nodecmd/whitelist.go @@ -68,6 +68,14 @@ func whitelist(_ *cobra.Command, args []string) error { return err } + clustersConfig, err := app.LoadClustersConfig() + if err != nil { + return err + } + clusterConfig := clustersConfig.Clusters[clusterName] + if clusterConfig.Local { + return notImplementedForLocal("whitelist") + } if discoverIP { userIPAddress, err = utils.GetUserIPAddress() if err != nil { diff --git a/internal/mocks/process_checker.go b/internal/mocks/process_checker.go index 2398cd337..884ae855d 100644 --- a/internal/mocks/process_checker.go +++ b/internal/mocks/process_checker.go @@ -14,7 +14,7 @@ type ProcessChecker struct { } // IsServerProcessRunning provides a mock function with given fields: app -func (_m *ProcessChecker) IsServerProcessRunning(app *application.Avalanche) (bool, error) { +func (_m *ProcessChecker) IsServerProcessRunning(app *application.Avalanche, _ string) (bool, error) { ret := _m.Called(app) if len(ret) == 0 { diff --git a/pkg/application/app.go b/pkg/application/app.go index 22dc227c1..5bb70ca33 100644 --- a/pkg/application/app.go +++ b/pkg/application/app.go @@ -689,6 +689,13 @@ func (app *Avalanche) LoadClustersConfig() (models.ClustersConfig, error) { return models.ClustersConfig{}, fmt.Errorf("unsupported clusters config version %s", v) } +func (app *Avalanche) GetClustersConfig() (models.ClustersConfig, error) { + if app.ClustersConfigExists() { + return app.LoadClustersConfig() + } + return models.ClustersConfig{}, nil +} + func (app *Avalanche) WriteClustersConfigFile(clustersConfig *models.ClustersConfig) error { clustersConfigPath := app.GetClustersConfigPath() if err := os.MkdirAll(filepath.Dir(clustersConfigPath), constants.DefaultPerms755); err != nil { @@ -787,13 +794,9 @@ func (app *Avalanche) SetupMonitoringEnv() error { } func (app *Avalanche) ClusterExists(clusterName string) (bool, error) { - clustersConfig := models.ClustersConfig{} - if app.ClustersConfigExists() { - var err error - clustersConfig, err = app.LoadClustersConfig() - if err != nil { - return false, err - } + clustersConfig, err := app.GetClustersConfig() + if err != nil { + return false, err } _, ok := clustersConfig.Clusters[clusterName] return ok, nil diff --git a/pkg/subnet/local_test.go b/pkg/subnet/local_test.go index e136286ba..8f3f159c4 100644 --- a/pkg/subnet/local_test.go +++ b/pkg/subnet/local_test.go @@ -143,7 +143,7 @@ func TestDeployToLocal(t *testing.T) { icmSpec := ICMSpec{ SkipICMDeploy: true, } - deployInfo, err := testDeployer.DeployToLocalNetwork(testChainName, testGenesis.Name(), icmSpec, "") + deployInfo, err := testDeployer.DeployToLocalNetwork(testChainName, testGenesis.Name(), icmSpec, "", "") require.NoError(err) require.Equal(testSubnetID2, deployInfo.SubnetID.String()) require.Equal(testBlockChainID2, deployInfo.BlockchainID.String()) From 046ccb69a1d1fc4b5689e1005e8420c8ba7693cc Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Sat, 12 Oct 2024 11:10:37 -0300 Subject: [PATCH 33/57] bump anr --- cmd/nodecmd/local.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index bbdd4d4cd..8fd29f025 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -325,7 +325,7 @@ func localStartNode(_ *cobra.Command, args []string) error { client.WithReassignPortsIfUsed(true), client.WithPluginDir(pluginDir), client.WithFreshStakingIds(true), - client.WithZeroIPIfPublicHTTPHost(false), + client.WithZeroIP(false), } if genesisPath != "" && utils.FileExists(genesisPath) { anrOpts = append(anrOpts, client.WithGenesisPath(genesisPath)) diff --git a/go.mod b/go.mod index e52bdf4c8..d28047098 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011223834-4c23cb10c23b + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241012120846-016fa62d1f70 github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index 9ee43b856..254aa363c 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011223834-4c23cb10c23b h1:fb0xrWKeQCSibMbMAW+a/88IDZqUIIBl4YK6R3S1m/k= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241011223834-4c23cb10c23b/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241012120846-016fa62d1f70 h1:t+d9CHpX7kKuC/LD7HjCYlcGn2ztA/deBJJS+aJL9NA= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241012120846-016fa62d1f70/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 h1:M58jcqAG51RrKKVCfhAZpPqCFdkqRzahEgkFqQA5EME= From f134935533c6c832b4067438e959f9d635dbf84c Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Sat, 12 Oct 2024 12:28:25 -0300 Subject: [PATCH 34/57] fixes for convert flow --- cmd/contractcmd/init_poa_validator_manager.go | 14 +++++++++----- pkg/contract/chain.go | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index 3bd5adc2b..6e962a657 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -31,7 +31,8 @@ var ( networkoptions.Devnet, networkoptions.Fuji, } - initPOAManagerFlags InitPOAManagerFlags + initPOAManagerFlags InitPOAManagerFlags + privateAggregatorEndpoints []string ) // avalanche contract initpoamanager @@ -46,6 +47,7 @@ func newInitPOAManagerCmd() *cobra.Command { networkoptions.AddNetworkFlagsToCmd(cmd, &initPOAManagerFlags.Network, true, initPOAManagerSupportedNetworkOptions) initPOAManagerFlags.PrivateKeyFlags.AddToCmd(cmd, "as contract deployer") cmd.Flags().StringVar(&initPOAManagerFlags.rpcEndpoint, "rpc", "", "deploy the contract into the given rpc endpoint") + cmd.Flags().StringSliceVar(&privateAggregatorEndpoints, "private-aggregator-endpoints", nil, "endpoints for private nodes that are not available as network peers but are needed in signature aggregation") return cmd } @@ -116,9 +118,11 @@ func initPOAManager(_ *cobra.Command, args []string) error { if err != nil { return err } - aggregatorExtraPeerEndpoints, err := blockchaincmd.GetAggregatorExtraPeerEndpoints(network) - if err != nil { - return err + if len(privateAggregatorEndpoints) == 0 { + privateAggregatorEndpoints, err = blockchaincmd.GetAggregatorExtraPeerEndpoints(network) + if err != nil { + return err + } } if err := validatormanager.SetupPoA( app, @@ -128,7 +132,7 @@ func initPOAManager(_ *cobra.Command, args []string) error { privateKey, common.HexToAddress(sc.PoAValidatorManagerOwner), avaGoBootstrapValidators, - aggregatorExtraPeerEndpoints, + privateAggregatorEndpoints, ); err != nil { return err } diff --git a/pkg/contract/chain.go b/pkg/contract/chain.go index 9631aa717..584667dd0 100644 --- a/pkg/contract/chain.go +++ b/pkg/contract/chain.go @@ -119,7 +119,7 @@ func GetBlockchainEndpoints( case chainSpec.CChain: rpcEndpoint = network.CChainEndpoint() wsEndpoint = network.CChainWSEndpoint() - case network.Kind == models.Local || network.Kind == models.Devnet: + case network.Kind == models.Local: blockchainID, err := GetBlockchainID(app, network, chainSpec) if err != nil { return "", "", err From 719aea1c870652c77b730b331b96d8cb3e13bc4e Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Sun, 13 Oct 2024 03:28:32 -0300 Subject: [PATCH 35/57] add check for already initialized error on PoA init --- cmd/blockchaincmd/create.go | 2 +- cmd/networkcmd/start.go | 1 + cmd/nodecmd/local.go | 30 +++++++-- pkg/binutils/processes.go | 14 +++-- pkg/contract/contract.go | 51 ++++++++++++++++ pkg/evm/evm.go | 78 ++++++++++++++++++++++++ pkg/subnet/local.go | 11 +++- pkg/validatormanager/validatormanager.go | 47 ++++++++++---- 8 files changed, 212 insertions(+), 22 deletions(-) diff --git a/cmd/blockchaincmd/create.go b/cmd/blockchaincmd/create.go index b5d44935c..456491938 100644 --- a/cmd/blockchaincmd/create.go +++ b/cmd/blockchaincmd/create.go @@ -113,7 +113,7 @@ configuration, pass the -f flag.`, cmd.Flags().BoolVar(&createFlags.proofOfStake, "proof-of-stake", false, "(coming soon) use proof of stake for validator management") cmd.Flags().StringVar(&createFlags.poaValidatorManagerOwner, "poa-manager-owner", "", "EVM address that controls Validator Manager Owner (for Proof of Authority only)") cmd.Flags().BoolVar(&sovereign, "sovereign", true, "set to false if creating non-sovereign blockchain") - cmd.Flags().BoolVar(&createFlags.enableDebugging, "debug", false, "enable blockchain debugging") + cmd.Flags().BoolVar(&createFlags.enableDebugging, "debug", true, "enable blockchain debugging") return cmd } diff --git a/cmd/networkcmd/start.go b/cmd/networkcmd/start.go index 6d9f1bf81..c7fa95358 100644 --- a/cmd/networkcmd/start.go +++ b/cmd/networkcmd/start.go @@ -71,6 +71,7 @@ func StartNetwork(*cobra.Command, []string) error { binutils.LocalNetworkGRPCServerPort, binutils.LocalNetworkGRPCGatewayPort, app.GetSnapshotsDir(), + "", ); err != nil { return err } diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 8fd29f025..7e3ea6c8f 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -182,7 +182,7 @@ func localStartNode(_ *cobra.Command, args []string) error { // check if this is existing cluster rootDir := app.GetLocalDir(clusterName) - pluginDir := app.GetPluginsDir() + pluginDir := filepath.Join(rootDir, "node1", "plugins") ctx, cancel := utils.GetANRContext() defer cancel() @@ -196,12 +196,14 @@ func localStartNode(_ *cobra.Command, args []string) error { ux.Logger.PrintToUser("Using AvalancheGo version: %s", avalancheGoVersion) } } + serverLogPath := filepath.Join(rootDir, "server.log") sd := subnet.NewLocalDeployer(app, avalancheGoVersion, avalanchegoBinaryPath, "") if err := sd.StartServer( constants.ServerRunFileLocalClusterPrefix, binutils.LocalClusterGRPCServerPort, binutils.LocalClusterGRPCGatewayPort, rootDir, + serverLogPath, ); err != nil { return err } @@ -301,6 +303,10 @@ func localStartNode(_ *cobra.Command, args []string) error { if err := os.MkdirAll(rootDir, 0o700); err != nil { return fmt.Errorf("could not create root directory %s: %w", rootDir, err) } + // make sure pluginDir exists + if err := os.MkdirAll(pluginDir, 0o700); err != nil { + return fmt.Errorf("could not create plugin directory %s: %w", pluginDir, err) + } if stakingTLSKeyPath != "" && stakingCertKeyPath != "" && stakingSignerKeyPath != "" { if err := os.MkdirAll(filepath.Join(rootDir, "node1", "staking"), 0o700); err != nil { @@ -475,7 +481,8 @@ func localTrack(_ *cobra.Command, args []string) error { return fmt.Errorf("blockchain %s has not been deployed to %s", blockchainName, network.Name()) } subnetID := sc.Networks[network.Name()].SubnetID - chainVMID, err := anrutils.VMID(blockchainName) + blockchainID := sc.Networks[network.Name()].BlockchainID + vmID, err := anrutils.VMID(blockchainName) if err != nil { return fmt.Errorf("failed to create VM ID from %s: %w", blockchainName, err) } @@ -491,10 +498,25 @@ func localTrack(_ *cobra.Command, args []string) error { default: return fmt.Errorf("unknown vm: %s", sc.VM) } - binaryDownloader := binutils.NewPluginBinaryDownloader(app) - if err := binaryDownloader.InstallVM(chainVMID.String(), vmBin); err != nil { + rootDir := app.GetLocalDir(clusterName) + pluginPath := filepath.Join(rootDir, "node1", "plugins", vmID.String()) + if err := utils.FileCopy(vmBin, pluginPath); err != nil { return err } + if err := os.Chmod(pluginPath, constants.DefaultPerms755); err != nil { + return err + } + if app.ChainConfigExists(blockchainName) { + inputChainConfigPath := app.GetChainConfigPath(blockchainName) + outputChainConfigPath := filepath.Join(rootDir, "node1", "configs", "chains", blockchainID.String(), "config.json") + if err := os.MkdirAll(filepath.Dir(outputChainConfigPath), 0o700); err != nil { + return fmt.Errorf("could not create chain conf directory %s: %w", filepath.Dir(outputChainConfigPath), err) + } + if err := utils.FileCopy(inputChainConfigPath, outputChainConfigPath); err != nil { + return err + } + } + cli, err := binutils.NewGRPCClientWithEndpoint( binutils.LocalClusterGRPCServerEndpoint, binutils.WithAvoidRPCVersionCheck(true), diff --git a/pkg/binutils/processes.go b/pkg/binutils/processes.go index 0fc5a7163..0abea5b54 100644 --- a/pkg/binutils/processes.go +++ b/pkg/binutils/processes.go @@ -225,6 +225,7 @@ func StartServerProcess( serverPort string, gatewayPort string, snapshotsDir string, + logPath string, ) error { thisBin := reexec.Self() @@ -239,13 +240,16 @@ func StartServerProcess( } cmd := exec.Command(thisBin, args...) - outputDirPrefix := path.Join(app.GetRunDir(), prefix+"server") - outputDir, err := anrutils.MkDirWithTimestamp(outputDirPrefix) - if err != nil { - return err + if logPath == "" { + outputDirPrefix := path.Join(app.GetRunDir(), prefix+"server") + outputDir, err := anrutils.MkDirWithTimestamp(outputDirPrefix) + if err != nil { + return err + } + logPath = path.Join(outputDir, "avalanche-cli-backend.log") } - outputFile, err := os.Create(path.Join(outputDir, "avalanche-cli-backend.log")) + outputFile, err := os.Create(logPath) if err != nil { return err } diff --git a/pkg/contract/contract.go b/pkg/contract/contract.go index a2f3eccc3..483551ca5 100644 --- a/pkg/contract/contract.go +++ b/pkg/contract/contract.go @@ -4,6 +4,7 @@ package contract import ( _ "embed" + "encoding/hex" "encoding/json" "fmt" "math/big" @@ -16,6 +17,8 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" "github.com/ava-labs/subnet-evm/core/types" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/crypto" ) var ErrFailedReceiptStatus = fmt.Errorf("failed receipt status") @@ -387,6 +390,54 @@ func TxToMethodWithWarpMessage( return tx, receipt, nil } +func DebugTraceCall( + rpcURL string, + privateKey string, + contractAddress common.Address, + payment *big.Int, + methodSpec string, + params ...interface{}, +) (map[string]interface{}, error) { + methodName, methodABI, err := ParseSpec(methodSpec, nil, false, false, false, false, params...) + if err != nil { + return nil, err + } + metadata := &bind.MetaData{ + ABI: methodABI, + } + abi, err := metadata.GetAbi() + if err != nil { + return nil, err + } + callData, err := abi.Pack(methodName, params...) + if err != nil { + return nil, err + } + client, err := evm.GetRPCClient(rpcURL) + if err != nil { + return nil, err + } + defer client.Close() + pk, err := crypto.HexToECDSA(privateKey) + if err != nil { + return nil, err + } + from := crypto.PubkeyToAddress(pk.PublicKey) + data := map[string]string{ + "from": from.Hex(), + "to": contractAddress.Hex(), + "input": "0x" + hex.EncodeToString(callData), + } + if payment != nil { + hexBytes, _ := hexutil.Big(*payment).MarshalText() + data["value"] = string(hexBytes) + } + return evm.DebugTraceCall( + client, + data, + ) +} + func CallToMethod( rpcURL string, contractAddress common.Address, diff --git a/pkg/evm/evm.go b/pkg/evm/evm.go index 8269fd6c6..20868d9e4 100644 --- a/pkg/evm/evm.go +++ b/pkg/evm/evm.go @@ -5,8 +5,10 @@ package evm import ( "context" "crypto/ecdsa" + "encoding/hex" "fmt" "math/big" + "strings" "time" "github.com/ava-labs/avalanche-cli/pkg/utils" @@ -487,6 +489,40 @@ func DebugTraceTransaction( return trace, err } +func DebugTraceCall( + client *rpc.Client, + toTrace map[string]string, +) (map[string]interface{}, error) { + var ( + err error + trace map[string]interface{} + ) + for i := 0; i < repeatsOnFailure; i++ { + ctx, cancel := utils.GetAPILargeContext() + defer cancel() + err = client.CallContext( + ctx, + &trace, + "debug_traceCall", + toTrace, + "latest", + map[string]interface{}{ + "tracer": "callTracer", + "tracerConfig": map[string]interface{}{ + "onlyTopCall": false, + }, + }, + ) + if err == nil { + break + } + err = fmt.Errorf("failure tracing call for client %#v: %w", client, err) + ux.Logger.RedXToUser("%s", err) + time.Sleep(sleepBetweenRepeats) + } + return trace, err +} + func GetTrace(rpcURL string, txID string) (map[string]interface{}, error) { client, err := GetRPCClient(rpcURL) if err != nil { @@ -607,3 +643,45 @@ func WaitForNewBlock( } return fmt.Errorf("new block not produced in %f seconds", totalDuration.Seconds()) } + +func GetFunctionSelector(functionSignature string) string { + return "0x" + hex.EncodeToString(crypto.Keccak256([]byte(functionSignature))[:4]) +} + +func GetErrorFromTrace( + trace map[string]interface{}, + functionSignatureToError map[string]error, +) (error, error) { + traceOutputI, ok := trace["output"] + if !ok { + return nil, fmt.Errorf("trace does not contain output field") + } + traceOutput, ok := traceOutputI.(string) + if !ok { + return nil, fmt.Errorf("expected type string for trace output, got %T", traceOutputI) + } + traceOutputBytes, err := hex.DecodeString(strings.TrimPrefix(traceOutput, "0x")) + if err != nil { + return nil, fmt.Errorf("failure decoding trace output: %w", err) + } + if len(traceOutputBytes) < 4 { + return nil, fmt.Errorf("less than 4 bytes in trace output") + } + traceErrorSelector := "0x" + hex.EncodeToString(traceOutputBytes[:4]) + for errorSignature, err := range functionSignatureToError { + errorSelector := GetFunctionSelector(errorSignature) + if traceErrorSelector == errorSelector { + return err, nil + } + } + return nil, fmt.Errorf("unknown error selector: %s", traceErrorSelector) +} + +func TransactionError(tx *types.Transaction, err error, msg string, args ...interface{}) error { + msgSuffix := ": %w" + if tx != nil { + msgSuffix += fmt.Sprintf(" (txHash=%s)", tx.Hash().String()) + } + args = append(args, err) + return fmt.Errorf(msg+msgSuffix, args...) +} diff --git a/pkg/subnet/local.go b/pkg/subnet/local.go index cd94f0547..863e56d06 100644 --- a/pkg/subnet/local.go +++ b/pkg/subnet/local.go @@ -112,6 +112,7 @@ func (d *LocalDeployer) DeployToLocalNetwork( binutils.LocalNetworkGRPCServerPort, binutils.LocalNetworkGRPCGatewayPort, d.app.GetSnapshotsDir(), + "", ); err != nil { return nil, err } @@ -123,6 +124,7 @@ func (d *LocalDeployer) StartServer( serverPort string, gatewayPort string, snapshotsDir string, + logPath string, ) error { isRunning, err := d.procChecker.IsServerProcessRunning(d.app, prefix) if err != nil { @@ -130,7 +132,14 @@ func (d *LocalDeployer) StartServer( } if !isRunning { d.app.Log.Debug("gRPC server is not running") - if err := binutils.StartServerProcess(d.app, prefix, serverPort, gatewayPort, snapshotsDir); err != nil { + if err := binutils.StartServerProcess( + d.app, + prefix, + serverPort, + gatewayPort, + snapshotsDir, + logPath, + ); err != nil { return fmt.Errorf("failed starting gRPC server process: %w", err) } d.backendStartedHere = true diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index 63cf4796a..0703a267d 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -4,6 +4,7 @@ package validatormanager import ( _ "embed" + "errors" "fmt" "math/big" "strings" @@ -12,6 +13,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/contract" "github.com/ava-labs/avalanche-cli/pkg/evm" "github.com/ava-labs/avalanche-cli/pkg/models" + "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanche-cli/sdk/interchain" "github.com/ava-labs/avalanchego/ids" avagoconstants "github.com/ava-labs/avalanchego/utils/constants" @@ -29,6 +31,8 @@ const ( ValidatorContractAddress = "0x5F584C2D56B4c356e7d82EC6129349393dc5df17" ) +var errAlreadyInitialized = errors.New("the contract is already initialized") + //go:embed deployed_poa_validator_manager_bytecode.txt var deployedPoAValidatorManagerBytecode []byte @@ -67,7 +71,7 @@ func PoAValidatorManagerInitialize( ChurnPeriodSeconds: defaultChurnPeriodSeconds, MaximumChurnPercentage: defaultMaximumChurnPercentage, } - return contract.TxToMethod( + tx, receipt, err := contract.TxToMethod( rpcURL, privateKey, managerAddress, @@ -76,15 +80,33 @@ func PoAValidatorManagerInitialize( params, ownerAddress, ) -} - -func TransactionError(tx *types.Transaction, err error, msg string, args ...interface{}) error { - msgSuffix := ":%w" - if tx != nil { - msgSuffix += fmt.Sprintf(" (txHash=%s)", tx.Hash().String()) + if err != nil { + trace, traceCallErr := contract.DebugTraceCall( + rpcURL, + privateKey, + managerAddress, + nil, + "initialize((bytes32,uint64,uint8),address)", + params, + ownerAddress, + ) + if traceCallErr != nil { + ux.Logger.PrintToUser("Could not get debug trace for PoA initialization error on %s: %s", rpcURL, traceCallErr) + ux.Logger.PrintToUser("Verify --debug flag value when calling 'blockchain create'") + return tx, receipt, err + } + errorSignatureToError := map[string]error{ + "InvalidInitialization()": errAlreadyInitialized, + } + errorFromSignature, _ := evm.GetErrorFromTrace(trace, errorSignatureToError) + if errorFromSignature != nil { + return tx, receipt, errorFromSignature + } else { + ux.Logger.PrintToUser("error trace for PoA initialization error:") + ux.Logger.PrintToUser("%#v", trace) + } } - args = append(args, err) - return fmt.Errorf(msg+msgSuffix, args...) + return tx, receipt, err } // constructs p-chain-validated (signed) subnet conversion warp @@ -251,7 +273,10 @@ func SetupPoA( ownerAddress, ) if err != nil { - return TransactionError(tx, err, "failure initializing poa validator manager") + if !errors.Is(err, errAlreadyInitialized) { + return evm.TransactionError(tx, err, "failure initializing poa validator manager") + } + ux.Logger.PrintToUser("Warning: the PoA contract is already initialized.") } subnetConversionSignedMessage, err := PoaValidatorManagerGetPChainSubnetConversionWarpMessage( network, @@ -277,7 +302,7 @@ func SetupPoA( subnetConversionSignedMessage, ) if err != nil { - return TransactionError(tx, err, "failure initializing validators set on poa manager") + return evm.TransactionError(tx, err, "failure initializing validators set on poa manager") } return nil } From 2aa05d1e535ef8c73b367191319fda259cda45db Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Sun, 13 Oct 2024 03:48:41 -0300 Subject: [PATCH 36/57] nit --- pkg/evm/evm.go | 83 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/pkg/evm/evm.go b/pkg/evm/evm.go index 20868d9e4..47cf0191c 100644 --- a/pkg/evm/evm.go +++ b/pkg/evm/evm.go @@ -8,6 +8,7 @@ import ( "encoding/hex" "fmt" "math/big" + "net/url" "strings" "time" @@ -349,15 +350,80 @@ func SendTransaction( return err } +func FindOutScheme(rpcURL string) (ethclient.Client, string, error) { + if b, err := HasScheme(rpcURL); err != nil { + return nil, "", err + } else if b { + return nil, "", fmt.Errorf("url does have scheme") + } + notDeterminedErr := fmt.Errorf("url %s has no scheme and protocol could not be determined", rpcURL) + // let's start with ws it always give same error for http/https/wss + scheme := "ws://" + ctx, cancel := utils.GetAPILargeContext() + defer cancel() + client, err := ethclient.DialContext(ctx, scheme+rpcURL) + if err == nil { + return client, scheme, nil + } else if !strings.Contains(err.Error(), "websocket: bad handshake") { + return nil, "", notDeterminedErr + } + // wss give specific errors for http/http + scheme = "wss://" + client, err = ethclient.DialContext(ctx, scheme+rpcURL) + if err == nil { + return client, scheme, nil + } else if !strings.Contains(err.Error(), "websocket: bad handshake") && // may be https + !strings.Contains(err.Error(), "first record does not look like a TLS handshake") { // may be http + return nil, "", notDeterminedErr + } + // https/http discrimination based on sending a specific query + scheme = "https://" + client, err = ethclient.DialContext(ctx, scheme+rpcURL) + if err == nil { + _, err = client.ChainID(ctx) + switch { + case err == nil: + return client, scheme, nil + case strings.Contains(err.Error(), "server gave HTTP response to HTTPS client"): + scheme = "http://" + client, err = ethclient.DialContext(ctx, scheme+rpcURL) + if err == nil { + return client, scheme, nil + } + } + } + return nil, "", notDeterminedErr +} + +func HasScheme(rpcURL string) (bool, error) { + if parsedURL, err := url.Parse(rpcURL); err != nil { + if !strings.Contains(err.Error(), "first path segment in URL cannot contain colon") { + return false, err + } + return false, nil + } else if parsedURL.Scheme == "" { + return false, nil + } + return true, nil +} + func GetClient(rpcURL string) (ethclient.Client, error) { var ( client ethclient.Client err error ) + hasScheme, err := HasScheme(rpcURL) + if err != nil { + return nil, err + } for i := 0; i < repeatsOnFailure; i++ { ctx, cancel := utils.GetAPILargeContext() defer cancel() - client, err = ethclient.DialContext(ctx, rpcURL) + if hasScheme { + client, err = ethclient.DialContext(ctx, rpcURL) + } else { + client, _, err = FindOutScheme(rpcURL) + } if err == nil { break } @@ -447,10 +513,23 @@ func GetRPCClient(rpcURL string) (*rpc.Client, error) { client *rpc.Client err error ) + hasScheme, err := HasScheme(rpcURL) + if err != nil { + return nil, err + } for i := 0; i < repeatsOnFailure; i++ { ctx, cancel := utils.GetAPILargeContext() defer cancel() - client, err = rpc.DialContext(ctx, rpcURL) + if !hasScheme { + _, scheme, findErr := FindOutScheme(rpcURL) + if findErr == nil { + client, err = rpc.DialContext(ctx, scheme+rpcURL) + } else { + err = findErr + } + } else { + client, err = rpc.DialContext(ctx, rpcURL) + } if err == nil { break } From b10649ca39554900c37547068c148d5f1c73fca7 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Sun, 13 Oct 2024 19:08:52 -0300 Subject: [PATCH 37/57] not to much further to have a complete flow --- cmd/blockchaincmd/add_validator.go | 96 +++++++++++++++---- cmd/blockchaincmd/deploy.go | 1 + cmd/contractcmd/init_poa_validator_manager.go | 1 + go.mod | 2 +- go.sum | 2 + pkg/subnet/public.go | 38 +++++++- pkg/validatormanager/validatormanager.go | 68 +++++++++++-- sdk/interchain/signature-aggregator.go | 10 +- 8 files changed, 185 insertions(+), 33 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index 9bf732e38..f63109df1 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -61,6 +61,7 @@ var ( errMutuallyExclusiveStartOptions = errors.New("--use-default-start-time/--use-default-validator-params and --start-time are mutually exclusive") errMutuallyExclusiveWeightOptions = errors.New("--use-default-validator-params and --weight are mutually exclusive") ErrNotPermissionedSubnet = errors.New("subnet is not permissioned") + privateAggregatorEndpoints []string ) // avalanche blockchain addValidator @@ -95,6 +96,7 @@ Testnet or Mainnet.`, cmd.Flags().StringVar(&pop, "bls-proof-of-possession", "", "set the BLS proof of possession of the validator to add") cmd.Flags().StringVar(&changeAddr, "change-address", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet") cmd.Flags().StringVar(&nodeEndpoint, "node-endpoint", "", "gather node id/bls from publicly available avalanchego apis on the given endpoint") + cmd.Flags().StringSliceVar(&privateAggregatorEndpoints, "private-aggregator-endpoints", nil, "endpoints for private nodes that are not available as network peers but are needed in signature aggregation") return cmd } @@ -120,6 +122,8 @@ func addValidator(_ *cobra.Command, args []string) error { return fmt.Errorf("failure parsing BLS info: %w", err) } expiry := uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix()) + //expiry = 1728906495 + expiry = 1728913615 fmt.Println("Expiry:", expiry) network, err := networkoptions.GetNetworkFromCmdLineFlags( @@ -150,10 +154,10 @@ func addValidator(_ *cobra.Command, args []string) error { } for _, n := range []string{ - "NodeID-BJe9MSoteeNtrQkKnicKez1zoLiMXrPKq", - "NodeID-FeonWY2gTTTHTvu86BUU4zPYnTzjCrsiu", - "NodeID-HfTXNwnR8TFKe6Z3aTKm1Mufuvn6kNaob", - "NodeID-8THh1JB8D27gU4qaCLFZqWr4qqDk1xoup", + "NodeID-EdozwfGju54Wyq65Hxb2aGRsvsX35AzfR", + "NodeID-2aMuVFi1yAah7uQ21umSFWL9MR7sMjHzD", + "NodeID-MKvwytUJUXvD4ZrFegX5NN9bataApatKf", + "NodeID-EkMcxQtbeYw6aj3pttZLyH33RBdYkSJqK", } { nID, err := ids.NodeIDFromString(n) if err != nil { @@ -174,8 +178,18 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return fmt.Errorf("failed to load sidecar: %w", err) } - balanceOwners := warpMessage.PChainOwner{} - disableOwners := warpMessage.PChainOwner{} + balanceOwners := warpMessage.PChainOwner{ + Threshold: 1, + Addresses: []ids.ShortID{ + ids.GenerateTestShortID(), + }, + } + disableOwners := warpMessage.PChainOwner{ + Threshold: 1, + Addresses: []ids.ShortID{ + ids.GenerateTestShortID(), + }, + } ownerPrivateKeyFound, n, _, ownerPrivateKey, err := contract.SearchForManagedKey( app, @@ -209,38 +223,61 @@ func addValidator(_ *cobra.Command, args []string) error { fmt.Println(evmTx.Hash()) } fmt.Println(receipt) - return err + //return err + } + if evmTx != nil { + fmt.Println("txHash", evmTx.Hash()) } client, err := evm.GetClient(rpcURL) if err != nil { return err } defer client.Close() - ctx, cancel := utils.GetAPILargeContext() - defer cancel() + /* + ctx, cancel := utils.GetAPILargeContext() + defer cancel() - fmt.Println("receipt:", receipt.BlockNumber, receipt.BlockHash) - unsignedMessage, err := evm.ExtractWarpMessageFromReceipt( - client, - ctx, - receipt, + txHash := "0xa5a3a27c782ab0bfcc04bf0c5dc86903fc51342e791ad13d6ae94a7ed558aff1" + receipt, err = client.TransactionReceipt(ctx, common.HexToHash(txHash)) + if err != nil { + return err + } + fmt.Println("receipt:", receipt.BlockNumber, receipt.BlockHash) + unsignedMessage, err := evm.ExtractWarpMessageFromReceipt( + client, + ctx, + receipt, + ) + if err != nil { + return err + } + fmt.Println("unsigned warp message: ", unsignedMessage.ID()) + */ + subnetID, err := contract.GetSubnetID( + app, + network, + chainSpec, ) if err != nil { return err } - fmt.Println("unsigned warp message: ", unsignedMessage.ID()) - subnetID, err := contract.GetSubnetID( + blockchainID, err := contract.GetBlockchainID( app, network, chainSpec, ) - fmt.Println("Get signed message") - signedMessage, err := validatormanager.PoaValidatorManagerGetSubnetValidatorRegistrationMessage( + if err != nil { + return err + } + //fmt.Println(hex.EncodeToString(unsignedMessage.Bytes())) + signedMessage, validationID, err := validatormanager.PoaValidatorManagerGetSubnetValidatorRegistrationMessage( network, app.Log, - logging.Verbo, + logging.Info, 0, + privateAggregatorEndpoints, subnetID, + blockchainID, common.HexToAddress(validatormanager.ValidatorContractAddress), nodeID, blsInfo.PublicKey, @@ -252,6 +289,8 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return err } + fmt.Println("validationID", validationID) + fmt.Println("TODO BIEN") kc, err := keychain.GetKeychainFromCmdLineFlags( app, @@ -269,7 +308,24 @@ func addValidator(_ *cobra.Command, args []string) error { deployer := subnet.NewPublicDeployer(app, kc, network) fmt.Println("register validator on pchain") - _, err = deployer.RegisterL1Validator(balance, blsInfo, signedMessage) + balance = constants.BootstrapValidatorBalance + txID, _, err := deployer.RegisterL1Validator(balance, blsInfo, signedMessage) + /* + if err != nil { + return err + } + */ + fmt.Println(txID) + _, err = validatormanager.PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( + network, + app.Log, + logging.Info, + 0, + privateAggregatorEndpoints, + subnetID, + validationID, + true, + ) if err != nil { return err } diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 78e19cf7a..d1fbb4f1c 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -733,6 +733,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { privateKey, common.HexToAddress(sidecar.PoAValidatorManagerOwner), avaGoBootstrapValidators, + nil, ); err != nil { return err } diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index 4512a8f9d..8d5399ea4 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -124,6 +124,7 @@ func initPOAManager(_ *cobra.Command, args []string) error { privateKey, common.HexToAddress(sc.PoAValidatorManagerOwner), avaGoBootstrapValidators, + nil, ); err != nil { return err } diff --git a/go.mod b/go.mod index 3776779d4..95ac75f07 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/ava-labs/apm v1.0.0 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344 github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 - github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f + github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 github.com/ava-labs/subnet-evm v0.6.10 github.com/aws/aws-sdk-go-v2 v1.31.0 diff --git a/go.sum b/go.sum index f7f98a76c..ad7126bae 100644 --- a/go.sum +++ b/go.sum @@ -89,6 +89,8 @@ github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2 github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f h1:YUQF1wQJeEcTMC5W/OrwgSFTFMS4zeCM8O02rLeEDow= github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= +github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 h1:M58jcqAG51RrKKVCfhAZpPqCFdkqRzahEgkFqQA5EME= +github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c= diff --git a/pkg/subnet/public.go b/pkg/subnet/public.go index d801e10be..aa52917d6 100644 --- a/pkg/subnet/public.go +++ b/pkg/subnet/public.go @@ -128,16 +128,48 @@ func (d *PublicDeployer) RegisterL1Validator( balance uint64, pop signer.ProofOfPossession, message *warp.Message, -) (*txs.Tx, error) { +) (ids.ID, *txs.Tx, error) { wallet, err := d.loadCacheWallet() if err != nil { - return nil, err + return ids.Empty, nil, err } - return wallet.P().IssueRegisterSubnetValidatorTx( + tx, err := d.createRegisterSubnetValidatorTx( + balance, + pop, + message, + wallet, + ) + if err != nil { + return ids.Empty, nil, err + } + id, err := d.Commit(tx, true) + return id, tx, err +} + +func (d *PublicDeployer) createRegisterSubnetValidatorTx( + balance uint64, + pop signer.ProofOfPossession, + message *warp.Message, + wallet primary.Wallet, +) (*txs.Tx, error) { + unsignedTx, err := wallet.P().Builder().NewRegisterSubnetValidatorTx( balance, pop.ProofOfPossession, message.Bytes(), ) + if err != nil { + return nil, fmt.Errorf("error building tx: %w", err) + } + if unsignedTx != nil { + if err := printFee("RegisterSubnetValidatorTX", wallet, unsignedTx); err != nil { + return nil, err + } + } + tx := txs.Tx{Unsigned: unsignedTx} + if err := wallet.P().Signer().Sign(context.Background(), &tx); err != nil { + return nil, fmt.Errorf("error signing tx: %w", err) + } + return &tx, nil } // change subnet owner for [subnetID] diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index fdebb1b57..8cdb4d3da 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -4,6 +4,7 @@ package validatormanager import ( _ "embed" + "encoding/hex" "fmt" "math/big" "strings" @@ -99,6 +100,7 @@ func PoaValidatorManagerGetPChainSubnetConversionWarpMessage( aggregatorLogger logging.Logger, aggregatorLogLevel logging.Level, aggregatorQuorumPercentage uint64, + aggregatorExtraPeerEndpoints []string, subnetID ids.ID, managerBlockchainID ids.ID, managerAddress common.Address, @@ -147,6 +149,7 @@ func PoaValidatorManagerGetPChainSubnetConversionWarpMessage( aggregatorLogLevel, subnetID, aggregatorQuorumPercentage, + aggregatorExtraPeerEndpoints, ) if err != nil { return nil, err @@ -217,6 +220,7 @@ func SetupPoA( privateKey string, ownerAddress common.Address, convertSubnetValidators []*txs.ConvertSubnetValidator, + aggregatorExtraPeerEndpoints []string, ) error { if err := evm.SetupProposerVM( rpcURL, @@ -256,6 +260,7 @@ func SetupPoA( app.Log, logging.Info, 0, + aggregatorExtraPeerEndpoints, subnetID, blockchainID, managerAddress, @@ -337,7 +342,9 @@ func PoaValidatorManagerGetSubnetValidatorRegistrationMessage( aggregatorLogger logging.Logger, aggregatorLogLevel logging.Level, aggregatorQuorumPercentage uint64, + aggregatorExtraPeerEndpoints []string, subnetID ids.ID, + blockchainID ids.ID, managerAddress common.Address, nodeID ids.NodeID, blsPublicKey [48]byte, @@ -345,7 +352,7 @@ func PoaValidatorManagerGetSubnetValidatorRegistrationMessage( balanceOwners warpMessage.PChainOwner, disableOwners warpMessage.PChainOwner, weight uint64, -) (*warp.Message, error) { +) (*warp.Message, ids.ID, error) { addressedCallPayload, err := warpMessage.NewRegisterSubnetValidator( subnetID, nodeID, @@ -356,35 +363,39 @@ func PoaValidatorManagerGetSubnetValidatorRegistrationMessage( weight, ) if err != nil { - return nil, err + return nil, ids.Empty, err } + validationID := addressedCallPayload.ValidationID() registerSubnetValidatorAddressedCall, err := warpPayload.NewAddressedCall( managerAddress.Bytes(), addressedCallPayload.Bytes(), ) if err != nil { - return nil, err + return nil, ids.Empty, err } registerSubnetValidatorUnsignedMessage, err := warp.NewUnsignedMessage( network.ID, - subnetID, + blockchainID, registerSubnetValidatorAddressedCall.Bytes(), ) if err != nil { - return nil, err + return nil, ids.Empty, err } fmt.Println("check", registerSubnetValidatorUnsignedMessage.ID()) + fmt.Println(hex.EncodeToString(registerSubnetValidatorUnsignedMessage.Bytes())) signatureAggregator, err := interchain.NewSignatureAggregator( network, aggregatorLogger, aggregatorLogLevel, subnetID, aggregatorQuorumPercentage, + aggregatorExtraPeerEndpoints, ) if err != nil { - return nil, err + return nil, ids.Empty, err } - return signatureAggregator.Sign(registerSubnetValidatorUnsignedMessage, nil) + signedMessage, err := signatureAggregator.Sign(registerSubnetValidatorUnsignedMessage, nil) + return signedMessage, validationID, err } func GetRegisteredValidator( @@ -407,3 +418,46 @@ func GetRegisteredValidator( } return validatorID, nil } + +func PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( + network models.Network, + aggregatorLogger logging.Logger, + aggregatorLogLevel logging.Level, + aggregatorQuorumPercentage uint64, + aggregatorExtraPeerEndpoints []string, + subnetID ids.ID, + validationID ids.ID, + registered bool, +) (*warp.Message, error) { + addressedCallPayload, err := warpMessage.NewSubnetValidatorRegistration(validationID, registered) + if err != nil { + return nil, err + } + subnetValidatorRegistrationAddressedCall, err := warpPayload.NewAddressedCall( + nil, + addressedCallPayload.Bytes(), + ) + if err != nil { + return nil, err + } + subnetConversionUnsignedMessage, err := warp.NewUnsignedMessage( + network.ID, + avagoconstants.PlatformChainID, + subnetValidatorRegistrationAddressedCall.Bytes(), + ) + if err != nil { + return nil, err + } + signatureAggregator, err := interchain.NewSignatureAggregator( + network, + aggregatorLogger, + aggregatorLogLevel, + subnetID, + aggregatorQuorumPercentage, + aggregatorExtraPeerEndpoints, + ) + if err != nil { + return nil, err + } + return signatureAggregator.Sign(subnetConversionUnsignedMessage, subnetID[:]) +} diff --git a/sdk/interchain/signature-aggregator.go b/sdk/interchain/signature-aggregator.go index 00d8840dc..405d5bff7 100644 --- a/sdk/interchain/signature-aggregator.go +++ b/sdk/interchain/signature-aggregator.go @@ -45,11 +45,16 @@ type SignatureAggregator struct { // Returns: // - peers.AppRequestNetwork: The created AppRequestNetwork, or nil if an error occurred. // - error: An error if the creation of the AppRequestNetwork failed. -func createAppRequestNetwork(network models.Network, logLevel logging.Level) (peers.AppRequestNetwork, error) { +func createAppRequestNetwork( + network models.Network, + logLevel logging.Level, + extraPeerEndpoints []string, +) (peers.AppRequestNetwork, error) { peerNetwork, err := peers.NewNetwork( logLevel, prometheus.DefaultRegisterer, nil, + extraPeerEndpoints, &config.Config{ PChainAPI: &apiConfig.APIConfig{ BaseURL: network.Endpoint, @@ -130,8 +135,9 @@ func NewSignatureAggregator( logLevel logging.Level, subnetID ids.ID, quorumPercentage uint64, + extraPeerEndpoints []string, ) (*SignatureAggregator, error) { - peerNetwork, err := createAppRequestNetwork(network, logLevel) + peerNetwork, err := createAppRequestNetwork(network, logLevel, extraPeerEndpoints) if err != nil { return nil, err } From 11ffc8e7f2ddf9c461ba56abea4c8621ad103493 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 10:38:22 -0300 Subject: [PATCH 38/57] ok esto esta funcionando --- cmd/blockchaincmd/add_validator.go | 89 +++++++++++++++++++----- cmd/blockchaincmd/helpers.go | 37 ++++++++++ go.mod | 2 + pkg/evm/evm.go | 12 ++-- pkg/validatormanager/validatormanager.go | 18 +++++ sdk/interchain/signature-aggregator.go | 13 ++-- 6 files changed, 143 insertions(+), 28 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index f63109df1..ddbc20bc5 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -97,6 +97,7 @@ Testnet or Mainnet.`, cmd.Flags().StringVar(&changeAddr, "change-address", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet") cmd.Flags().StringVar(&nodeEndpoint, "node-endpoint", "", "gather node id/bls from publicly available avalanchego apis on the given endpoint") cmd.Flags().StringSliceVar(&privateAggregatorEndpoints, "private-aggregator-endpoints", nil, "endpoints for private nodes that are not available as network peers but are needed in signature aggregation") + privateKeyFlags.AddToCmd(cmd, "to pay fees for completing the validator's registration (blockchain gas token)") return cmd } @@ -122,8 +123,6 @@ func addValidator(_ *cobra.Command, args []string) error { return fmt.Errorf("failure parsing BLS info: %w", err) } expiry := uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix()) - //expiry = 1728906495 - expiry = 1728913615 fmt.Println("Expiry:", expiry) network, err := networkoptions.GetNetworkFromCmdLineFlags( @@ -204,6 +203,46 @@ func addValidator(_ *cobra.Command, args []string) error { if !ownerPrivateKeyFound { return fmt.Errorf("not private key found for PoA manager owner %s", sc.PoAValidatorManagerOwner) } + ux.Logger.PrintToUser(logging.Yellow.Wrap("PoA manager owner %s pays for the initialization of the validator's registration (Blockchain gas token)"), sc.PoAValidatorManagerOwner) + genesisAddress, 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, + "pay for completing registration of validator? (Blockchain gas token)", + app.GetKeyDir(), + app.GetKey, + genesisAddress, + genesisPrivateKey, + ) + if err != nil { + return err + } + } + + kc, err := keychain.GetKeychainFromCmdLineFlags( + app, + "to pay for transaction fees on P-Chain", + network, + keyName, + useEwoq, + useLedger, + ledgerAddresses, + 0, + ) + if err != nil { + return err + } fmt.Println("Initialize registration") fmt.Println(rpcURL) @@ -292,19 +331,6 @@ func addValidator(_ *cobra.Command, args []string) error { fmt.Println("validationID", validationID) fmt.Println("TODO BIEN") - kc, err := keychain.GetKeychainFromCmdLineFlags( - app, - constants.PayTxsFeesMsg, - network, - keyName, - useEwoq, - useLedger, - ledgerAddresses, - 0, - ) - if err != nil { - return err - } deployer := subnet.NewPublicDeployer(app, kc, network) fmt.Println("register validator on pchain") @@ -316,7 +342,16 @@ func addValidator(_ *cobra.Command, args []string) error { } */ fmt.Println(txID) - _, err = validatormanager.PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( + + if err := UpdatePChainHeight( + deployer, + kc.Addresses().List()[0], + "Waiting for P-Chain to update validator information ...", + ); err != nil { + return err + } + + subnetValidatorRegistrationSignedMessage, err := validatormanager.PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( network, app.Log, logging.Info, @@ -329,6 +364,28 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return err } + fmt.Println("TODO BIEN") + + if err := evm.SetupProposerVM( + rpcURL, + privateKey, + ); err != nil { + return err + } + + tx, _, err := validatormanager.PoAValidatorManagerCompleteValidatorRegistration( + rpcURL, + common.HexToAddress(validatormanager.ValidatorContractAddress), + privateKey, + subnetValidatorRegistrationSignedMessage, + ) + if tx != nil { + fmt.Println("tx hash", tx.Hash()) + } + if err != nil { + return err + } + fmt.Println("TODO BIEN") return nil blockchainName := args[0] diff --git a/cmd/blockchaincmd/helpers.go b/cmd/blockchaincmd/helpers.go index 98ada06c5..6bf702fab 100644 --- a/cmd/blockchaincmd/helpers.go +++ b/cmd/blockchaincmd/helpers.go @@ -4,11 +4,14 @@ package blockchaincmd import ( "fmt" + "time" "github.com/ava-labs/avalanche-cli/pkg/keychain" "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" + "github.com/ava-labs/avalanche-cli/pkg/subnet" "github.com/ava-labs/avalanche-cli/pkg/txutils" + "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanchego/ids" "github.com/spf13/cobra" ) @@ -93,3 +96,37 @@ func UpdateKeychainWithSubnetControlKeys( } return nil } + +func UpdatePChainHeight( + deployer *subnet.PublicDeployer, + destinationAddress ids.ShortID, + title string, +) error { + bar, err := ux.TimedProgressBar( + 30*time.Second, + title, + 2, + ) + if err != nil { + return err + } + // Issue random transaction >30s after ConverSubnetTx to evict its block from the block map + _, _, err = deployer.PChainTransfer(destinationAddress, 1) + if err != nil { + return err + } + if err := ux.ExtraStepExecuted(bar); err != nil { + return err + } + // Issue random transaction to advance the p-chain height now that the + // ConvertSubnetTx block isn't in the block map + _, _, err = deployer.PChainTransfer(destinationAddress, 1) + if err != nil { + return err + } + if err := ux.ExtraStepExecuted(bar); err != nil { + return err + } + fmt.Println() + return nil +} diff --git a/go.mod b/go.mod index 95ac75f07..61ff60dcc 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/ava-labs/avalanche-cli go 1.22.8 +replace github.com/ava-labs/awm-relayer => ../awm-relayer + require ( github.com/ava-labs/apm v1.0.0 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344 diff --git a/pkg/evm/evm.go b/pkg/evm/evm.go index dcdfda486..198685351 100644 --- a/pkg/evm/evm.go +++ b/pkg/evm/evm.go @@ -549,11 +549,6 @@ func issueTxsToActivateProposerVMFork( ) error { const numTriggerTxs = 2 // Number of txs needed to activate the proposer VM fork addr := crypto.PubkeyToAddress(fundedKey.PublicKey) - nonce, err := client.NonceAt(ctx, addr, nil) - if err != nil { - return err - } - gasPrice := big.NewInt(params.MinGasPrice) txSigner := types.LatestSignerForChainID(chainID) for i := 0; i < numTriggerTxs; i++ { @@ -561,6 +556,10 @@ func issueTxsToActivateProposerVMFork( if err != nil { return err } + nonce, err := client.NonceAt(ctx, addr, nil) + if err != nil { + return err + } tx := types.NewTransaction( nonce, addr, common.Big1, params.TxGas, gasPrice, nil) triggerTx, err := types.SignTx(tx, txSigner, fundedKey) @@ -573,7 +572,6 @@ func issueTxsToActivateProposerVMFork( if err := WaitForNewBlock(client, ctx, prevBlockNumber, 0, 0); err != nil { return err } - nonce++ } return nil } @@ -589,7 +587,7 @@ func WaitForNewBlock( stepDuration = 1 * time.Second } if totalDuration == 0 { - totalDuration = 5 * time.Second + totalDuration = 10 * time.Second } steps := totalDuration / stepDuration for seconds := 0; seconds < int(steps); seconds++ { diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index 8cdb4d3da..309a55f24 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -461,3 +461,21 @@ func PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( } return signatureAggregator.Sign(subnetConversionUnsignedMessage, subnetID[:]) } + +// last step of flow for adding a new validator +func PoAValidatorManagerCompleteValidatorRegistration( + rpcURL string, + managerAddress common.Address, + privateKey string, // not need to be owner atm + subnetValidatorRegistrationSignedMessage *warp.Message, +) (*types.Transaction, *types.Receipt, error) { + return contract.TxToMethodWithWarpMessage( + rpcURL, + privateKey, + managerAddress, + subnetValidatorRegistrationSignedMessage, + big.NewInt(0), + "completeValidatorRegistration(uint32)", + uint32(0), + ) +} diff --git a/sdk/interchain/signature-aggregator.go b/sdk/interchain/signature-aggregator.go index 405d5bff7..187374a4a 100644 --- a/sdk/interchain/signature-aggregator.go +++ b/sdk/interchain/signature-aggregator.go @@ -48,11 +48,12 @@ type SignatureAggregator struct { func createAppRequestNetwork( network models.Network, logLevel logging.Level, + registerer prometheus.Registerer, extraPeerEndpoints []string, ) (peers.AppRequestNetwork, error) { peerNetwork, err := peers.NewNetwork( logLevel, - prometheus.DefaultRegisterer, + registerer, nil, extraPeerEndpoints, &config.Config{ @@ -81,6 +82,7 @@ func createAppRequestNetwork( func initSignatureAggregator( network peers.AppRequestNetwork, logger logging.Logger, + registerer prometheus.Registerer, subnetID ids.ID, quorumPercentage uint64, ) (*SignatureAggregator, error) { @@ -96,7 +98,7 @@ func initSignatureAggregator( messageCreator, err := message.NewCreator( logger, - prometheus.DefaultRegisterer, + registerer, constants.DefaultNetworkCompressionType, constants.DefaultNetworkMaximumInboundTimeout, ) @@ -104,7 +106,7 @@ func initSignatureAggregator( return nil, fmt.Errorf("failed to create message creator: %w", err) } - metricsInstance := metrics.NewSignatureAggregatorMetrics(prometheus.DefaultRegisterer) + metricsInstance := metrics.NewSignatureAggregatorMetrics(registerer) signatureAggregator, err := aggregator.NewSignatureAggregator( network, logger, @@ -137,11 +139,12 @@ func NewSignatureAggregator( quorumPercentage uint64, extraPeerEndpoints []string, ) (*SignatureAggregator, error) { - peerNetwork, err := createAppRequestNetwork(network, logLevel, extraPeerEndpoints) + registerer := prometheus.NewRegistry() + peerNetwork, err := createAppRequestNetwork(network, logLevel, registerer, extraPeerEndpoints) if err != nil { return nil, err } - return initSignatureAggregator(peerNetwork, logger, subnetID, quorumPercentage) + return initSignatureAggregator(peerNetwork, logger, registerer, subnetID, quorumPercentage) } // AggregateSignatures aggregates signatures for a given message and justification. From 8241469384ec68edf5d3f49ac96b521203bdf843 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 12:08:10 -0300 Subject: [PATCH 39/57] started refactoring --- cmd/blockchaincmd/add_validator.go | 137 +++++++++++------------ go.mod | 15 ++- go.sum | 36 +++--- pkg/evm/evm.go | 9 +- pkg/validatormanager/validatormanager.go | 119 +++++++++++++++++++- 5 files changed, 208 insertions(+), 108 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index ddbc20bc5..7c85333a4 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -102,6 +102,8 @@ Testnet or Mainnet.`, } func addValidator(_ *cobra.Command, args []string) error { + blockchainName := args[0] + if nodeEndpoint != "" { infoClient := info.NewClient(nodeEndpoint) ctx, cancel := utils.GetAPILargeContext() @@ -123,7 +125,6 @@ func addValidator(_ *cobra.Command, args []string) error { return fmt.Errorf("failure parsing BLS info: %w", err) } expiry := uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix()) - fmt.Println("Expiry:", expiry) network, err := networkoptions.GetNetworkFromCmdLineFlags( app, @@ -139,7 +140,7 @@ func addValidator(_ *cobra.Command, args []string) error { } chainSpec := contract.ChainSpec{ - BlockchainName: "poa", + BlockchainName: blockchainName, } rpcURL, _, err := contract.GetBlockchainEndpoints( app, @@ -151,27 +152,7 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return err } - - for _, n := range []string{ - "NodeID-EdozwfGju54Wyq65Hxb2aGRsvsX35AzfR", - "NodeID-2aMuVFi1yAah7uQ21umSFWL9MR7sMjHzD", - "NodeID-MKvwytUJUXvD4ZrFegX5NN9bataApatKf", - "NodeID-EkMcxQtbeYw6aj3pttZLyH33RBdYkSJqK", - } { - nID, err := ids.NodeIDFromString(n) - if err != nil { - return err - } - validatorID, err := validatormanager.GetRegisteredValidator( - rpcURL, - common.HexToAddress(validatormanager.ValidatorContractAddress), - nID, - ) - if err != nil { - return err - } - fmt.Println(nID, validatorID) - } + ux.Logger.PrintToUser(logging.Yellow.Wrap("RPC Endpoint: %s"), rpcURL) sc, err := app.LoadSidecar(chainSpec.BlockchainName) if err != nil { @@ -190,7 +171,7 @@ func addValidator(_ *cobra.Command, args []string) error { }, } - ownerPrivateKeyFound, n, _, ownerPrivateKey, err := contract.SearchForManagedKey( + ownerPrivateKeyFound, _, _, ownerPrivateKey, err := contract.SearchForManagedKey( app, network, common.HexToAddress(sc.PoAValidatorManagerOwner), @@ -199,7 +180,6 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return err } - fmt.Println(n) if !ownerPrivateKeyFound { return fmt.Errorf("not private key found for PoA manager owner %s", sc.PoAValidatorManagerOwner) } @@ -244,11 +224,11 @@ func addValidator(_ *cobra.Command, args []string) error { return err } - fmt.Println("Initialize registration") - fmt.Println(rpcURL) - evmTx, receipt, err := validatormanager.PoAValidatorManagerInitializeValidatorRegistration( + signedMessage, validationID, err := validatormanager.InitValidatorRegistration( + app, + network, rpcURL, - common.HexToAddress(validatormanager.ValidatorContractAddress), + chainSpec, ownerPrivateKey, nodeID, blsInfo.PublicKey[:], @@ -256,42 +236,64 @@ func addValidator(_ *cobra.Command, args []string) error { balanceOwners, disableOwners, weight, + privateAggregatorEndpoints, ) if err != nil { - if evmTx != nil { - fmt.Println(evmTx.Hash()) - } - fmt.Println(receipt) - //return err + return err + } + ux.Logger.PrintToUser("ValidationID: %s", validationID) + + deployer := subnet.NewPublicDeployer(app, kc, network) + balance = constants.BootstrapValidatorBalance + txID, _, err := deployer.RegisterL1Validator(balance, blsInfo, signedMessage) + if err != nil { + // return err + } + ux.Logger.PrintToUser("RegisterSubnetValidatorTx ID: %s", txID) + + if err := UpdatePChainHeight( + deployer, + kc.Addresses().List()[0], + "Waiting for P-Chain to update validator information ...", + ); err != nil { + return err + } + + if err := validatormanager.FinishValidatorRegistration( + app, + network, + rpcURL, + chainSpec, + privateKey, + validationID, + privateAggregatorEndpoints, + ); err != nil { + return err } - if evmTx != nil { - fmt.Println("txHash", evmTx.Hash()) + + ux.Logger.GreenCheckmarkToUser("Validator successfully added to the Subnet") + + return nil + + tx, _, err := validatormanager.PoAValidatorManagerInitializeValidatorRegistration( + rpcURL, + common.HexToAddress(validatormanager.ValidatorContractAddress), + ownerPrivateKey, + nodeID, + blsInfo.PublicKey[:], + expiry, + balanceOwners, + disableOwners, + weight, + ) + if err != nil { + //return validatormanager.TransactionError(tx, err, "failure initializing validator registration") } client, err := evm.GetClient(rpcURL) if err != nil { return err } defer client.Close() - /* - ctx, cancel := utils.GetAPILargeContext() - defer cancel() - - txHash := "0xa5a3a27c782ab0bfcc04bf0c5dc86903fc51342e791ad13d6ae94a7ed558aff1" - receipt, err = client.TransactionReceipt(ctx, common.HexToHash(txHash)) - if err != nil { - return err - } - fmt.Println("receipt:", receipt.BlockNumber, receipt.BlockHash) - unsignedMessage, err := evm.ExtractWarpMessageFromReceipt( - client, - ctx, - receipt, - ) - if err != nil { - return err - } - fmt.Println("unsigned warp message: ", unsignedMessage.ID()) - */ subnetID, err := contract.GetSubnetID( app, network, @@ -308,8 +310,7 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return err } - //fmt.Println(hex.EncodeToString(unsignedMessage.Bytes())) - signedMessage, validationID, err := validatormanager.PoaValidatorManagerGetSubnetValidatorRegistrationMessage( + signedMessage, validationID, err = validatormanager.PoaValidatorManagerGetSubnetValidatorRegistrationMessage( network, app.Log, logging.Info, @@ -328,20 +329,15 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return err } - fmt.Println("validationID", validationID) - fmt.Println("TODO BIEN") - deployer := subnet.NewPublicDeployer(app, kc, network) + return nil - fmt.Println("register validator on pchain") balance = constants.BootstrapValidatorBalance - txID, _, err := deployer.RegisterL1Validator(balance, blsInfo, signedMessage) - /* - if err != nil { - return err - } - */ - fmt.Println(txID) + txID, _, err = deployer.RegisterL1Validator(balance, blsInfo, signedMessage) + if err != nil { + // return err + } + ux.Logger.PrintToUser("RegisterSubnetValidatorTx ID: %s", txID) if err := UpdatePChainHeight( deployer, @@ -373,7 +369,7 @@ func addValidator(_ *cobra.Command, args []string) error { return err } - tx, _, err := validatormanager.PoAValidatorManagerCompleteValidatorRegistration( + tx, _, err = validatormanager.PoAValidatorManagerCompleteValidatorRegistration( rpcURL, common.HexToAddress(validatormanager.ValidatorContractAddress), privateKey, @@ -388,7 +384,6 @@ func addValidator(_ *cobra.Command, args []string) error { fmt.Println("TODO BIEN") return nil - blockchainName := args[0] err = prompts.ValidateNodeID(nodeIDStr) if err != nil { return err diff --git a/go.mod b/go.mod index 61ff60dcc..30db8b622 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 github.com/ava-labs/subnet-evm v0.6.10 - github.com/aws/aws-sdk-go-v2 v1.31.0 + github.com/aws/aws-sdk-go-v2 v1.32.2 github.com/aws/aws-sdk-go-v2/config v1.27.26 github.com/aws/aws-sdk-go-v2/service/ec2 v1.162.0 github.com/chelnak/ysmrr v0.4.0 @@ -50,7 +50,7 @@ require ( golang.org/x/sync v0.8.0 golang.org/x/text v0.17.0 google.golang.org/api v0.184.0 - google.golang.org/protobuf v1.34.2 + google.golang.org/protobuf v1.35.1 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -72,16 +72,16 @@ require ( github.com/ava-labs/teleporter v1.0.7 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.26 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 // indirect - github.com/aws/aws-sdk-go-v2/service/kms v1.36.2 // indirect + github.com/aws/aws-sdk-go-v2/service/kms v1.37.2 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.22.3 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 // indirect - github.com/aws/smithy-go v1.21.0 // indirect + github.com/aws/smithy-go v1.22.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect @@ -117,7 +117,6 @@ require ( github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect github.com/getsentry/sentry-go v0.18.0 // indirect github.com/gliderlabs/ssh v0.3.7 // indirect - github.com/go-cmd/cmd v1.4.1 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect github.com/go-logr/logr v1.4.2 // indirect @@ -228,7 +227,7 @@ require ( gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect - google.golang.org/grpc v1.67.0 // indirect + google.golang.org/grpc v1.67.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect diff --git a/go.sum b/go.sum index ad7126bae..60613bf6e 100644 --- a/go.sum +++ b/go.sum @@ -87,10 +87,6 @@ github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb134 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= -github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f h1:YUQF1wQJeEcTMC5W/OrwgSFTFMS4zeCM8O02rLeEDow= -github.com/ava-labs/awm-relayer v1.4.1-0.20241003162124-807fd305670f/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= -github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 h1:M58jcqAG51RrKKVCfhAZpPqCFdkqRzahEgkFqQA5EME= -github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c= @@ -100,8 +96,8 @@ github.com/ava-labs/subnet-evm v0.6.10/go.mod h1:dw4kg0o58dvYlndj2ZcwB7hioRc1kjg github.com/ava-labs/teleporter v1.0.7 h1:9H0wTWhgWeA4u6uxi9KngdBu/LOoYsfAmIZhXNzuvf8= github.com/ava-labs/teleporter v1.0.7/go.mod h1:wgCgU6vU5MtP83otpjEin8jL2jrflVBNQCTxVXMx/kU= github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= -github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U= -github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA= +github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI= +github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= github.com/aws/aws-sdk-go-v2/config v1.27.26 h1:T1kAefbKuNum/AbShMsZEro6eRkeOT8YILfE9wyjAYQ= github.com/aws/aws-sdk-go-v2/config v1.27.26/go.mod h1:ivWHkAWFrw/nxty5Fku7soTIVdqZaZ7dw+tc5iGW3GA= @@ -111,10 +107,10 @@ github.com/aws/aws-sdk-go-v2/credentials v1.17.26/go.mod h1:3vAM49zkIa3q8WT6o9Ve github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2/go.mod h1:3hGg3PpiEjHnrkrlasTfxFqUsZ2GCk/fMUn4CbKgSkM= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 h1:KreluoV8FZDEtI6Co2xuNk/UqI9iwMrOx/87PBNIKqw= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11/go.mod h1:SeSUYBLsMYFoRvHE0Tjvn7kbxaUhl75CJi1sbfhMxkU= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 h1:kYQ3H1u0ANr9KEKlGs/jTLrBFPo8P8NaH/w7A01NeeM= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18/go.mod h1:r506HmK5JDUh9+Mw4CfGJGSSoqIiLCndAuqXuhbv67Y= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18 h1:Z7IdFUONvTcvS7YuhtVxN99v2cCoHRXOS4mTr0B/pUc= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.18/go.mod h1:DkKMmksZVVyat+Y+r1dEOgJEfUeA7UngIHWeKsi0yNc= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 h1:UAsR3xA31QGf79WzpG/ixT9FZvQlh5HY1NRqSHBNOCk= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21/go.mod h1:JNr43NFf5L9YaG3eKTm7HQzls9J+A9YYcGI5Quh1r2Y= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 h1:6jZVETqmYCadGFvrYEQfC5fAQmlo80CeL5psbno6r0s= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21/go.mod h1:1SR0GbLlnN3QUmYaflZNiH1ql+1qrSiB2vwcJ+4UM60= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= github.com/aws/aws-sdk-go-v2/service/ec2 v1.162.0 h1:A1YMX7uMzXhfIEL9zc5049oQgSaH4ZeXx/sOth0dk/I= @@ -124,8 +120,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3/go.mod h1: github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2/go.mod h1:45MfaXZ0cNbeuT0KQ1XJylq8A6+OpVV2E5kvY/Kq+u8= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 h1:HGErhhrxZlQ044RiM+WdoZxp0p+EGM62y3L6pwA4olE= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17/go.mod h1:RkZEx4l0EHYDJpWppMJ3nD9wZJAa8/0lq9aVC+r2UII= -github.com/aws/aws-sdk-go-v2/service/kms v1.36.2 h1:yERi4A+3+9emx/NKSQ5bf0QP7DHCGU0bjv3pxdpDcsg= -github.com/aws/aws-sdk-go-v2/service/kms v1.36.2/go.mod h1:OHmlX4+o0XIlJAQGAHPIy0N9yZcYS/vNG+T7geSNcFw= +github.com/aws/aws-sdk-go-v2/service/kms v1.37.2 h1:tfBABi5R6aSZlhgTWHxL+opYUDOnIGoNcJLwVYv0jLM= +github.com/aws/aws-sdk-go-v2/service/kms v1.37.2/go.mod h1:dZYFcQwuoh+cLOlFnZItijZptmyDhRIkOKWFO1CfzV8= github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7NkwbjlijluLsrIbu/iyl35RO4= github.com/aws/aws-sdk-go-v2/service/sso v1.1.1/go.mod h1:SuZJxklHxLAXgLTc1iFXbEWkXs7QRTQpCLGaKIprQW0= github.com/aws/aws-sdk-go-v2/service/sso v1.22.3 h1:Fv1vD2L65Jnp5QRsdiM64JvUM4Xe+E0JyVsRQKv6IeA= @@ -136,8 +132,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxq github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 h1:ZsDKRLXGWHk8WdtyYMoGNO7bTudrvuKpDKgMVRlepGE= github.com/aws/aws-sdk-go-v2/service/sts v1.30.3/go.mod h1:zwySh8fpFyXp9yOr/KVzxOl8SRqgf/IDw5aUt9UKFcQ= github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw= -github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA= -github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= +github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= +github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -334,8 +330,6 @@ github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7 github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= -github.com/go-cmd/cmd v1.4.1 h1:JUcEIE84v8DSy02XTZpUDeGKExk2oW3DA10hTjbQwmc= -github.com/go-cmd/cmd v1.4.1/go.mod h1:tbBenttXtZU4c5djS1o7PWL5pd2xAr5sIqH1kGdNiRc= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= @@ -370,8 +364,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= -github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= -github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= @@ -1247,8 +1239,8 @@ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw= -google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -1260,8 +1252,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/evm/evm.go b/pkg/evm/evm.go index 198685351..1ed71ca4e 100644 --- a/pkg/evm/evm.go +++ b/pkg/evm/evm.go @@ -16,7 +16,6 @@ import ( "github.com/ava-labs/subnet-evm/core/types" "github.com/ava-labs/subnet-evm/ethclient" "github.com/ava-labs/subnet-evm/interfaces" - subnetEvmInterfaces "github.com/ava-labs/subnet-evm/interfaces" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/precompile/contracts/warp" "github.com/ava-labs/subnet-evm/predicate" @@ -258,6 +257,7 @@ func GetSignedTxToMethodWithWarpMessage( callData []byte, value *big.Int, ) (*types.Transaction, error) { + const defaultGasLimit = 2_000_000 privateKey, err := crypto.HexToECDSA(privateKeyStr) if err != nil { return nil, err @@ -289,7 +289,10 @@ func GetSignedTxToMethodWithWarpMessage( } gasLimit, err := EstimateGasLimit(client, msg) if err != nil { - return nil, err + // assuming this is related to the tx itself. + // just using default gas limit, and let the user debug the + // tx if needed so + gasLimit = defaultGasLimit } tx := types.NewTx(&types.DynamicFeeTx{ ChainID: chainID, @@ -608,7 +611,7 @@ func ExtractWarpMessageFromReceipt( ctx context.Context, receipt *types.Receipt, ) (*avalancheWarp.UnsignedMessage, error) { - logs, err := client.FilterLogs(ctx, subnetEvmInterfaces.FilterQuery{ + logs, err := client.FilterLogs(ctx, interfaces.FilterQuery{ BlockHash: &receipt.BlockHash, Addresses: []common.Address{warp.Module.Address}, }) diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index 309a55f24..bf0aa8196 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -4,7 +4,6 @@ package validatormanager import ( _ "embed" - "encoding/hex" "fmt" "math/big" "strings" @@ -81,7 +80,7 @@ func PoAValidatorManagerInitialize( } func TransactionError(tx *types.Transaction, err error, msg string, args ...interface{}) error { - msgSuffix := ":%w" + msgSuffix := ": %w" if tx != nil { msgSuffix += fmt.Sprintf(" (txHash=%s)", tx.Hash().String()) } @@ -381,8 +380,6 @@ func PoaValidatorManagerGetSubnetValidatorRegistrationMessage( if err != nil { return nil, ids.Empty, err } - fmt.Println("check", registerSubnetValidatorUnsignedMessage.ID()) - fmt.Println(hex.EncodeToString(registerSubnetValidatorUnsignedMessage.Bytes())) signatureAggregator, err := interchain.NewSignatureAggregator( network, aggregatorLogger, @@ -479,3 +476,117 @@ func PoAValidatorManagerCompleteValidatorRegistration( uint32(0), ) } + +func InitValidatorRegistration( + app *application.Avalanche, + network models.Network, + rpcURL string, + chainSpec contract.ChainSpec, + ownerPrivateKey string, + nodeID ids.NodeID, + blsPublicKey []byte, + expiry uint64, + balanceOwners warpMessage.PChainOwner, + disableOwners warpMessage.PChainOwner, + weight uint64, + aggregatorExtraPeerEndpoints []string, +) (*warp.Message, ids.ID, error) { + subnetID, err := contract.GetSubnetID( + app, + network, + chainSpec, + ) + if err != nil { + return nil, ids.Empty, err + } + blockchainID, err := contract.GetBlockchainID( + app, + network, + chainSpec, + ) + if err != nil { + return nil, ids.Empty, err + } + managerAddress := common.HexToAddress(ValidatorContractAddress) + tx, _, err := PoAValidatorManagerInitializeValidatorRegistration( + rpcURL, + managerAddress, + ownerPrivateKey, + nodeID, + blsPublicKey, + expiry, + balanceOwners, + disableOwners, + weight, + ) + if err != nil { + _ = tx + //return nil, ids.Empty, TransactionError(tx, err, "failure initializing validator registration") + } + return PoaValidatorManagerGetSubnetValidatorRegistrationMessage( + network, + app.Log, + logging.Info, + 0, + aggregatorExtraPeerEndpoints, + subnetID, + blockchainID, + managerAddress, + nodeID, + [48]byte(blsPublicKey), + expiry, + balanceOwners, + disableOwners, + weight, + ) +} + +func FinishValidatorRegistration( + app *application.Avalanche, + network models.Network, + rpcURL string, + chainSpec contract.ChainSpec, + privateKey string, + validationID ids.ID, + aggregatorExtraPeerEndpoints []string, +) error { + managerAddress := common.HexToAddress(ValidatorContractAddress) + subnetID, err := contract.GetSubnetID( + app, + network, + chainSpec, + ) + if err != nil { + return err + } + signedMessage, err := PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( + network, + app.Log, + logging.Info, + 0, + aggregatorExtraPeerEndpoints, + subnetID, + validationID, + true, + ) + if err != nil { + return err + } + if err := evm.SetupProposerVM( + rpcURL, + privateKey, + ); err != nil { + return err + } + tx, _, err := PoAValidatorManagerCompleteValidatorRegistration( + rpcURL, + managerAddress, + privateKey, + signedMessage, + ) + if err != nil { + _ = tx + //return TransactionError(tx, err, "failure completing validator registration") + } + return nil +} From 918e28e7da29f1cee563de27af7718e9e9512d6d Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 12:09:29 -0300 Subject: [PATCH 40/57] use relayer branch --- go.mod | 4 +--- go.sum | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 30db8b622..3b8e83d7d 100644 --- a/go.mod +++ b/go.mod @@ -2,13 +2,11 @@ module github.com/ava-labs/avalanche-cli go 1.22.8 -replace github.com/ava-labs/awm-relayer => ../awm-relayer - require ( github.com/ava-labs/apm v1.0.0 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344 github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 - github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 + github.com/ava-labs/awm-relayer v1.4.1-0.20241014150833-56c34fc5124b github.com/ava-labs/coreth v0.13.8 github.com/ava-labs/subnet-evm v0.6.10 github.com/aws/aws-sdk-go-v2 v1.32.2 diff --git a/go.sum b/go.sum index 60613bf6e..506751081 100644 --- a/go.sum +++ b/go.sum @@ -87,6 +87,8 @@ github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb134 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241005224128-cc3c07bb1344/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= +github.com/ava-labs/awm-relayer v1.4.1-0.20241014150833-56c34fc5124b h1:IFGojn8/tbbccw/LzPmcdaMiDK9Rpz2Qh+08woL4QZo= +github.com/ava-labs/awm-relayer v1.4.1-0.20241014150833-56c34fc5124b/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c= From b91ce21b1af1ae61e6c602df3dc721f44621560c Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 15:45:47 -0300 Subject: [PATCH 41/57] partial work --- cmd/blockchaincmd/add_validator.go | 473 ++++++++-------------- cmd/blockchaincmd/change_weight.go | 4 +- cmd/blockchaincmd/prompt_genesis_input.go | 6 +- pkg/validatormanager/validatormanager.go | 6 +- 4 files changed, 169 insertions(+), 320 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index 7c85333a4..2c9c177d1 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -15,7 +15,6 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/cobrautils" "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanche-cli/pkg/contract" - "github.com/ava-labs/avalanche-cli/pkg/evm" "github.com/ava-labs/avalanche-cli/pkg/keychain" "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" @@ -27,6 +26,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/validatormanager" "github.com/ava-labs/avalanchego/ids" avagoconstants "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/vms/platformvm" warpMessage "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" @@ -41,20 +41,22 @@ var ( networkoptions.Mainnet, } - nodeIDStr string - nodeEndpoint string - balance uint64 - weight uint64 - startTimeStr string - duration time.Duration - defaultValidatorParams bool - useDefaultStartTime bool - useDefaultDuration bool - useDefaultWeight bool - waitForTxAcceptance bool - publicKey string - pop string - changeAddr string + nodeIDStr string + nodeEndpoint string + balance uint64 + weight uint64 + startTimeStr string + duration time.Duration + defaultValidatorParams bool + useDefaultStartTime bool + useDefaultDuration bool + useDefaultWeight bool + waitForTxAcceptance bool + publicKey string + pop string + remainingBalancheOwnerAddr string + disableOwnerAddr string + rpcURL string errNoSubnetID = errors.New("failed to find the subnet ID for this subnet, has it been deployed/created on this network?") errMutuallyExclusiveDurationOptions = errors.New("--use-default-duration/--use-default-validator-params and --staking-period are mutually exclusive") @@ -94,15 +96,49 @@ Testnet or Mainnet.`, cmd.Flags().StringVar(&nodeIDStr, "node-id", "", "node-id of the validator to add") cmd.Flags().StringVar(&publicKey, "bls-public-key", "", "set the BLS public key of the validator to add") cmd.Flags().StringVar(&pop, "bls-proof-of-possession", "", "set the BLS proof of possession of the validator to add") - cmd.Flags().StringVar(&changeAddr, "change-address", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet") + cmd.Flags().StringVar(&remainingBalancheOwnerAddr, "remaining-balance-owner", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet") + cmd.Flags().StringVar(&disableOwnerAddr, "disable-owner", "", "P-Chain address that will able to disable the validator with a P-Chain transaction") cmd.Flags().StringVar(&nodeEndpoint, "node-endpoint", "", "gather node id/bls from publicly available avalanchego apis on the given endpoint") cmd.Flags().StringSliceVar(&privateAggregatorEndpoints, "private-aggregator-endpoints", nil, "endpoints for private nodes that are not available as network peers but are needed in signature aggregation") privateKeyFlags.AddToCmd(cmd, "to pay fees for completing the validator's registration (blockchain gas token)") + cmd.Flags().StringVar(&rpcURL, "rpc", "", "connect to validator manager at the given rpc endpoint") return cmd } func addValidator(_ *cobra.Command, args []string) error { blockchainName := args[0] + _, err := ValidateSubnetNameAndGetChains([]string{blockchainName}) + if err != nil { + return err + } + + network, err := networkoptions.GetNetworkFromCmdLineFlags( + app, + "", + globalNetworkFlags, + true, + false, + addValidatorSupportedNetworkOptions, + "", + ) + if err != nil { + return err + } + + fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee + kc, err := keychain.GetKeychainFromCmdLineFlags( + app, + "to pay for transaction fees on P-Chain", + network, + keyName, + useEwoq, + useLedger, + ledgerAddresses, + fee, + ) + if err != nil { + return err + } if nodeEndpoint != "" { infoClient := info.NewClient(nodeEndpoint) @@ -116,6 +152,52 @@ func addValidator(_ *cobra.Command, args []string) error { publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:]) pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:]) } + if nodeIDStr == "" { + nodeID, err := PromptNodeID("add as a blockchain validator") + if err != nil { + return err + } + nodeIDStr = nodeID.String() + } + if sovereign && publicKey == "" && pop == "" { + publicKey, pop, err = promptProofOfPossession(true, true) + if err != nil { + return err + } + } + if err := prompts.ValidateNodeID(nodeIDStr); err != nil { + return err + } + + network.HandlePublicNetworkSimulation() + + if !sovereign { + if err := UpdateKeychainWithSubnetControlKeys(kc, network, blockchainName); err != nil { + return err + } + } + deployer := subnet.NewPublicDeployer(app, kc, network) + if !sovereign { + return CallAddValidatorNonSOV(deployer, network, kc, useLedger, blockchainName, nodeIDStr, defaultValidatorParams, waitForTxAcceptance) + } + return CallAddValidator(deployer, network, kc, blockchainName, nodeIDStr, publicKey, pop) +} + +func promptValidatorBalance() (uint64, error) { + ux.Logger.PrintToUser("Balance is used to pay for continuous fee to the P-Chain") + txt := "What balance would you like to assign to the bootstrap validator (in AVAX)?" + return app.Prompt.CaptureValidatorBalance(txt) +} + +func CallAddValidator( + deployer *subnet.PublicDeployer, + network models.Network, + kc *keychain.Keychain, + blockchainName string, + nodeIDStr string, + publicKey string, + pop string, +) error { nodeID, err := ids.NodeIDFromString(nodeIDStr) if err != nil { return err @@ -124,53 +206,17 @@ func addValidator(_ *cobra.Command, args []string) error { if err != nil { return fmt.Errorf("failure parsing BLS info: %w", err) } - expiry := uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix()) - network, err := networkoptions.GetNetworkFromCmdLineFlags( - app, - "", - globalNetworkFlags, - true, - false, - addValidatorSupportedNetworkOptions, - "", - ) - if err != nil { - return err - } + expiry := uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix()) chainSpec := contract.ChainSpec{ BlockchainName: blockchainName, } - rpcURL, _, err := contract.GetBlockchainEndpoints( - app, - network, - chainSpec, - false, - false, - ) - if err != nil { - return err - } - ux.Logger.PrintToUser(logging.Yellow.Wrap("RPC Endpoint: %s"), rpcURL) sc, err := app.LoadSidecar(chainSpec.BlockchainName) if err != nil { return fmt.Errorf("failed to load sidecar: %w", err) } - balanceOwners := warpMessage.PChainOwner{ - Threshold: 1, - Addresses: []ids.ShortID{ - ids.GenerateTestShortID(), - }, - } - disableOwners := warpMessage.PChainOwner{ - Threshold: 1, - Addresses: []ids.ShortID{ - ids.GenerateTestShortID(), - }, - } - ownerPrivateKeyFound, _, _, ownerPrivateKey, err := contract.SearchForManagedKey( app, network, @@ -184,6 +230,7 @@ func addValidator(_ *cobra.Command, args []string) error { return fmt.Errorf("not private key found for PoA manager owner %s", sc.PoAValidatorManagerOwner) } ux.Logger.PrintToUser(logging.Yellow.Wrap("PoA manager owner %s pays for the initialization of the validator's registration (Blockchain gas token)"), sc.PoAValidatorManagerOwner) + genesisAddress, genesisPrivateKey, err := contract.GetEVMSubnetPrefundedKey( app, network, @@ -210,18 +257,66 @@ func addValidator(_ *cobra.Command, args []string) error { } } - kc, err := keychain.GetKeychainFromCmdLineFlags( - app, - "to pay for transaction fees on P-Chain", - network, - keyName, - useEwoq, - useLedger, - ledgerAddresses, - 0, - ) + if rpcURL == "" { + rpcURL, _, err = contract.GetBlockchainEndpoints( + app, + network, + chainSpec, + true, + false, + ) + if err != nil { + return err + } + } + ux.Logger.PrintToUser(logging.Yellow.Wrap("RPC Endpoint: %s"), rpcURL) + + if balance == 0 { + balance, err = promptValidatorBalance() + if err != nil { + return err + } + } + + if remainingBalancheOwnerAddr == "" { + remainingBalancheOwnerAddr, err = getKeyForChangeOwner("", network) + if err != nil { + return err + } + } + addrs, err := address.ParseToIDs([]string{remainingBalancheOwnerAddr}) if err != nil { - return err + return fmt.Errorf("failure parsing remaining balanche owner address %s: %w", remainingBalancheOwnerAddr, err) + } + balanceOwners := warpMessage.PChainOwner{ + Threshold: 1, + Addresses: addrs, + } + + if disableOwnerAddr == "" { + disableOwnerAddr, err := prompts.PromptAddress( + app.Prompt, + "objetivo", + app.GetKeyDir(), + app.GetKey, + "", + network, + prompts.PChainFormat, + "pepito", + ) + if err != nil { + return err + } + fmt.Println(disableOwnerAddr) + } + + return nil + + disableOwners := warpMessage.PChainOwner{ + Threshold: 1, + Addresses: []ids.ShortID{ + ids.GenerateTestShortID(), + }, } signedMessage, validationID, err := validatormanager.InitValidatorRegistration( @@ -243,11 +338,9 @@ func addValidator(_ *cobra.Command, args []string) error { } ux.Logger.PrintToUser("ValidationID: %s", validationID) - deployer := subnet.NewPublicDeployer(app, kc, network) - balance = constants.BootstrapValidatorBalance txID, _, err := deployer.RegisterL1Validator(balance, blsInfo, signedMessage) if err != nil { - // return err + return err } ux.Logger.PrintToUser("RegisterSubnetValidatorTx ID: %s", txID) @@ -273,254 +366,10 @@ func addValidator(_ *cobra.Command, args []string) error { ux.Logger.GreenCheckmarkToUser("Validator successfully added to the Subnet") - return nil - - tx, _, err := validatormanager.PoAValidatorManagerInitializeValidatorRegistration( - rpcURL, - common.HexToAddress(validatormanager.ValidatorContractAddress), - ownerPrivateKey, - nodeID, - blsInfo.PublicKey[:], - expiry, - balanceOwners, - disableOwners, - weight, - ) - if err != nil { - //return validatormanager.TransactionError(tx, err, "failure initializing validator registration") - } - client, err := evm.GetClient(rpcURL) - if err != nil { - return err - } - defer client.Close() - subnetID, err := contract.GetSubnetID( - app, - network, - chainSpec, - ) - if err != nil { - return err - } - blockchainID, err := contract.GetBlockchainID( - app, - network, - chainSpec, - ) - if err != nil { - return err - } - signedMessage, validationID, err = validatormanager.PoaValidatorManagerGetSubnetValidatorRegistrationMessage( - network, - app.Log, - logging.Info, - 0, - privateAggregatorEndpoints, - subnetID, - blockchainID, - common.HexToAddress(validatormanager.ValidatorContractAddress), - nodeID, - blsInfo.PublicKey, - expiry, - balanceOwners, - disableOwners, - weight, - ) - if err != nil { - return err - } - - return nil - - balance = constants.BootstrapValidatorBalance - txID, _, err = deployer.RegisterL1Validator(balance, blsInfo, signedMessage) - if err != nil { - // return err - } - ux.Logger.PrintToUser("RegisterSubnetValidatorTx ID: %s", txID) - - if err := UpdatePChainHeight( - deployer, - kc.Addresses().List()[0], - "Waiting for P-Chain to update validator information ...", - ); err != nil { - return err - } - - subnetValidatorRegistrationSignedMessage, err := validatormanager.PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( - network, - app.Log, - logging.Info, - 0, - privateAggregatorEndpoints, - subnetID, - validationID, - true, - ) - if err != nil { - return err - } - fmt.Println("TODO BIEN") - - if err := evm.SetupProposerVM( - rpcURL, - privateKey, - ); err != nil { - return err - } - - tx, _, err = validatormanager.PoAValidatorManagerCompleteValidatorRegistration( - rpcURL, - common.HexToAddress(validatormanager.ValidatorContractAddress), - privateKey, - subnetValidatorRegistrationSignedMessage, - ) - if tx != nil { - fmt.Println("tx hash", tx.Hash()) - } - if err != nil { - return err - } - fmt.Println("TODO BIEN") - return nil - - err = prompts.ValidateNodeID(nodeIDStr) - if err != nil { - return err - } - - network, err = networkoptions.GetNetworkFromCmdLineFlags( - app, - "", - globalNetworkFlags, - true, - false, - addValidatorSupportedNetworkOptions, - "", - ) - if err != nil { - return err - } - fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee - kc, err = keychain.GetKeychainFromCmdLineFlags( - app, - constants.PayTxsFeesMsg, - network, - keyName, - useEwoq, - useLedger, - ledgerAddresses, - fee, - ) - if err != nil { - return err - } - network.HandlePublicNetworkSimulation() - if !sovereign { - if err := UpdateKeychainWithSubnetControlKeys(kc, network, blockchainName); err != nil { - return err - } - } - deployer = subnet.NewPublicDeployer(app, kc, network) - if !sovereign { - return CallAddValidatorNonSOV(deployer, network, kc, useLedger, blockchainName, nodeIDStr, defaultValidatorParams, waitForTxAcceptance) - } - return CallAddValidator(deployer, network, kc, useLedger, blockchainName, nodeIDStr) -} - -func promptValidatorBalance() (uint64, error) { - ux.Logger.PrintToUser("Balance is used to pay for continuous fee to the P-Chain") - txt := "What balance would you like to assign to the bootstrap validator (in AVAX)?" - return app.Prompt.CaptureValidatorBalance(txt) -} - -func CallAddValidator( - deployer *subnet.PublicDeployer, - network models.Network, - kc *keychain.Keychain, - useLedgerSetting bool, - blockchainName string, - nodeIDStrFormat string, -) error { - useLedger = useLedgerSetting - - _, err := ValidateSubnetNameAndGetChains([]string{blockchainName}) - if err != nil { - return err - } - - switch network.Kind { - case models.Devnet: - if !useLedger && keyName == "" { - useLedger, keyName, err = prompts.GetKeyOrLedger(app.Prompt, constants.PayTxsFeesMsg, app.GetKeyDir(), false) - if err != nil { - return err - } - } - case models.Fuji: - if !useLedger && keyName == "" { - useLedger, keyName, err = prompts.GetKeyOrLedger(app.Prompt, constants.PayTxsFeesMsg, app.GetKeyDir(), false) - if err != nil { - return err - } - } - case models.Mainnet: - useLedger = true - if keyName != "" { - return ErrStoredKeyOnMainnet - } - default: - return errors.New("unsupported network") - } - - sc, err := app.LoadSidecar(blockchainName) - if err != nil { - return err - } - - subnetID := sc.Networks[network.Name()].SubnetID - if subnetID == ids.Empty { - return errNoSubnetID - } - - // TODO: implement getting validator manager controller address - //kcKeys, err := kc.PChainFormattedStrAddresses() - //if err != nil { - // return err - //} - - if nodeIDStr == "" { - nodeID, err := PromptNodeID("add as a blockchain validator") - if err != nil { - return err - } - nodeIDStr = nodeID.String() - } - - publicKey, pop, err = promptProofOfPossession(publicKey == "", pop == "") - if err != nil { - return err - } - - if balance == 0 { - balance, err = promptValidatorBalance() - if err != nil { - return err - } - } - - if changeAddr == "" { - changeAddr, err = getKeyForChangeOwner("", network) - if err != nil { - return err - } - } - - ux.Logger.PrintToUser("NodeID: %s", nodeIDStrFormat) + ux.Logger.PrintToUser("NodeID: %s", nodeID) ux.Logger.PrintToUser("Network: %s", network.Name()) ux.Logger.PrintToUser("Weight: %d", weight) ux.Logger.PrintToUser("Balance: %d", balance) - ux.Logger.PrintToUser("Change Address: %s", changeAddr) ux.Logger.PrintToUser("Inputs complete, issuing transaction to add the provided validator information...") /* diff --git a/cmd/blockchaincmd/change_weight.go b/cmd/blockchaincmd/change_weight.go index 65f700f63..6b4080565 100644 --- a/cmd/blockchaincmd/change_weight.go +++ b/cmd/blockchaincmd/change_weight.go @@ -166,13 +166,13 @@ func setWeight(_ *cobra.Command, args []string) error { return err } - changeAddr, err = getChangeAddrFromPChain() + remainingBalancheOwnerAddr, err = getChangeAddrFromPChain() if err != nil { return fmt.Errorf("failure parsing change owner address: %w", err) } // add back validator to subnet with updated weight - return CallAddValidator(deployer, network, kc, useLedger, blockchainName, nodeID.String()) + return CallAddValidator(deployer, network, kc, blockchainName, nodeID.String(), publicKey, pop) } // getValidatorBalanceFromPChain gets remaining balance of validator from p chain diff --git a/cmd/blockchaincmd/prompt_genesis_input.go b/cmd/blockchaincmd/prompt_genesis_input.go index 842a2cc45..5deea6986 100644 --- a/cmd/blockchaincmd/prompt_genesis_input.go +++ b/cmd/blockchaincmd/prompt_genesis_input.go @@ -32,8 +32,10 @@ func getValidatorContractManagerAddr() (string, error) { } func promptProofOfPossession(promptPublicKey, promptPop bool) (string, string, error) { - ux.Logger.PrintToUser("Next, we need the public key and proof of possession of the node's BLS") - ux.Logger.PrintToUser("Check https://docs.avax.network/api-reference/info-api#infogetnodeid for instructions on calling info.getNodeID API") + if promptPublicKey || promptPop { + ux.Logger.PrintToUser("Next, we need the public key and proof of possession of the node's BLS") + ux.Logger.PrintToUser("Check https://docs.avax.network/api-reference/info-api#infogetnodeid for instructions on calling info.getNodeID API") + } var err error publicKey := "" proofOfPossesion := "" diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index bf0aa8196..4be2daa55 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -520,8 +520,7 @@ func InitValidatorRegistration( weight, ) if err != nil { - _ = tx - //return nil, ids.Empty, TransactionError(tx, err, "failure initializing validator registration") + return nil, ids.Empty, TransactionError(tx, err, "failure initializing validator registration") } return PoaValidatorManagerGetSubnetValidatorRegistrationMessage( network, @@ -585,8 +584,7 @@ func FinishValidatorRegistration( signedMessage, ) if err != nil { - _ = tx - //return TransactionError(tx, err, "failure completing validator registration") + return TransactionError(tx, err, "failure completing validator registration") } return nil } From 72c14640dbfbb5d783a125dcf1c96afbe298cf70 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 15:47:58 -0300 Subject: [PATCH 42/57] use anr main --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d28047098..56852d20d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241012120846-016fa62d1f70 + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014184529-5bcdd0c507ec github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index 254aa363c..3672efa9d 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241012120846-016fa62d1f70 h1:t+d9CHpX7kKuC/LD7HjCYlcGn2ztA/deBJJS+aJL9NA= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241012120846-016fa62d1f70/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014184529-5bcdd0c507ec h1:SPDvCcpYkG7kVDdogbW9tDYTYTIJkAeBzU4gAm3ZhXs= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014184529-5bcdd0c507ec/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3 h1:JfVooBCdMzpeGUT9/phJNl2GHflkGehlMJokXeWKa2A= github.com/ava-labs/avalanchego v1.12.0-initial-poc.3/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241010130039-bceba83023b8 h1:M58jcqAG51RrKKVCfhAZpPqCFdkqRzahEgkFqQA5EME= From 3ed244f678cf2b56d8e0a97c9700538b131a2af7 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 16:22:21 -0300 Subject: [PATCH 43/57] working for devnets --- cmd/blockchaincmd/add_validator.go | 102 ++++++++++------------------- cmd/blockchaincmd/change_weight.go | 2 +- 2 files changed, 37 insertions(+), 67 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index 2c9c177d1..931f74424 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -9,7 +9,6 @@ import ( "time" "github.com/ava-labs/avalanchego/api/info" - warpPlatformVM "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ethereum/go-ethereum/common" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" @@ -41,22 +40,22 @@ var ( networkoptions.Mainnet, } - nodeIDStr string - nodeEndpoint string - balance uint64 - weight uint64 - startTimeStr string - duration time.Duration - defaultValidatorParams bool - useDefaultStartTime bool - useDefaultDuration bool - useDefaultWeight bool - waitForTxAcceptance bool - publicKey string - pop string - remainingBalancheOwnerAddr string - disableOwnerAddr string - rpcURL string + nodeIDStr string + nodeEndpoint string + balance uint64 + weight uint64 + startTimeStr string + duration time.Duration + defaultValidatorParams bool + useDefaultStartTime bool + useDefaultDuration bool + useDefaultWeight bool + waitForTxAcceptance bool + publicKey string + pop string + remainingBalanceOwnerAddr string + disableOwnerAddr string + rpcURL string errNoSubnetID = errors.New("failed to find the subnet ID for this subnet, has it been deployed/created on this network?") errMutuallyExclusiveDurationOptions = errors.New("--use-default-duration/--use-default-validator-params and --staking-period are mutually exclusive") @@ -96,7 +95,7 @@ Testnet or Mainnet.`, cmd.Flags().StringVar(&nodeIDStr, "node-id", "", "node-id of the validator to add") cmd.Flags().StringVar(&publicKey, "bls-public-key", "", "set the BLS public key of the validator to add") cmd.Flags().StringVar(&pop, "bls-proof-of-possession", "", "set the BLS proof of possession of the validator to add") - cmd.Flags().StringVar(&remainingBalancheOwnerAddr, "remaining-balance-owner", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet") + cmd.Flags().StringVar(&remainingBalanceOwnerAddr, "remaining-balance-owner", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet") cmd.Flags().StringVar(&disableOwnerAddr, "disable-owner", "", "P-Chain address that will able to disable the validator with a P-Chain transaction") cmd.Flags().StringVar(&nodeEndpoint, "node-endpoint", "", "gather node id/bls from publicly available avalanchego apis on the given endpoint") cmd.Flags().StringSliceVar(&privateAggregatorEndpoints, "private-aggregator-endpoints", nil, "endpoints for private nodes that are not available as network peers but are needed in signature aggregation") @@ -278,45 +277,43 @@ func CallAddValidator( } } - if remainingBalancheOwnerAddr == "" { - remainingBalancheOwnerAddr, err = getKeyForChangeOwner("", network) + if remainingBalanceOwnerAddr == "" { + remainingBalanceOwnerAddr, err = getKeyForChangeOwner("", network) if err != nil { return err } } - addrs, err := address.ParseToIDs([]string{remainingBalancheOwnerAddr}) + remainingBalanceOwnerAddrID, err := address.ParseToIDs([]string{remainingBalanceOwnerAddr}) if err != nil { - return fmt.Errorf("failure parsing remaining balanche owner address %s: %w", remainingBalancheOwnerAddr, err) + return fmt.Errorf("failure parsing remaining balanche owner address %s: %w", remainingBalanceOwnerAddr, err) } - balanceOwners := warpMessage.PChainOwner{ + remainingBalanceOwners := warpMessage.PChainOwner{ Threshold: 1, - Addresses: addrs, + Addresses: remainingBalanceOwnerAddrID, } if disableOwnerAddr == "" { - disableOwnerAddr, err := prompts.PromptAddress( + disableOwnerAddr, err = prompts.PromptAddress( app.Prompt, - "objetivo", + "be able to disable the validator using P-Chain transactions", app.GetKeyDir(), app.GetKey, "", network, prompts.PChainFormat, - "pepito", + "Enter P-Chain address (Example: P-...)", ) if err != nil { return err } - fmt.Println(disableOwnerAddr) } - - return nil - + disableOwnerAddrID, err := address.ParseToIDs([]string{disableOwnerAddr}) + if err != nil { + return fmt.Errorf("failure parsing disable owner address %s: %w", disableOwnerAddr, err) + } disableOwners := warpMessage.PChainOwner{ Threshold: 1, - Addresses: []ids.ShortID{ - ids.GenerateTestShortID(), - }, + Addresses: disableOwnerAddrID, } signedMessage, validationID, err := validatormanager.InitValidatorRegistration( @@ -328,7 +325,7 @@ func CallAddValidator( nodeID, blsInfo.PublicKey[:], expiry, - balanceOwners, + remainingBalanceOwners, disableOwners, weight, privateAggregatorEndpoints, @@ -364,42 +361,15 @@ func CallAddValidator( return err } + ux.Logger.PrintToUser(" NodeID: %s", nodeID) + ux.Logger.PrintToUser(" Network: %s", network.Name()) + ux.Logger.PrintToUser(" Weight: %d", weight) + ux.Logger.PrintToUser(" Balance: %d", balance) ux.Logger.GreenCheckmarkToUser("Validator successfully added to the Subnet") - ux.Logger.PrintToUser("NodeID: %s", nodeID) - ux.Logger.PrintToUser("Network: %s", network.Name()) - ux.Logger.PrintToUser("Weight: %d", weight) - ux.Logger.PrintToUser("Balance: %d", balance) - ux.Logger.PrintToUser("Inputs complete, issuing transaction to add the provided validator information...") - - /* - blsInfo, err := getBLSInfo(publicKey, pop) - if err != nil { - return fmt.Errorf("failure parsing BLS info: %w", err) - } - nodeID, err := ids.NodeIDFromString(nodeIDStrFormat) - if err != nil { - return err - } - // TODO: generate warp message - // expiry is set to 48 hours from time of transaction - message, err := generateWarpMessageAddValidator(subnetID, nodeID, weight, publicKey, uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix())) - if err != nil { - return err - } - tx, err := deployer.RegisterL1Validator(balance, blsInfo, message) - if err != nil { - return err - } - ux.Logger.GreenCheckmarkToUser("Register Subnet Validator Tx ID: %s", tx.ID()) - */ return nil } -func generateWarpMessageAddValidator(subnetID ids.ID, nodeID ids.NodeID, weight uint64, blsPublicKey string, expiry uint64) (warpPlatformVM.Message, error) { - return warpPlatformVM.Message{}, nil -} - func CallAddValidatorNonSOV( deployer *subnet.PublicDeployer, network models.Network, diff --git a/cmd/blockchaincmd/change_weight.go b/cmd/blockchaincmd/change_weight.go index 6b4080565..218ef3482 100644 --- a/cmd/blockchaincmd/change_weight.go +++ b/cmd/blockchaincmd/change_weight.go @@ -166,7 +166,7 @@ func setWeight(_ *cobra.Command, args []string) error { return err } - remainingBalancheOwnerAddr, err = getChangeAddrFromPChain() + remainingBalanceOwnerAddr, err = getChangeAddrFromPChain() if err != nil { return fmt.Errorf("failure parsing change owner address: %w", err) } From 5859945901fbf01762a6f7acb6b09e49f33d153f Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 17:15:15 -0300 Subject: [PATCH 44/57] is this working --- cmd/blockchaincmd/add_validator.go | 2 +- cmd/nodecmd/local.go | 5 +++-- pkg/node/helper.go | 4 ++-- pkg/node/sync.go | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index 931f74424..8bf0392c7 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -278,7 +278,7 @@ func CallAddValidator( } if remainingBalanceOwnerAddr == "" { - remainingBalanceOwnerAddr, err = getKeyForChangeOwner("", network) + remainingBalanceOwnerAddr, err = getKeyForChangeOwner(nodeID.String(), "", network) if err != nil { return err } diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 7e3ea6c8f..f9ebd5ff1 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -13,6 +13,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/localnet" "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" + "github.com/ava-labs/avalanche-cli/pkg/node" "github.com/ava-labs/avalanche-cli/pkg/subnet" "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" @@ -542,8 +543,8 @@ func localTrack(_ *cobra.Command, args []string) error { rpcEndpoints := set.Of(networkInfo.RPCEndpoints...) wsEndpoints := set.Of(networkInfo.WSEndpoints...) for _, publicEndpoint := range publicEndpoints { - rpcEndpoints.Add(getRPCEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) - wsEndpoints.Add(getWSEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) + rpcEndpoints.Add(node.GetRPCEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) + wsEndpoints.Add(node.GetWSEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) } networkInfo.RPCEndpoints = rpcEndpoints.List() networkInfo.WSEndpoints = wsEndpoints.List() diff --git a/pkg/node/helper.go b/pkg/node/helper.go index d97fec3f9..45d746c40 100644 --- a/pkg/node/helper.go +++ b/pkg/node/helper.go @@ -150,7 +150,7 @@ func DisconnectHosts(hosts []*models.Host) { } } -func getWSEndpoint(endpoint string, blockchainID string) string { +func GetWSEndpoint(endpoint string, blockchainID string) string { return models.NewDevnetNetwork(endpoint, 0).BlockchainWSEndpoint(blockchainID) } @@ -176,7 +176,7 @@ func getPublicEndpoints( return endpoints, nil } -func getRPCEndpoint(endpoint string, blockchainID string) string { +func GetRPCEndpoint(endpoint string, blockchainID string) string { return models.NewDevnetNetwork(endpoint, 0).BlockchainEndpoint(blockchainID) } diff --git a/pkg/node/sync.go b/pkg/node/sync.go index d30f1c38f..96c8511de 100644 --- a/pkg/node/sync.go +++ b/pkg/node/sync.go @@ -160,8 +160,8 @@ func trackSubnet( return err } for _, publicEndpoint := range publicEndpoints { - rpcEndpoints.Add(getRPCEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) - wsEndpoints.Add(getWSEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) + rpcEndpoints.Add(GetRPCEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) + wsEndpoints.Add(GetWSEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) } networkInfo.RPCEndpoints = rpcEndpoints.List() networkInfo.WSEndpoints = wsEndpoints.List() From deaa32106a2bb099658632b234dc2f5b6d57bdfd Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 17:40:12 -0300 Subject: [PATCH 45/57] working for local --- cmd/blockchaincmd/add_validator.go | 7 +++++++ cmd/contractcmd/init_poa_validator_manager.go | 2 +- cmd/nodecmd/local.go | 13 ++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index 8bf0392c7..f7ef3e7fb 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -316,6 +316,13 @@ func CallAddValidator( Addresses: disableOwnerAddrID, } + if len(privateAggregatorEndpoints) == 0 { + privateAggregatorEndpoints, err = GetAggregatorExtraPeerEndpoints(network) + if err != nil { + return err + } + } + 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 e56b547c2..dd0e4776c 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -96,7 +96,7 @@ func initPOAManager(_ *cobra.Command, args []string) error { if privateKey == "" { privateKey, err = prompts.PromptPrivateKey( app.Prompt, - "Which key to you want to use to pay for initializing Proof of Authority Validator Manager contract? (Uses Blockchain gas token)", + "pay for initializing Proof of Authority Validator Manager contract? (Uses Blockchain gas token)", app.GetKeyDir(), app.GetKey, genesisAddress, diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index f9ebd5ff1..617fb4bd1 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -36,6 +36,7 @@ var ( stakingTLSKeyPath string stakingCertKeyPath string stakingSignerKeyPath string + numNodes uint32 ) // const snapshotName = "local_snapshot" @@ -91,6 +92,7 @@ status by running avalanche node status local cmd.Flags().StringVar(&stakingTLSKeyPath, "staking-tls-key-path", "", "path to provided staking tls key for node") cmd.Flags().StringVar(&stakingCertKeyPath, "staking-cert-key-path", "", "path to provided staking cert key for node") cmd.Flags().StringVar(&stakingSignerKeyPath, "staking-signer-key-path", "", "path to provided staking signer key for node") + cmd.Flags().Uint32Var(&numNodes, "num-nodes", 1, "number of nodes to start") return cmd } @@ -187,6 +189,11 @@ func localStartNode(_ *cobra.Command, args []string) error { ctx, cancel := utils.GetANRContext() defer cancel() + // make sure rootDir exists + if err := os.MkdirAll(rootDir, 0o700); err != nil { + return fmt.Errorf("could not create root directory %s: %w", rootDir, err) + } + // starts server avalancheGoVersion := "latest" if avalanchegoBinaryPath == "" { @@ -300,10 +307,6 @@ func localStartNode(_ *cobra.Command, args []string) error { defer os.Remove(upgradePath) } - // make sure rootDir exists - if err := os.MkdirAll(rootDir, 0o700); err != nil { - return fmt.Errorf("could not create root directory %s: %w", rootDir, err) - } // make sure pluginDir exists if err := os.MkdirAll(pluginDir, 0o700); err != nil { return fmt.Errorf("could not create plugin directory %s: %w", pluginDir, err) @@ -325,7 +328,7 @@ func localStartNode(_ *cobra.Command, args []string) error { } anrOpts := []client.OpOption{ - client.WithNumNodes(1), + client.WithNumNodes(numNodes), client.WithNetworkID(network.ID), client.WithExecPath(avalancheGoBinPath), client.WithRootDataDir(rootDir), From 422537e9e1dc48c77122431ca9582e5a624f68d0 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 18:46:00 -0300 Subject: [PATCH 46/57] nit --- cmd/blockchaincmd/add_validator.go | 11 +++++------ cmd/blockchaincmd/deploy.go | 6 ++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index f7ef3e7fb..e78b6c6cd 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -184,7 +184,7 @@ func addValidator(_ *cobra.Command, args []string) error { func promptValidatorBalance() (uint64, error) { ux.Logger.PrintToUser("Balance is used to pay for continuous fee to the P-Chain") - txt := "What balance would you like to assign to the bootstrap validator (in AVAX)?" + txt := "What balance would you like to assign to the bootstrap validator (in nAVAX)?" return app.Prompt.CaptureValidatorBalance(txt) } @@ -316,12 +316,11 @@ func CallAddValidator( Addresses: disableOwnerAddrID, } - if len(privateAggregatorEndpoints) == 0 { - privateAggregatorEndpoints, err = GetAggregatorExtraPeerEndpoints(network) - if err != nil { - return err - } + networkAggregatorEndpoints, err := GetAggregatorExtraPeerEndpoints(network) + if err != nil { + return err } + privateAggregatorEndpoints = append(privateAggregatorEndpoints, networkAggregatorEndpoints...) signedMessage, validationID, err := validatormanager.InitValidatorRegistration( app, diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index c5440d530..7cb74310b 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -77,6 +77,7 @@ var ( bootstrapValidatorsJSONFilePath string privateKeyFlags contract.PrivateKeyFlags bootstrapEndpoints []string + convertOnly bool errMutuallyExlusiveControlKeys = errors.New("--control-keys and --same-control-key are mutually exclusive") ErrMutuallyExlusiveKeyLedger = errors.New("key source flags --key, --ledger/--ledger-addrs are mutually exclusive") @@ -132,6 +133,7 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`, cmd.Flags().StringVar(&bootstrapValidatorsJSONFilePath, "bootstrap-filepath", "", "JSON file path that provides details about bootstrap validators, leave Node-ID and BLS values empty if using --generate-node-id=true") cmd.Flags().BoolVar(&generateNodeID, "generate-node-id", false, "whether to create new node id for bootstrap validators (Node-ID and BLS values in bootstrap JSON file will be overridden if --bootstrap-filepath flag is used)") cmd.Flags().StringSliceVar(&bootstrapEndpoints, "bootstrap-endpoints", nil, "take validator node info from the given endpoints") + cmd.Flags().BoolVar(&convertOnly, "convert-only", false, "avoid node track, restart and poa manager setup") return cmd } @@ -727,7 +729,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { return err } - if !generateNodeID { + if !convertOnly { clusterName, err := node.GetClusterNameFromList(app) if err != nil { return err @@ -782,7 +784,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { } 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.GreenCheckmarkToUser("Converted subnet successfully generated") 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) From e47405b1c9f6be814c034dfa222963ccb8b7e328 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 19:30:41 -0300 Subject: [PATCH 47/57] working --- cmd/blockchaincmd/add_validator.go | 12 +++- cmd/blockchaincmd/deploy.go | 59 +++++++++++++++++-- cmd/contractcmd/init_poa_validator_manager.go | 17 ++++-- go.mod | 2 +- go.sum | 4 +- pkg/validatormanager/validatormanager.go | 13 ++-- sdk/interchain/signature-aggregator.go | 5 +- 7 files changed, 86 insertions(+), 26 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index e78b6c6cd..d4d88bb99 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -316,11 +316,17 @@ func CallAddValidator( Addresses: disableOwnerAddrID, } + // given by users + extraAggregatorPeers, err := UrisToPeers(privateAggregatorEndpoints) + if err != nil { + return err + } + // available in local cluster networkAggregatorEndpoints, err := GetAggregatorExtraPeerEndpoints(network) if err != nil { return err } - privateAggregatorEndpoints = append(privateAggregatorEndpoints, networkAggregatorEndpoints...) + extraAggregatorPeers = append(extraAggregatorPeers, networkAggregatorEndpoints...) signedMessage, validationID, err := validatormanager.InitValidatorRegistration( app, @@ -334,7 +340,7 @@ func CallAddValidator( remainingBalanceOwners, disableOwners, weight, - privateAggregatorEndpoints, + extraAggregatorPeers, ) if err != nil { return err @@ -362,7 +368,7 @@ func CallAddValidator( chainSpec, privateKey, validationID, - privateAggregatorEndpoints, + extraAggregatorPeers, ); err != nil { return err } diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 7cb74310b..092387032 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -13,6 +13,7 @@ import ( "time" "github.com/ava-labs/avalanche-cli/pkg/node" + "github.com/ava-labs/avalanchego/network/peer" "github.com/ava-labs/avalanchego/api/info" "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" @@ -764,7 +765,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { if err != nil { return err } - aggregatorExtraPeerEndpoints, err := GetAggregatorExtraPeerEndpoints(network) + extraAggregatorPeers, err := GetAggregatorExtraPeerEndpoints(network) if err != nil { return err } @@ -778,7 +779,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { genesisPrivateKey, common.HexToAddress(sidecar.PoAValidatorManagerOwner), avaGoBootstrapValidators, - aggregatorExtraPeerEndpoints, + extraAggregatorPeers, ); err != nil { return err } @@ -1052,8 +1053,54 @@ func LoadBootstrapValidator(filepath string) ([]models.SubnetValidator, error) { return subnetValidators, nil } -func GetAggregatorExtraPeerEndpoints(network models.Network) ([]string, error) { - aggregatorExtraPeerEndpoints := []string{} +func UrisToPeers(uris []string) ([]info.Peer, error) { + peers := []info.Peer{} + ctx, cancel := utils.GetANRContext() + defer cancel() + for _, uri := range uris { + client := info.NewClient(uri) + nodeID, _, err := client.GetNodeID(ctx) + if err != nil { + return nil, err + } + ip, err := client.GetNodeIP(ctx) + if err != nil { + return nil, err + } + peers = append(peers, info.Peer{ + Info: peer.Info{ + ID: nodeID, + PublicIP: ip, + }, + }) + } + return peers, nil +} + +func GetAggregatorExtraPeerEndpoints(network models.Network) ([]info.Peer, error) { + aggregatorExtraPeerEndpointsUris, err := GetAggregatorExtraPeerEndpointsUris(network) + if err != nil { + return nil, err + } + aggregatorPeers, err := UrisToPeers(aggregatorExtraPeerEndpointsUris) + if err != nil { + return nil, err + } + for _, uri := range aggregatorExtraPeerEndpointsUris { + infoClient := info.NewClient(uri) + ctx, cancel := utils.GetAPILargeContext() + defer cancel() + peers, err := infoClient.Peers(ctx) + if err != nil { + return nil, err + } + aggregatorPeers = append(aggregatorPeers, peers...) + } + return aggregatorPeers, nil +} + +func GetAggregatorExtraPeerEndpointsUris(network models.Network) ([]string, error) { + aggregatorExtraPeerEndpointsUris := []string{} if network.ClusterName != "" { clustersConfig, err := app.LoadClustersConfig() if err != nil { @@ -1076,9 +1123,9 @@ func GetAggregatorExtraPeerEndpoints(network models.Network) ([]string, error) { return nil, err } for _, nodeInfo := range status.ClusterInfo.NodeInfos { - aggregatorExtraPeerEndpoints = append(aggregatorExtraPeerEndpoints, nodeInfo.Uri) + aggregatorExtraPeerEndpointsUris = append(aggregatorExtraPeerEndpointsUris, nodeInfo.Uri) } } } - return aggregatorExtraPeerEndpoints, nil + return aggregatorExtraPeerEndpointsUris, nil } diff --git a/cmd/contractcmd/init_poa_validator_manager.go b/cmd/contractcmd/init_poa_validator_manager.go index dd0e4776c..24713f5e6 100644 --- a/cmd/contractcmd/init_poa_validator_manager.go +++ b/cmd/contractcmd/init_poa_validator_manager.go @@ -118,12 +118,17 @@ func initPOAManager(_ *cobra.Command, args []string) error { if err != nil { return err } - if len(privateAggregatorEndpoints) == 0 { - privateAggregatorEndpoints, err = blockchaincmd.GetAggregatorExtraPeerEndpoints(network) - if err != nil { - return err - } + // given by users + extraAggregatorPeers, err := blockchaincmd.UrisToPeers(privateAggregatorEndpoints) + if err != nil { + return err + } + // available in local cluster + networkAggregatorEndpoints, err := blockchaincmd.GetAggregatorExtraPeerEndpoints(network) + if err != nil { + return err } + extraAggregatorPeers = append(extraAggregatorPeers, networkAggregatorEndpoints...) if err := validatormanager.SetupPoA( app, network, @@ -132,7 +137,7 @@ func initPOAManager(_ *cobra.Command, args []string) error { privateKey, common.HexToAddress(sc.PoAValidatorManagerOwner), avaGoBootstrapValidators, - privateAggregatorEndpoints, + extraAggregatorPeers, ); err != nil { return err } diff --git a/go.mod b/go.mod index f74d9db3a..aae239d7e 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/ava-labs/apm v1.0.0 github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54 github.com/ava-labs/avalanchego v1.12.0-initial-poc.5 - github.com/ava-labs/awm-relayer v1.4.1-0.20241014150833-56c34fc5124b + github.com/ava-labs/awm-relayer v1.4.1-0.20241014222901-4b34ab86afd0 github.com/ava-labs/coreth v0.13.8 github.com/ava-labs/subnet-evm v0.6.10 github.com/aws/aws-sdk-go-v2 v1.32.2 diff --git a/go.sum b/go.sum index f6ddf53a5..184e729a8 100644 --- a/go.sum +++ b/go.sum @@ -83,14 +83,14 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014184529-5bcdd0c507ec h1:SPDvCcpYkG7kVDdogbW9tDYTYTIJkAeBzU4gAm3ZhXs= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014184529-5bcdd0c507ec/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54 h1:Hc06tSzeuQZTacGcrVLOnZjgKg1Cs655GT1Mmp9fCsU= github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54/go.mod h1:ASWB/CKJm8wVZUBp3DY0AV8jTBLCs01kzQz9GGwtzi8= github.com/ava-labs/avalanchego v1.12.0-initial-poc.5 h1:gW4xAqZNvkA4gP8M9yDyd7YUzuwfQbbCR+hgd1ztOto= github.com/ava-labs/avalanchego v1.12.0-initial-poc.5/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= github.com/ava-labs/awm-relayer v1.4.1-0.20241014150833-56c34fc5124b h1:IFGojn8/tbbccw/LzPmcdaMiDK9Rpz2Qh+08woL4QZo= github.com/ava-labs/awm-relayer v1.4.1-0.20241014150833-56c34fc5124b/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= +github.com/ava-labs/awm-relayer v1.4.1-0.20241014222901-4b34ab86afd0 h1:zsoK+TbXg/XOTXd+PXRrF6aGmpilcunfpcw/McPVBho= +github.com/ava-labs/awm-relayer v1.4.1-0.20241014222901-4b34ab86afd0/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c= diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index 88432ff8a..9a44b4bdf 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanche-cli/sdk/interchain" + "github.com/ava-labs/avalanchego/api/info" "github.com/ava-labs/avalanchego/ids" avagoconstants "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/logging" @@ -121,7 +122,7 @@ func PoaValidatorManagerGetPChainSubnetConversionWarpMessage( aggregatorLogger logging.Logger, aggregatorLogLevel logging.Level, aggregatorQuorumPercentage uint64, - aggregatorExtraPeerEndpoints []string, + aggregatorExtraPeerEndpoints []info.Peer, subnetID ids.ID, managerBlockchainID ids.ID, managerAddress common.Address, @@ -241,7 +242,7 @@ func SetupPoA( privateKey string, ownerAddress common.Address, convertSubnetValidators []*txs.ConvertSubnetValidator, - aggregatorExtraPeerEndpoints []string, + aggregatorExtraPeerEndpoints []info.Peer, ) error { if err := evm.SetupProposerVM( rpcURL, @@ -366,7 +367,7 @@ func PoaValidatorManagerGetSubnetValidatorRegistrationMessage( aggregatorLogger logging.Logger, aggregatorLogLevel logging.Level, aggregatorQuorumPercentage uint64, - aggregatorExtraPeerEndpoints []string, + aggregatorExtraPeerEndpoints []info.Peer, subnetID ids.ID, blockchainID ids.ID, managerAddress common.Address, @@ -446,7 +447,7 @@ func PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( aggregatorLogger logging.Logger, aggregatorLogLevel logging.Level, aggregatorQuorumPercentage uint64, - aggregatorExtraPeerEndpoints []string, + aggregatorExtraPeerEndpoints []info.Peer, subnetID ids.ID, validationID ids.ID, registered bool, @@ -514,7 +515,7 @@ func InitValidatorRegistration( balanceOwners warpMessage.PChainOwner, disableOwners warpMessage.PChainOwner, weight uint64, - aggregatorExtraPeerEndpoints []string, + aggregatorExtraPeerEndpoints []info.Peer, ) (*warp.Message, ids.ID, error) { subnetID, err := contract.GetSubnetID( app, @@ -572,7 +573,7 @@ func FinishValidatorRegistration( chainSpec contract.ChainSpec, privateKey string, validationID ids.ID, - aggregatorExtraPeerEndpoints []string, + aggregatorExtraPeerEndpoints []info.Peer, ) error { managerAddress := common.HexToAddress(ValidatorContractAddress) subnetID, err := contract.GetSubnetID( diff --git a/sdk/interchain/signature-aggregator.go b/sdk/interchain/signature-aggregator.go index 187374a4a..8bbb09a56 100644 --- a/sdk/interchain/signature-aggregator.go +++ b/sdk/interchain/signature-aggregator.go @@ -8,6 +8,7 @@ import ( "time" "github.com/ava-labs/avalanche-cli/pkg/models" + "github.com/ava-labs/avalanchego/api/info" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/message" "github.com/ava-labs/avalanchego/utils/constants" @@ -49,7 +50,7 @@ func createAppRequestNetwork( network models.Network, logLevel logging.Level, registerer prometheus.Registerer, - extraPeerEndpoints []string, + extraPeerEndpoints []info.Peer, ) (peers.AppRequestNetwork, error) { peerNetwork, err := peers.NewNetwork( logLevel, @@ -137,7 +138,7 @@ func NewSignatureAggregator( logLevel logging.Level, subnetID ids.ID, quorumPercentage uint64, - extraPeerEndpoints []string, + extraPeerEndpoints []info.Peer, ) (*SignatureAggregator, error) { registerer := prometheus.NewRegistry() peerNetwork, err := createAppRequestNetwork(network, logLevel, registerer, extraPeerEndpoints) From 480d4ba32b2bc58bd905763183b86ee895cf202c Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Mon, 14 Oct 2024 22:32:30 -0300 Subject: [PATCH 48/57] bump anr --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index aae239d7e..9d0d0d6ff 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54 + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241015011122-81bbf3a1dca2 github.com/ava-labs/avalanchego v1.12.0-initial-poc.5 github.com/ava-labs/awm-relayer v1.4.1-0.20241014222901-4b34ab86afd0 github.com/ava-labs/coreth v0.13.8 diff --git a/go.sum b/go.sum index 184e729a8..39b1e197d 100644 --- a/go.sum +++ b/go.sum @@ -83,12 +83,10 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54 h1:Hc06tSzeuQZTacGcrVLOnZjgKg1Cs655GT1Mmp9fCsU= -github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241014200823-e2da066cad54/go.mod h1:ASWB/CKJm8wVZUBp3DY0AV8jTBLCs01kzQz9GGwtzi8= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241015011122-81bbf3a1dca2 h1:tfqlJGby5nYWZJjGfDZaEOUQxpNJgVYNOAME04Qmgqc= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241015011122-81bbf3a1dca2/go.mod h1:ASWB/CKJm8wVZUBp3DY0AV8jTBLCs01kzQz9GGwtzi8= github.com/ava-labs/avalanchego v1.12.0-initial-poc.5 h1:gW4xAqZNvkA4gP8M9yDyd7YUzuwfQbbCR+hgd1ztOto= github.com/ava-labs/avalanchego v1.12.0-initial-poc.5/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE= -github.com/ava-labs/awm-relayer v1.4.1-0.20241014150833-56c34fc5124b h1:IFGojn8/tbbccw/LzPmcdaMiDK9Rpz2Qh+08woL4QZo= -github.com/ava-labs/awm-relayer v1.4.1-0.20241014150833-56c34fc5124b/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= github.com/ava-labs/awm-relayer v1.4.1-0.20241014222901-4b34ab86afd0 h1:zsoK+TbXg/XOTXd+PXRrF6aGmpilcunfpcw/McPVBho= github.com/ava-labs/awm-relayer v1.4.1-0.20241014222901-4b34ab86afd0/go.mod h1:K01Md6zPkOFRWeQyxmZ/t9HJfoNgUGqa1L8rOp35GXw= github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= From e97fd1fc1ffa1a4af8d4066822fdb6834e226ce9 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Wed, 16 Oct 2024 17:26:33 -0400 Subject: [PATCH 49/57] Fix merge --- cmd/nodecmd/local.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/cmd/nodecmd/local.go b/cmd/nodecmd/local.go index 0201dccf3..193ab7620 100644 --- a/cmd/nodecmd/local.go +++ b/cmd/nodecmd/local.go @@ -3,25 +3,11 @@ package nodecmd import ( - "fmt" - "os" - "path/filepath" - - "github.com/ava-labs/avalanche-cli/pkg/binutils" "github.com/ava-labs/avalanche-cli/pkg/cobrautils" - "github.com/ava-labs/avalanche-cli/pkg/constants" - "github.com/ava-labs/avalanche-cli/pkg/localnet" - "github.com/ava-labs/avalanche-cli/pkg/models" "github.com/ava-labs/avalanche-cli/pkg/networkoptions" "github.com/ava-labs/avalanche-cli/pkg/node" - "github.com/ava-labs/avalanche-cli/pkg/subnet" - "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" - "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" "github.com/spf13/cobra" ) From b5b28fd9c774cec4c1582b08f26d11bec8122168 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Wed, 16 Oct 2024 17:28:26 -0400 Subject: [PATCH 50/57] Fix merge --- pkg/node/local.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/node/local.go b/pkg/node/local.go index 62434da55..294e11869 100644 --- a/pkg/node/local.go +++ b/pkg/node/local.go @@ -100,8 +100,8 @@ func TrackSubnetWithLocalMachine(app *application.Avalanche, clusterName, blockc rpcEndpoints := set.Of(networkInfo.RPCEndpoints...) wsEndpoints := set.Of(networkInfo.WSEndpoints...) for _, publicEndpoint := range publicEndpoints { - rpcEndpoints.Add(getRPCEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) - wsEndpoints.Add(getWSEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) + rpcEndpoints.Add(GetRPCEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) + wsEndpoints.Add(GetWSEndpoint(publicEndpoint, networkInfo.BlockchainID.String())) } networkInfo.RPCEndpoints = rpcEndpoints.List() networkInfo.WSEndpoints = wsEndpoints.List() From c459f5c26085569792457511e03b69d9b2e788ff Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Wed, 16 Oct 2024 17:33:40 -0400 Subject: [PATCH 51/57] Fix merge --- cmd/blockchaincmd/deploy.go | 4 +-- cmd/nodecmd/destroy.go | 66 ------------------------------------- 2 files changed, 1 insertion(+), 69 deletions(-) diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 71fb9f648..2c69e45ba 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -7,17 +7,15 @@ import ( "encoding/json" "errors" "fmt" - "github.com/ava-labs/avalanchego/api/info" "os" "path/filepath" "strings" "time" - "github.com/ava-labs/avalanche-cli/pkg/node" "github.com/ava-labs/avalanchego/network/peer" - "github.com/ava-labs/avalanchego/api/info" "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" diff --git a/cmd/nodecmd/destroy.go b/cmd/nodecmd/destroy.go index c31b8ce1f..154db3a2f 100644 --- a/cmd/nodecmd/destroy.go +++ b/cmd/nodecmd/destroy.go @@ -5,7 +5,6 @@ package nodecmd import ( "errors" "fmt" - "github.com/ava-labs/avalanche-cli/pkg/models" "os" "strings" @@ -325,68 +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 := models.ClustersConfig{} - if app.ClustersConfigExists() { - var err error - clustersConfig, err = app.LoadClustersConfig() - 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 - } - clusterNodes := clustersConfig.Clusters[clusterName].Nodes - if len(clusterNodes) == 0 { - return nil, fmt.Errorf("no nodes found in cluster %s", clusterName) - } - return clusterNodes, 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 -} From 93aa9c3437aa18ff50ae3e52f952d5783ff016bc Mon Sep 17 00:00:00 2001 From: sukantoraymond Date: Wed, 16 Oct 2024 18:22:25 -0400 Subject: [PATCH 52/57] Update avalanche go ledger (#2234) * update avalanche go ledger * fixes * nit * update prompt * update tests * update avalanchego --------- Co-authored-by: Felipe Madero Co-authored-by: arturrez <56270896+arturrez@users.noreply.github.com> --- cmd/keycmd/transfer.go | 15 ++ cmd/nodecmd/create_devnet.go | 4 +- go.mod | 32 ++--- go.sum | 60 ++++---- internal/mocks/binary_checker.go | 2 +- internal/mocks/downloader.go | 2 +- internal/mocks/info.go | 24 ++-- internal/mocks/installer.go | 2 +- internal/mocks/network.go | 2 +- internal/mocks/pclient.go | 28 ++-- internal/mocks/plugin_binary_downloader.go | 2 +- internal/mocks/process_checker.go | 2 +- internal/mocks/prompter.go | 155 ++------------------- internal/mocks/publisher.go | 2 +- tests/e2e/testcases/key/suite.go | 7 +- tests/e2e/testcases/packageman/suite.go | 1 + tests/e2e/testcases/subnet/local/suite.go | 6 +- tests/e2e/testcases/upgrade/suite.go | 8 +- tests/e2e/utils/helpers.go | 23 +++ 19 files changed, 143 insertions(+), 234 deletions(-) diff --git a/cmd/keycmd/transfer.go b/cmd/keycmd/transfer.go index c99b1f447..f28c596a4 100644 --- a/cmd/keycmd/transfer.go +++ b/cmd/keycmd/transfer.go @@ -28,6 +28,7 @@ import ( avmtxs "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/txs" + avagofee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" @@ -598,6 +599,20 @@ func transferF(*cobra.Command, []string) error { return fmt.Errorf("error signing tx: %w", err) } + pContext := wallet.P().Builder().Context() + var pFeeCalculator avagofee.Calculator + if pContext.GasPrice != 0 { + pFeeCalculator = avagofee.NewDynamicCalculator(pContext.ComplexityWeights, pContext.GasPrice) + } else { + pFeeCalculator = avagofee.NewStaticCalculator(pContext.StaticFeeConfig) + } + txFee, err := pFeeCalculator.CalculateFee(unsignedTx) + if err != nil { + return err + } + ux.Logger.PrintToUser("") + ux.Logger.PrintToUser("Paid fee: %.9f", float64(txFee)/float64(units.Avax)) + ctx, cancel := utils.GetAPIContext() defer cancel() err = wallet.P().IssueTx( diff --git a/cmd/nodecmd/create_devnet.go b/cmd/nodecmd/create_devnet.go index 8b592f7aa..889d0eb40 100644 --- a/cmd/nodecmd/create_devnet.go +++ b/cmd/nodecmd/create_devnet.go @@ -22,6 +22,8 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/utils" "github.com/ava-labs/avalanche-cli/pkg/ux" "github.com/ava-labs/avalanchego/config" + avago_upgrade "github.com/ava-labs/avalanchego/upgrade" + avago_constants "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/logging" @@ -41,7 +43,7 @@ const ( func generateCustomCchainGenesis() ([]byte, error) { cChainGenesisMap := map[string]interface{}{} - cChainGenesisMap["config"] = coreth_params.AvalancheLocalChainConfig + cChainGenesisMap["config"] = coreth_params.GetChainConfig(avago_upgrade.GetConfig(avago_constants.LocalID), coreth_params.AvalancheLocalChainID) cChainGenesisMap["nonce"] = hexa0Str cChainGenesisMap["timestamp"] = hexa0Str cChainGenesisMap["extraData"] = "0x00" diff --git a/go.mod b/go.mod index bcaa9d4c2..667b4b4d2 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,20 @@ module github.com/ava-labs/avalanche-cli -go 1.22.7 +go 1.22.8 require ( github.com/ava-labs/apm v1.0.0 - github.com/ava-labs/avalanche-network-runner v1.8.3-0.20240815175406-50423422fb5b - github.com/ava-labs/avalanchego v1.11.11-0.20240815211142-ce78e7f1799f + github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a + github.com/ava-labs/avalanchego v1.11.13-0.20241016194412-e5ca05301169 github.com/ava-labs/awm-relayer v1.3.0 - github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180 + github.com/ava-labs/coreth v0.13.8 github.com/ava-labs/subnet-evm v0.6.9-0.20240815191823-9f3608326298 github.com/aws/aws-sdk-go-v2 v1.32.2 github.com/aws/aws-sdk-go-v2/config v1.27.26 github.com/aws/aws-sdk-go-v2/service/ec2 v1.182.0 github.com/chelnak/ysmrr v0.4.0 github.com/docker/docker v27.1.1+incompatible - github.com/ethereum/go-ethereum v1.13.8 + github.com/ethereum/go-ethereum v1.13.14 github.com/fatih/color v1.17.0 github.com/go-git/go-git/v5 v5.12.0 github.com/jedib0t/go-pretty/v6 v6.5.9 @@ -62,7 +62,7 @@ require ( github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/VictoriaMetrics/fastcache v1.12.1 // indirect github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect - github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 // indirect + github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 // indirect github.com/ava-labs/teleporter v1.0.0 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.26 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 // indirect @@ -82,7 +82,7 @@ require ( github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/cavaliergopher/grab/v3 v3.0.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/cloudflare/circl v1.3.7 // indirect github.com/cockroachdb/errors v1.9.1 // indirect @@ -105,7 +105,7 @@ require ( github.com/emirpasic/gods v1.18.1 // indirect github.com/ethereum/c-kzg-4844 v0.4.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect + github.com/fjl/memsize v0.0.2 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect @@ -116,7 +116,7 @@ require ( github.com/go-git/go-billy/v5 v5.5.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-ole/go-ole v1.2.6 // indirect + github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -134,13 +134,13 @@ require ( github.com/googleapis/gax-go/v2 v2.12.4 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/rpc v1.2.0 // indirect - github.com/gorilla/websocket v1.4.2 // indirect + github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect github.com/hashicorp/go-bexpr v0.1.10 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 // indirect + github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 // indirect github.com/holiman/bloomfilter/v2 v2.0.3 // indirect github.com/holiman/uint256 v1.2.4 // indirect github.com/huin/goupnp v1.3.0 // indirect @@ -175,7 +175,7 @@ require ( github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect - github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/cors v1.7.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect @@ -200,7 +200,7 @@ require ( github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect github.com/zondax/hid v0.9.2 // indirect - github.com/zondax/ledger-go v0.14.3 // indirect + github.com/zondax/ledger-go v1.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect go.opentelemetry.io/otel v1.24.0 // indirect @@ -218,9 +218,9 @@ require ( golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.24.0 // indirect gonum.org/v1/gonum v0.11.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect - google.golang.org/grpc v1.64.1 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect + google.golang.org/grpc v1.66.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect diff --git a/go.sum b/go.sum index d136a2b86..43e34cdc9 100644 --- a/go.sum +++ b/go.sum @@ -83,16 +83,16 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/ava-labs/apm v1.0.0 h1:6FwozH67hEkbWVsOXNZGexBy5KLpNeYucN9zcFUHv+Q= github.com/ava-labs/apm v1.0.0/go.mod h1:TJL7pTlZNvQatsQPsLUtDHApEwVZ/qS7iSNtRFU83mc= -github.com/ava-labs/avalanche-network-runner v1.8.3-0.20240815175406-50423422fb5b h1:9DEFDbJFdkMxzfjwUm1KbyzqYlhn8QDYrW9pYmFVNdA= -github.com/ava-labs/avalanche-network-runner v1.8.3-0.20240815175406-50423422fb5b/go.mod h1:X4ly6Ebq6vzsj9q9G9W00YftOrS7ZT2jLi9cxLqT4eQ= -github.com/ava-labs/avalanchego v1.11.11-0.20240815211142-ce78e7f1799f h1:fLWva3zOGwhZAnLq+nhiTs1Q24dL1nPvF4qVZZ6IGFg= -github.com/ava-labs/avalanchego v1.11.11-0.20240815211142-ce78e7f1799f/go.mod h1:UkyrRDXK2E15Lq2abyae2Pt+JsWvgsg1pe0/AtoMyAM= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a h1:xd2RUTW9w34+V6yI7zWfByHZ8y5CeXhvHK+nAJ9FCbI= +github.com/ava-labs/avalanche-network-runner v1.8.4-0.20241003175856-6b1bcdf33e7a/go.mod h1:l4QzFnujbyyyeq6oBQ4F6sw9TrTQCjD2V4vUd7ZBCCo= +github.com/ava-labs/avalanchego v1.11.13-0.20241016194412-e5ca05301169 h1:v09QsEUbm5fjPgDWEJZzSFU7T4b0SPiKyZq5DvR8rSU= +github.com/ava-labs/avalanchego v1.11.13-0.20241016194412-e5ca05301169/go.mod h1:YlinMYWE4yXu4bA5Vdzn1WcQ+z5qjrpxeBYwWAPdrvA= github.com/ava-labs/awm-relayer v1.3.0 h1:aI90Daoq7bs9SnfZpyjXajj7YLcdZoFgEkyCd52fOHE= github.com/ava-labs/awm-relayer v1.3.0/go.mod h1:UI1Tm0jfFIpO1S2hpE5WGzJCDpLHLldhsE1bWn2FjEE= -github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180 h1:6aIHp7wbyGVYdhHVQUbG7BEcbCMEQ5SYopPPJyipyvk= -github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180/go.mod h1:/wNBVq7J7wlC2Kbov7kk6LV5xZvau7VF9zwTVOeyAjY= -github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c= -github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g= +github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= +github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= +github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= +github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/ava-labs/subnet-evm v0.6.9-0.20240815191823-9f3608326298 h1:g7JdXUEZ5Hk3sKhJPoZattE4obRaF7qapHREnB4O+Rg= github.com/ava-labs/subnet-evm v0.6.9-0.20240815191823-9f3608326298/go.mod h1:QfIzh7YxKj97jbendOHQbaAxM7SMj5MWdV13o1VLn70= github.com/ava-labs/teleporter v1.0.0 h1:io209qZh3SDpwLre0oStMzOFRcPvOrmMQuLq5OFvzJo= @@ -180,8 +180,9 @@ github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chelnak/ysmrr v0.4.0 h1:WMvLGPlBK0kb6wHf5z9FfNvpM6sB9765jy2ajYc1Sfs= github.com/chelnak/ysmrr v0.4.0/go.mod h1:8vCna4PJsPCb6eevtoG7Tljzfx3twpsO203Qj2gafLM= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -292,8 +293,8 @@ github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHj github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY= github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.10.3/go.mod h1:99onQmSd1GRGOziyGldI41YQb7EESX3Q4H41IfJgIQQ= -github.com/ethereum/go-ethereum v1.13.8 h1:1od+thJel3tM52ZUNQwvpYOeRHlbkVFZ5S8fhi0Lgsg= -github.com/ethereum/go-ethereum v1.13.8/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= +github.com/ethereum/go-ethereum v1.13.14 h1:EwiY3FZP94derMCIam1iW4HFVrSgIcpsu0HwTQtm6CQ= +github.com/ethereum/go-ethereum v1.13.14/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= @@ -301,8 +302,9 @@ github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLg github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= +github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= +github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= @@ -353,8 +355,9 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= -github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= @@ -386,8 +389,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= -github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4= +github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -471,8 +474,9 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk= github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/graph-gophers/graphql-go v0.0.0-20201113091052-beb923fada29/go.mod h1:9CQHMSxwO4MprSdzoIEobiHpoLtHm77vfxsvsIN5Vuc= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= @@ -487,8 +491,8 @@ github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuW github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= -github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= +github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= +github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.1.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= @@ -749,8 +753,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= @@ -884,8 +888,8 @@ github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPR github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U= github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= -github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfUCw= -github.com/zondax/ledger-go v0.14.3/go.mod h1:IKKaoxupuB43g4NxeQmbLXv7T9AlQyie1UpHb342ycI= +github.com/zondax/ledger-go v1.0.0 h1:BvNoksIyRqyQTW78rIZP9A44WwAminKiomQa7jXp9EI= +github.com/zondax/ledger-go v1.0.0/go.mod h1:HpgkgFh3Jkwi9iYLDATdyRxc8CxqxcywsFj6QerWzvo= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -1212,10 +1216,10 @@ google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvx google.golang.org/genproto v0.0.0-20200108215221-bd8f9a0ef82f/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= -google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw= -google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 h1:+rdxYoE3E5htTEWIe15GlN6IfvbURM//Jt0mmkmm6ZU= +google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117/go.mod h1:OimBR/bc1wPO9iV4NC2bpyjy3VnAwZh5EBPQdtaE5oo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= @@ -1226,8 +1230,8 @@ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= -google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= +google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/internal/mocks/binary_checker.go b/internal/mocks/binary_checker.go index 885860e52..ec21488b8 100644 --- a/internal/mocks/binary_checker.go +++ b/internal/mocks/binary_checker.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks diff --git a/internal/mocks/downloader.go b/internal/mocks/downloader.go index c119d797a..1a1f45c9a 100644 --- a/internal/mocks/downloader.go +++ b/internal/mocks/downloader.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks diff --git a/internal/mocks/info.go b/internal/mocks/info.go index da4f831cb..efd1b3bdb 100644 --- a/internal/mocks/info.go +++ b/internal/mocks/info.go @@ -432,14 +432,14 @@ func (_m *InfoClient) Upgrades(_a0 context.Context, _a1 ...rpc.Option) (*upgrade return r0, r1 } -// Uptime provides a mock function with given fields: _a0, _a1, _a2 -func (_m *InfoClient) Uptime(_a0 context.Context, _a1 ids.ID, _a2 ...rpc.Option) (*info.UptimeResponse, error) { - _va := make([]interface{}, len(_a2)) - for _i := range _a2 { - _va[_i] = _a2[_i] +// Uptime provides a mock function with given fields: _a0, _a1 +func (_m *InfoClient) Uptime(_a0 context.Context, _a1 ...rpc.Option) (*info.UptimeResponse, error) { + _va := make([]interface{}, len(_a1)) + for _i := range _a1 { + _va[_i] = _a1[_i] } var _ca []interface{} - _ca = append(_ca, _a0, _a1) + _ca = append(_ca, _a0) _ca = append(_ca, _va...) ret := _m.Called(_ca...) @@ -449,19 +449,19 @@ func (_m *InfoClient) Uptime(_a0 context.Context, _a1 ids.ID, _a2 ...rpc.Option) var r0 *info.UptimeResponse var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ids.ID, ...rpc.Option) (*info.UptimeResponse, error)); ok { - return rf(_a0, _a1, _a2...) + if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) (*info.UptimeResponse, error)); ok { + return rf(_a0, _a1...) } - if rf, ok := ret.Get(0).(func(context.Context, ids.ID, ...rpc.Option) *info.UptimeResponse); ok { - r0 = rf(_a0, _a1, _a2...) + if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) *info.UptimeResponse); ok { + r0 = rf(_a0, _a1...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*info.UptimeResponse) } } - if rf, ok := ret.Get(1).(func(context.Context, ids.ID, ...rpc.Option) error); ok { - r1 = rf(_a0, _a1, _a2...) + if rf, ok := ret.Get(1).(func(context.Context, ...rpc.Option) error); ok { + r1 = rf(_a0, _a1...) } else { r1 = ret.Error(1) } diff --git a/internal/mocks/installer.go b/internal/mocks/installer.go index 323ff8645..5fa59ad64 100644 --- a/internal/mocks/installer.go +++ b/internal/mocks/installer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks diff --git a/internal/mocks/network.go b/internal/mocks/network.go index 0a09ba3ed..56ce44811 100644 --- a/internal/mocks/network.go +++ b/internal/mocks/network.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks diff --git a/internal/mocks/pclient.go b/internal/mocks/pclient.go index 281484347..070de1d96 100644 --- a/internal/mocks/pclient.go +++ b/internal/mocks/pclient.go @@ -7,7 +7,7 @@ import ( api "github.com/ava-labs/avalanchego/api" - fee "github.com/ava-labs/avalanchego/vms/components/fee" + gas "github.com/ava-labs/avalanchego/vms/components/gas" ids "github.com/ava-labs/avalanchego/ids" @@ -386,7 +386,7 @@ func (_m *PClient) GetCurrentValidators(ctx context.Context, subnetID ids.ID, no } // GetFeeConfig provides a mock function with given fields: ctx, options -func (_m *PClient) GetFeeConfig(ctx context.Context, options ...rpc.Option) (*fee.Config, error) { +func (_m *PClient) GetFeeConfig(ctx context.Context, options ...rpc.Option) (*gas.Config, error) { _va := make([]interface{}, len(options)) for _i := range options { _va[_i] = options[_i] @@ -400,16 +400,16 @@ func (_m *PClient) GetFeeConfig(ctx context.Context, options ...rpc.Option) (*fe panic("no return value specified for GetFeeConfig") } - var r0 *fee.Config + var r0 *gas.Config var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) (*fee.Config, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) (*gas.Config, error)); ok { return rf(ctx, options...) } - if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) *fee.Config); ok { + if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) *gas.Config); ok { r0 = rf(ctx, options...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*fee.Config) + r0 = ret.Get(0).(*gas.Config) } } @@ -423,7 +423,7 @@ func (_m *PClient) GetFeeConfig(ctx context.Context, options ...rpc.Option) (*fe } // GetFeeState provides a mock function with given fields: ctx, options -func (_m *PClient) GetFeeState(ctx context.Context, options ...rpc.Option) (fee.State, fee.GasPrice, time.Time, error) { +func (_m *PClient) GetFeeState(ctx context.Context, options ...rpc.Option) (gas.State, gas.Price, time.Time, error) { _va := make([]interface{}, len(options)) for _i := range options { _va[_i] = options[_i] @@ -437,23 +437,23 @@ func (_m *PClient) GetFeeState(ctx context.Context, options ...rpc.Option) (fee. panic("no return value specified for GetFeeState") } - var r0 fee.State - var r1 fee.GasPrice + var r0 gas.State + var r1 gas.Price var r2 time.Time var r3 error - if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) (fee.State, fee.GasPrice, time.Time, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) (gas.State, gas.Price, time.Time, error)); ok { return rf(ctx, options...) } - if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) fee.State); ok { + if rf, ok := ret.Get(0).(func(context.Context, ...rpc.Option) gas.State); ok { r0 = rf(ctx, options...) } else { - r0 = ret.Get(0).(fee.State) + r0 = ret.Get(0).(gas.State) } - if rf, ok := ret.Get(1).(func(context.Context, ...rpc.Option) fee.GasPrice); ok { + if rf, ok := ret.Get(1).(func(context.Context, ...rpc.Option) gas.Price); ok { r1 = rf(ctx, options...) } else { - r1 = ret.Get(1).(fee.GasPrice) + r1 = ret.Get(1).(gas.Price) } if rf, ok := ret.Get(2).(func(context.Context, ...rpc.Option) time.Time); ok { diff --git a/internal/mocks/plugin_binary_downloader.go b/internal/mocks/plugin_binary_downloader.go index 465ebf69e..1972dbd49 100644 --- a/internal/mocks/plugin_binary_downloader.go +++ b/internal/mocks/plugin_binary_downloader.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks diff --git a/internal/mocks/process_checker.go b/internal/mocks/process_checker.go index 39602919b..2398cd337 100644 --- a/internal/mocks/process_checker.go +++ b/internal/mocks/process_checker.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks diff --git a/internal/mocks/prompter.go b/internal/mocks/prompter.go index 0d38e7b05..ce4923a2d 100644 --- a/internal/mocks/prompter.go +++ b/internal/mocks/prompter.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.26.1. DO NOT EDIT. package mocks @@ -28,10 +28,6 @@ type Prompter struct { func (_m *Prompter) CaptureAddress(promptStr string) (common.Address, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureAddress") - } - var r0 common.Address var r1 error if rf, ok := ret.Get(0).(func(string) (common.Address, error)); ok { @@ -58,10 +54,6 @@ func (_m *Prompter) CaptureAddress(promptStr string) (common.Address, error) { func (_m *Prompter) CaptureAddresses(promptStr string) ([]common.Address, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureList") - } - var r0 []common.Address var r1 error if rf, ok := ret.Get(0).(func(string) ([]common.Address, error)); ok { @@ -70,7 +62,9 @@ func (_m *Prompter) CaptureAddresses(promptStr string) ([]common.Address, error) if rf, ok := ret.Get(0).(func(string) []common.Address); ok { r0 = rf(promptStr) } else { - r0 = ret.Get(0).([]common.Address) + if ret.Get(0) != nil { + r0 = ret.Get(0).([]common.Address) + } } if rf, ok := ret.Get(1).(func(string) error); ok { @@ -86,10 +80,6 @@ func (_m *Prompter) CaptureAddresses(promptStr string) ([]common.Address, error) func (_m *Prompter) CaptureDate(promptStr string) (time.Time, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureDate") - } - var r0 time.Time var r1 error if rf, ok := ret.Get(0).(func(string) (time.Time, error)); ok { @@ -114,10 +104,6 @@ func (_m *Prompter) CaptureDate(promptStr string) (time.Time, error) { func (_m *Prompter) CaptureEmail(promptStr string) (string, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureEmail") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { @@ -142,10 +128,6 @@ func (_m *Prompter) CaptureEmail(promptStr string) (string, error) { func (_m *Prompter) CaptureExistingFilepath(promptStr string) (string, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureExistingFilepath") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { @@ -170,10 +152,6 @@ func (_m *Prompter) CaptureExistingFilepath(promptStr string) (string, error) { func (_m *Prompter) CaptureFloat(promptStr string, validator func(float64) error) (float64, error) { ret := _m.Called(promptStr, validator) - if len(ret) == 0 { - panic("no return value specified for CaptureFloat") - } - var r0 float64 var r1 error if rf, ok := ret.Get(0).(func(string, func(float64) error) (float64, error)); ok { @@ -198,10 +176,6 @@ func (_m *Prompter) CaptureFloat(promptStr string, validator func(float64) error func (_m *Prompter) CaptureFujiDuration(promptStr string) (time.Duration, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureFujiDuration") - } - var r0 time.Duration var r1 error if rf, ok := ret.Get(0).(func(string) (time.Duration, error)); ok { @@ -226,10 +200,6 @@ func (_m *Prompter) CaptureFujiDuration(promptStr string) (time.Duration, error) func (_m *Prompter) CaptureFutureDate(promptStr string, minDate time.Time) (time.Time, error) { ret := _m.Called(promptStr, minDate) - if len(ret) == 0 { - panic("no return value specified for CaptureFutureDate") - } - var r0 time.Time var r1 error if rf, ok := ret.Get(0).(func(string, time.Time) (time.Time, error)); ok { @@ -254,10 +224,6 @@ func (_m *Prompter) CaptureFutureDate(promptStr string, minDate time.Time) (time func (_m *Prompter) CaptureGitURL(promptStr string) (*url.URL, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureGitURL") - } - var r0 *url.URL var r1 error if rf, ok := ret.Get(0).(func(string) (*url.URL, error)); ok { @@ -284,10 +250,6 @@ func (_m *Prompter) CaptureGitURL(promptStr string) (*url.URL, error) { func (_m *Prompter) CaptureID(promptStr string) (ids.ID, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureID") - } - var r0 ids.ID var r1 error if rf, ok := ret.Get(0).(func(string) (ids.ID, error)); ok { @@ -314,10 +276,6 @@ func (_m *Prompter) CaptureID(promptStr string) (ids.ID, error) { func (_m *Prompter) CaptureIndex(promptStr string, options []interface{}) (int, error) { ret := _m.Called(promptStr, options) - if len(ret) == 0 { - panic("no return value specified for CaptureIndex") - } - var r0 int var r1 error if rf, ok := ret.Get(0).(func(string, []interface{}) (int, error)); ok { @@ -342,10 +300,6 @@ func (_m *Prompter) CaptureIndex(promptStr string, options []interface{}) (int, func (_m *Prompter) CaptureInt(promptStr string) (int, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureInt") - } - var r0 int var r1 error if rf, ok := ret.Get(0).(func(string) (int, error)); ok { @@ -370,10 +324,6 @@ func (_m *Prompter) CaptureInt(promptStr string) (int, error) { func (_m *Prompter) CaptureList(promptStr string, options []string) (string, error) { ret := _m.Called(promptStr, options) - if len(ret) == 0 { - panic("no return value specified for CaptureList") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, []string) (string, error)); ok { @@ -398,10 +348,6 @@ func (_m *Prompter) CaptureList(promptStr string, options []string) (string, err func (_m *Prompter) CaptureListWithSize(promptStr string, options []string, size int) (string, error) { ret := _m.Called(promptStr, options, size) - if len(ret) == 0 { - panic("no return value specified for CaptureListWithSize") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, []string, int) (string, error)); ok { @@ -426,10 +372,6 @@ func (_m *Prompter) CaptureListWithSize(promptStr string, options []string, size func (_m *Prompter) CaptureMainnetDuration(promptStr string) (time.Duration, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureMainnetDuration") - } - var r0 time.Duration var r1 error if rf, ok := ret.Get(0).(func(string) (time.Duration, error)); ok { @@ -454,10 +396,6 @@ func (_m *Prompter) CaptureMainnetDuration(promptStr string) (time.Duration, err func (_m *Prompter) CaptureNewFilepath(promptStr string) (string, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureNewFilepath") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { @@ -482,10 +420,6 @@ func (_m *Prompter) CaptureNewFilepath(promptStr string) (string, error) { func (_m *Prompter) CaptureNoYes(promptStr string) (bool, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureNoYes") - } - var r0 bool var r1 error if rf, ok := ret.Get(0).(func(string) (bool, error)); ok { @@ -510,10 +444,6 @@ func (_m *Prompter) CaptureNoYes(promptStr string) (bool, error) { func (_m *Prompter) CaptureNodeID(promptStr string) (ids.NodeID, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureNodeID") - } - var r0 ids.NodeID var r1 error if rf, ok := ret.Get(0).(func(string) (ids.NodeID, error)); ok { @@ -540,10 +470,6 @@ func (_m *Prompter) CaptureNodeID(promptStr string) (ids.NodeID, error) { func (_m *Prompter) CapturePChainAddress(promptStr string, network models.Network) (string, error) { ret := _m.Called(promptStr, network) - if len(ret) == 0 { - panic("no return value specified for CapturePChainAddress") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, models.Network) (string, error)); ok { @@ -568,10 +494,6 @@ func (_m *Prompter) CapturePChainAddress(promptStr string, network models.Networ func (_m *Prompter) CapturePositiveBigInt(promptStr string) (*big.Int, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CapturePositiveBigInt") - } - var r0 *big.Int var r1 error if rf, ok := ret.Get(0).(func(string) (*big.Int, error)); ok { @@ -598,10 +520,6 @@ func (_m *Prompter) CapturePositiveBigInt(promptStr string) (*big.Int, error) { func (_m *Prompter) CapturePositiveInt(promptStr string, comparators []prompts.Comparator) (int, error) { ret := _m.Called(promptStr, comparators) - if len(ret) == 0 { - panic("no return value specified for CapturePositiveInt") - } - var r0 int var r1 error if rf, ok := ret.Get(0).(func(string, []prompts.Comparator) (int, error)); ok { @@ -626,10 +544,6 @@ func (_m *Prompter) CapturePositiveInt(promptStr string, comparators []prompts.C func (_m *Prompter) CaptureRepoBranch(promptStr string, repo string) (string, error) { ret := _m.Called(promptStr, repo) - if len(ret) == 0 { - panic("no return value specified for CaptureRepoBranch") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, string) (string, error)); ok { @@ -654,10 +568,6 @@ func (_m *Prompter) CaptureRepoBranch(promptStr string, repo string) (string, er func (_m *Prompter) CaptureRepoFile(promptStr string, repo string, branch string) (string, error) { ret := _m.Called(promptStr, repo, branch) - if len(ret) == 0 { - panic("no return value specified for CaptureRepoFile") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, string, string) (string, error)); ok { @@ -682,10 +592,6 @@ func (_m *Prompter) CaptureRepoFile(promptStr string, repo string, branch string func (_m *Prompter) CaptureString(promptStr string) (string, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureString") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { @@ -710,10 +616,6 @@ func (_m *Prompter) CaptureString(promptStr string) (string, error) { func (_m *Prompter) CaptureStringAllowEmpty(promptStr string) (string, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureStringAllowEmpty") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { @@ -738,10 +640,6 @@ func (_m *Prompter) CaptureStringAllowEmpty(promptStr string) (string, error) { func (_m *Prompter) CaptureURL(promptStr string, validateConnection bool) (string, error) { ret := _m.Called(promptStr, validateConnection) - if len(ret) == 0 { - panic("no return value specified for CaptureURL") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, bool) (string, error)); ok { @@ -766,10 +664,6 @@ func (_m *Prompter) CaptureURL(promptStr string, validateConnection bool) (strin func (_m *Prompter) CaptureUint32(promptStr string) (uint32, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureUint32") - } - var r0 uint32 var r1 error if rf, ok := ret.Get(0).(func(string) (uint32, error)); ok { @@ -794,10 +688,6 @@ func (_m *Prompter) CaptureUint32(promptStr string) (uint32, error) { func (_m *Prompter) CaptureUint64(promptStr string) (uint64, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureUint64") - } - var r0 uint64 var r1 error if rf, ok := ret.Get(0).(func(string) (uint64, error)); ok { @@ -822,10 +712,6 @@ func (_m *Prompter) CaptureUint64(promptStr string) (uint64, error) { func (_m *Prompter) CaptureUint64Compare(promptStr string, comparators []prompts.Comparator) (uint64, error) { ret := _m.Called(promptStr, comparators) - if len(ret) == 0 { - panic("no return value specified for CaptureUint64Compare") - } - var r0 uint64 var r1 error if rf, ok := ret.Get(0).(func(string, []prompts.Comparator) (uint64, error)); ok { @@ -850,10 +736,6 @@ func (_m *Prompter) CaptureUint64Compare(promptStr string, comparators []prompts func (_m *Prompter) CaptureValidatedString(promptStr string, validator func(string) error) (string, error) { ret := _m.Called(promptStr, validator) - if len(ret) == 0 { - panic("no return value specified for CaptureValidatedString") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, func(string) error) (string, error)); ok { @@ -878,10 +760,6 @@ func (_m *Prompter) CaptureValidatedString(promptStr string, validator func(stri func (_m *Prompter) CaptureVersion(promptStr string) (string, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureVersion") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string) (string, error)); ok { @@ -906,10 +784,6 @@ func (_m *Prompter) CaptureVersion(promptStr string) (string, error) { func (_m *Prompter) CaptureWeight(promptStr string) (uint64, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureWeight") - } - var r0 uint64 var r1 error if rf, ok := ret.Get(0).(func(string) (uint64, error)); ok { @@ -934,10 +808,6 @@ func (_m *Prompter) CaptureWeight(promptStr string) (uint64, error) { func (_m *Prompter) CaptureXChainAddress(promptStr string, network models.Network) (string, error) { ret := _m.Called(promptStr, network) - if len(ret) == 0 { - panic("no return value specified for CaptureXChainAddress") - } - var r0 string var r1 error if rf, ok := ret.Get(0).(func(string, models.Network) (string, error)); ok { @@ -962,10 +832,6 @@ func (_m *Prompter) CaptureXChainAddress(promptStr string, network models.Networ func (_m *Prompter) CaptureYesNo(promptStr string) (bool, error) { ret := _m.Called(promptStr) - if len(ret) == 0 { - panic("no return value specified for CaptureYesNo") - } - var r0 bool var r1 error if rf, ok := ret.Get(0).(func(string) (bool, error)); ok { @@ -990,10 +856,6 @@ func (_m *Prompter) CaptureYesNo(promptStr string) (bool, error) { func (_m *Prompter) ChooseKeyOrLedger(goal string) (bool, error) { ret := _m.Called(goal) - if len(ret) == 0 { - panic("no return value specified for ChooseKeyOrLedger") - } - var r0 bool var r1 error if rf, ok := ret.Get(0).(func(string) (bool, error)); ok { @@ -1014,12 +876,13 @@ func (_m *Prompter) ChooseKeyOrLedger(goal string) (bool, error) { return r0, r1 } -// NewPrompter creates a new instance of Prompter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewPrompter(t interface { +type mockConstructorTestingTNewPrompter interface { mock.TestingT Cleanup(func()) -}) *Prompter { +} + +// NewPrompter creates a new instance of Prompter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewPrompter(t mockConstructorTestingTNewPrompter) *Prompter { mock := &Prompter{} mock.Mock.Test(t) diff --git a/internal/mocks/publisher.go b/internal/mocks/publisher.go index 743dbe573..45d6028a6 100644 --- a/internal/mocks/publisher.go +++ b/internal/mocks/publisher.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.43.2. DO NOT EDIT. package mocks diff --git a/tests/e2e/testcases/key/suite.go b/tests/e2e/testcases/key/suite.go index a13cd4c95..4b954336f 100644 --- a/tests/e2e/testcases/key/suite.go +++ b/tests/e2e/testcases/key/suite.go @@ -11,7 +11,6 @@ import ( "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanche-cli/tests/e2e/commands" "github.com/ava-labs/avalanche-cli/tests/e2e/utils" - "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/utils/units" ginkgo "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" @@ -269,7 +268,6 @@ var _ = ginkgo.Describe("[Key]", func() { amount := 0.2 amountStr := fmt.Sprintf("%.2f", amount) - feeNAvax := genesis.LocalParams.TxFeeConfig.StaticFeeConfig.TxFee * 1 amountNAvax := uint64(amount * float64(units.Avax)) // send/receive without recovery @@ -287,13 +285,16 @@ var _ = ginkgo.Describe("[Key]", func() { } gomega.Expect(err).Should(gomega.BeNil()) + feeNAvax, err := utils.GetKeyTransferFee(output) + gomega.Expect(err).Should(gomega.BeNil()) + output, err = commands.ListKeys("local", true, true) gomega.Expect(err).Should(gomega.BeNil()) _, keyBalance2, err := utils.ParseAddrBalanceFromKeyListOutput(output, keyName) gomega.Expect(err).Should(gomega.BeNil()) _, ewoqKeyBalance2, err := utils.ParseAddrBalanceFromKeyListOutput(output, ewoqKeyName) gomega.Expect(err).Should(gomega.BeNil()) - gomega.Expect(ewoqKeyBalance1 - ewoqKeyBalance2).Should(gomega.Equal(feeNAvax + amountNAvax)) + gomega.Expect(feeNAvax + amountNAvax).Should(gomega.Equal(ewoqKeyBalance1 - ewoqKeyBalance2)) gomega.Expect(keyBalance2 - keyBalance1).Should(gomega.Equal(amountNAvax)) output, err = commands.ListKeys("local", true, true) diff --git a/tests/e2e/testcases/packageman/suite.go b/tests/e2e/testcases/packageman/suite.go index 7812a12c9..cdb302911 100644 --- a/tests/e2e/testcases/packageman/suite.go +++ b/tests/e2e/testcases/packageman/suite.go @@ -113,6 +113,7 @@ var _ = ginkgo.Describe("[Package Management]", ginkgo.Ordered, func() { }) ginkgo.It("can deploy with multiple avalanchego versions", func() { + ginkgo.Skip("skipped until two consecutive avago version with dynamic fees are available") // check avago install precondition gomega.Expect(utils.CheckAvalancheGoExists(binaryToVersion[utils.MultiAvago1Key])).Should(gomega.BeFalse()) gomega.Expect(utils.CheckAvalancheGoExists(binaryToVersion[utils.MultiAvago2Key])).Should(gomega.BeFalse()) diff --git a/tests/e2e/testcases/subnet/local/suite.go b/tests/e2e/testcases/subnet/local/suite.go index 235629127..6c4e445d7 100644 --- a/tests/e2e/testcases/subnet/local/suite.go +++ b/tests/e2e/testcases/subnet/local/suite.go @@ -326,7 +326,7 @@ var _ = ginkgo.Describe("[Subnet Compatibility]", func() { }) ginkgo.It("can deploy a subnet-evm with old version", func() { - subnetEVMVersion := "v0.6.6" + subnetEVMVersion := "v0.6.9" commands.CreateSubnetEvmConfigWithVersion(subnetName, utils.SubnetEvmGenesisPath, subnetEVMVersion) deployOutput := commands.DeploySubnetLocally(subnetName) @@ -349,8 +349,8 @@ var _ = ginkgo.Describe("[Subnet Compatibility]", func() { ginkgo.It("can't deploy conflicting vm versions", func() { // TODO: These shouldn't be hardcoded either - subnetEVMVersion1 := "v0.6.6" - subnetEVMVersion2 := "v0.6.2" + subnetEVMVersion1 := "v0.6.9" + subnetEVMVersion2 := "v0.6.8" commands.CreateSubnetEvmConfigWithVersion(subnetName, utils.SubnetEvmGenesisPath, subnetEVMVersion1) commands.CreateSubnetEvmConfigWithVersion(secondSubnetName, utils.SubnetEvmGenesis2Path, subnetEVMVersion2) diff --git a/tests/e2e/testcases/upgrade/suite.go b/tests/e2e/testcases/upgrade/suite.go index 52bebc2a4..fa6fe0f2a 100644 --- a/tests/e2e/testcases/upgrade/suite.go +++ b/tests/e2e/testcases/upgrade/suite.go @@ -31,11 +31,11 @@ const ( subnetName = "e2eSubnetTest" secondSubnetName = "e2eSecondSubnetTest" - subnetEVMVersion1 = "v0.6.5" - subnetEVMVersion2 = "v0.6.6" + subnetEVMVersion1 = "v0.6.9" + subnetEVMVersion2 = "v0.6.10" - avagoRPC1Version = "v1.11.4" - avagoRPC2Version = "v1.11.5" + avagoRPC1Version = "v1.11.11" + avagoRPC2Version = "v1.11.11" controlKeys = "P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p" keyName = "ewoq" diff --git a/tests/e2e/utils/helpers.go b/tests/e2e/utils/helpers.go index f08c6786a..9f3ac0126 100644 --- a/tests/e2e/utils/helpers.go +++ b/tests/e2e/utils/helpers.go @@ -20,6 +20,9 @@ import ( "strings" "time" + "github.com/ava-labs/avalanchego/genesis" + "github.com/ava-labs/avalanchego/utils/units" + "github.com/ava-labs/avalanche-cli/pkg/binutils" "github.com/ava-labs/avalanche-cli/pkg/constants" "github.com/ava-labs/avalanche-cli/pkg/key" @@ -1043,3 +1046,23 @@ func ExecCommand(cmdName string, args []string, showStdout bool, errorIsExpected return stdout + string(stderr) } + +func GetKeyTransferFee(output string) (uint64, error) { + feeNAvax := genesis.LocalParams.TxFeeConfig.StaticFeeConfig.TxFee * 1 + for _, line := range strings.Split(output, "\n") { + if strings.Contains(line, "Paid fee") { + lineFields := strings.Fields(line) + if len(lineFields) < 3 { + return 0, fmt.Errorf("incorrect format for fee output of key transfer: %s", line) + } + feeAvaxStr := lineFields[2] + feeAvax, err := strconv.ParseFloat(feeAvaxStr, 64) + if err != nil { + return 0, err + } + feeAvax *= float64(units.Avax) + feeNAvax = uint64(feeAvax) + } + } + return feeNAvax, nil +} From 99ab7d9215df3469250c38bdf913d0e1b11ee9c0 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Wed, 16 Oct 2024 18:46:59 -0400 Subject: [PATCH 53/57] lint --- pkg/validatormanager/validatormanager.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/validatormanager/validatormanager.go b/pkg/validatormanager/validatormanager.go index 9a44b4bdf..f6ade8048 100644 --- a/pkg/validatormanager/validatormanager.go +++ b/pkg/validatormanager/validatormanager.go @@ -442,7 +442,7 @@ func GetRegisteredValidator( return validatorID, nil } -func PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( +func PoaValidatorManagerGetPChainSubnetValidatorRegistrationWarpMessage( network models.Network, aggregatorLogger logging.Logger, aggregatorLogLevel logging.Level, @@ -584,7 +584,7 @@ func FinishValidatorRegistration( if err != nil { return err } - signedMessage, err := PoaValidatorManagerGetPChainSubnetValidatorRegistrationnWarpMessage( + signedMessage, err := PoaValidatorManagerGetPChainSubnetValidatorRegistrationWarpMessage( network, app.Log, logging.Info, From 6850ff150576fa0f2a0f16a3cc652392fa5537f0 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Wed, 16 Oct 2024 19:33:40 -0400 Subject: [PATCH 54/57] fix merge --- cmd/blockchaincmd/deploy.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index 2c69e45ba..fb059efce 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -786,9 +786,12 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { } if !convertOnly { - clusterName, err := node.GetClusterNameFromList(app) - if err != nil { - return err + clusterName := network.ClusterName + if clusterName == "" { + clusterName, err = node.GetClusterNameFromList(app) + if err != nil { + return err + } } if !useLocalMachine { From b1d79428550199a10296586ea46cfa3d6c19871f Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 17 Oct 2024 07:03:16 -0300 Subject: [PATCH 55/57] nits --- cmd/blockchaincmd/deploy.go | 70 +++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/cmd/blockchaincmd/deploy.go b/cmd/blockchaincmd/deploy.go index b637420a2..64b672165 100644 --- a/cmd/blockchaincmd/deploy.go +++ b/cmd/blockchaincmd/deploy.go @@ -477,45 +477,47 @@ func deployBlockchain(cmd *cobra.Command, args []string) error { } if sidecar.Sovereign { - if !useLocalMachine { - 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.") + if !convertOnly { + if !useLocalMachine { + 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.") - useLocalMachine, err = app.Prompt.CaptureYesNo("Do you want to use your local machine as a bootstrap validator?") - if err != nil { - return err - } - } - if useLocalMachine { - // stop any local avalanche go process running before we start local node - _ = 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 - 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") - ux.Logger.PrintToUser("Please provide the full path to Avalanche Go binary in the build directory (e.g, xxx/build/avalanchego)") - avagoBinaryPath, err = app.Prompt.CaptureString("Path to Avalanche Go build") + useLocalMachine, err = app.Prompt.CaptureYesNo("Do you want to use your local machine as a bootstrap validator?") if err != nil { return err } } - network = models.NewNetworkFromCluster(network, clusterName) - // anrSettings, avagoVersionSettings, globalNetworkFlags are empty - if err = node.StartLocalNode(app, clusterName, useEtnaDevnet, avagoBinaryPath, anrSettings, avagoVersionSettings, globalNetworkFlags, nil); err != nil { - return err + if useLocalMachine { + // stop any local avalanche go process running before we start local node + _ = 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 + 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") + ux.Logger.PrintToUser("Please provide the full path to Avalanche Go binary in the build directory (e.g, xxx/build/avalanchego)") + avagoBinaryPath, err = app.Prompt.CaptureString("Path to Avalanche Go build") + if err != nil { + return err + } + } + network = models.NewNetworkFromCluster(network, clusterName) + // anrSettings, avagoVersionSettings, globalNetworkFlags are empty + if err = node.StartLocalNode(app, clusterName, useEtnaDevnet, avagoBinaryPath, anrSettings, avagoVersionSettings, globalNetworkFlags, nil); err != nil { + return err + } } } if len(bootstrapEndpoints) > 0 { From 7aa4b6d9005728403f017f99721c02a3a697ceb4 Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Thu, 17 Oct 2024 07:17:41 -0300 Subject: [PATCH 56/57] lint --- cmd/blockchaincmd/add_validator.go | 18 ++++++++++++------ pkg/subnet/public.go | 3 +-- sdk/interchain/signature-aggregator_test.go | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cmd/blockchaincmd/add_validator.go b/cmd/blockchaincmd/add_validator.go index d4d88bb99..7f7b4000a 100644 --- a/cmd/blockchaincmd/add_validator.go +++ b/cmd/blockchaincmd/add_validator.go @@ -91,7 +91,6 @@ Testnet or Mainnet.`, cmd.Flags().BoolVarP(&useEwoq, "ewoq", "e", false, "use ewoq key [fuji/devnet only]") cmd.Flags().BoolVarP(&useLedger, "ledger", "g", false, "use ledger instead of key (always true on mainnet, defaults to false on fuji/devnet)") cmd.Flags().StringSliceVar(&ledgerAddresses, "ledger-addrs", []string{}, "use the given ledger addresses") - cmd.Flags().BoolVar(&sovereign, "sovereign", true, "set to false if adding validator to a non-sovereign blockchain") cmd.Flags().StringVar(&nodeIDStr, "node-id", "", "node-id of the validator to add") cmd.Flags().StringVar(&publicKey, "bls-public-key", "", "set the BLS public key of the validator to add") cmd.Flags().StringVar(&pop, "bls-proof-of-possession", "", "set the BLS proof of possession of the validator to add") @@ -158,15 +157,22 @@ func addValidator(_ *cobra.Command, args []string) error { } nodeIDStr = nodeID.String() } + if err := prompts.ValidateNodeID(nodeIDStr); err != nil { + return err + } + + sc, err := app.LoadSidecar(blockchainName) + if err != nil { + return fmt.Errorf("failed to load sidecar: %w", err) + } + sovereign := sc.Sovereign + if sovereign && publicKey == "" && pop == "" { publicKey, pop, err = promptProofOfPossession(true, true) if err != nil { return err } } - if err := prompts.ValidateNodeID(nodeIDStr); err != nil { - return err - } network.HandlePublicNetworkSimulation() @@ -226,7 +232,7 @@ func CallAddValidator( return err } if !ownerPrivateKeyFound { - return fmt.Errorf("not private key found for PoA manager owner %s", sc.PoAValidatorManagerOwner) + return fmt.Errorf("private key for PoA manager owner %s is not found", sc.PoAValidatorManagerOwner) } ux.Logger.PrintToUser(logging.Yellow.Wrap("PoA manager owner %s pays for the initialization of the validator's registration (Blockchain gas token)"), sc.PoAValidatorManagerOwner) @@ -245,7 +251,7 @@ func CallAddValidator( if privateKey == "" { privateKey, err = prompts.PromptPrivateKey( app.Prompt, - "pay for completing registration of validator? (Blockchain gas token)", + "pay for registering validator on blockchain? (Blockchain gas token)", app.GetKeyDir(), app.GetKey, genesisAddress, diff --git a/pkg/subnet/public.go b/pkg/subnet/public.go index e7d95142a..d20dbe7cb 100644 --- a/pkg/subnet/public.go +++ b/pkg/subnet/public.go @@ -125,7 +125,6 @@ func (d *PublicDeployer) SetL1ValidatorWeight( return nil, nil } -//nolint:all func (d *PublicDeployer) RegisterL1Validator( balance uint64, pop signer.ProofOfPossession, @@ -148,7 +147,7 @@ func (d *PublicDeployer) RegisterL1Validator( return id, tx, err } -func (d *PublicDeployer) createRegisterSubnetValidatorTx( +func (*PublicDeployer) createRegisterSubnetValidatorTx( balance uint64, pop signer.ProofOfPossession, message *warp.Message, diff --git a/sdk/interchain/signature-aggregator_test.go b/sdk/interchain/signature-aggregator_test.go index 1e3284768..a7ce6b219 100644 --- a/sdk/interchain/signature-aggregator_test.go +++ b/sdk/interchain/signature-aggregator_test.go @@ -9,6 +9,7 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/awm-relayer/peers/mocks" + "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) @@ -25,6 +26,7 @@ func instantiateAggregator(t *testing.T) ( aggregator, err := initSignatureAggregator( mockNetwork, logging.NoLog{}, + prometheus.DefaultRegisterer, subnetID, DefaultQuorumPercentage, ) From dc51ea785c6701cfe80a1aa5cb8854b69e5e3fd8 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Thu, 17 Oct 2024 11:32:57 -0400 Subject: [PATCH 57/57] fix merge --- go.mod | 4 ++-- go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 196990a4a..45b32413a 100644 --- a/go.mod +++ b/go.mod @@ -180,7 +180,7 @@ require ( github.com/prometheus/common v0.55.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/cors v1.7.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect @@ -223,7 +223,7 @@ require ( golang.org/x/tools v0.24.0 // indirect gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect google.golang.org/grpc v1.67.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect diff --git a/go.sum b/go.sum index 7b72692d7..5b49cf0db 100644 --- a/go.sum +++ b/go.sum @@ -1227,8 +1227,8 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEY google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed h1:J6izYgfBXAI3xTKLgxzTmUltdYaLsuBxFCgDHWJ/eXg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=