Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Register validator local #2247

Merged
merged 67 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
bc89a4d
node local init
arturrez Oct 2, 2024
37da482
hardcode etna devnet config
arturrez Oct 2, 2024
9459b43
wip
arturrez Oct 3, 2024
3ddc12c
rm not needed utils
arturrez Oct 3, 2024
34f9382
Merge branch 'acp-77' into node-create-local
arturrez Oct 3, 2024
035cb92
ready for draft PR
arturrez Oct 3, 2024
3b1e676
nits
arturrez Oct 3, 2024
495d59c
refactor - wip
arturrez Oct 4, 2024
1d52dd5
make sure we can resume without prompts
arturrez Oct 5, 2024
1c1d061
add custom network and local cluster
arturrez Oct 5, 2024
ac37dce
devnet instead of custom network, rm custom
arturrez Oct 5, 2024
9acca2e
Merge branch 'acp-77' into node-create-local
arturrez Oct 8, 2024
64ba256
go mod tidy
arturrez Oct 8, 2024
71e313b
upgrade.json for etna devnet
arturrez Oct 8, 2024
884043e
more local cluster
arturrez Oct 9, 2024
1f1358e
partial work
felipemadero Oct 9, 2024
74b9a7c
separate between local network and local cluster
felipemadero Oct 10, 2024
dce0e98
Merge branch 'acp-77' into node-create-local
felipemadero Oct 10, 2024
23b4e86
working
felipemadero Oct 10, 2024
b8f20ca
nit
felipemadero Oct 10, 2024
e225ed5
fix plugin
felipemadero Oct 10, 2024
7a12d78
nit
felipemadero Oct 10, 2024
93a3cfe
improve snapshot management
felipemadero Oct 10, 2024
c617154
fix bug
felipemadero Oct 10, 2024
c6ed553
nit
felipemadero Oct 10, 2024
afb44a1
proper etna devnet boostrappers
arturrez Oct 10, 2024
f2653d8
fix bug with local rootdir
arturrez Oct 11, 2024
3b3d699
remove global node config stuff
felipemadero Oct 11, 2024
3b4cdfe
destroy node data and processes if bad start
felipemadero Oct 11, 2024
61eb94d
nit
felipemadero Oct 11, 2024
46fa068
always use fresh staking keys
felipemadero Oct 11, 2024
ac2bdc3
nit
felipemadero Oct 11, 2024
ea9d1b9
so less flags
felipemadero Oct 11, 2024
02f02ab
add back fast boot time
felipemadero Oct 11, 2024
c788f4a
Merge branch 'node-create-local-fix' into node-create-local
felipemadero Oct 11, 2024
27ecc41
add checks for local cluster. minor refactor (#2239)
arturrez Oct 12, 2024
046ccb6
bump anr
felipemadero Oct 12, 2024
f134935
fixes for convert flow
felipemadero Oct 12, 2024
719aea1
add check for already initialized error on PoA init
felipemadero Oct 13, 2024
2aa05d1
nit
felipemadero Oct 13, 2024
b10649c
not to much further to have a complete flow
felipemadero Oct 13, 2024
11ffc8e
ok esto esta funcionando
felipemadero Oct 14, 2024
8241469
started refactoring
felipemadero Oct 14, 2024
918e28e
use relayer branch
felipemadero Oct 14, 2024
b91ce21
partial work
felipemadero Oct 14, 2024
72c1464
use anr main
felipemadero Oct 14, 2024
3ed244f
working for devnets
felipemadero Oct 14, 2024
6f1e48c
Merge branch 'acp-77' into register-validator
felipemadero Oct 14, 2024
5986007
Merge branch 'node-create-local' into register-validator-local
felipemadero Oct 14, 2024
5859945
is this working
felipemadero Oct 14, 2024
deaa321
working for local
felipemadero Oct 14, 2024
422537e
nit
felipemadero Oct 14, 2024
e47405b
working
felipemadero Oct 14, 2024
480d4ba
bump anr
felipemadero Oct 15, 2024
55255d7
Merge branch 'acp-77' into register-validator-local
sukantoraymond Oct 16, 2024
e97fd1f
Fix merge
sukantoraymond Oct 16, 2024
b5b28fd
Fix merge
sukantoraymond Oct 16, 2024
c459f5c
Fix merge
sukantoraymond Oct 16, 2024
93aa9c3
Update avalanche go ledger (#2234)
sukantoraymond Oct 16, 2024
99ab7d9
lint
sukantoraymond Oct 16, 2024
6850ff1
fix merge
sukantoraymond Oct 16, 2024
86e1f0a
Merge branch 'acp-77' into register-validator-local
felipemadero Oct 17, 2024
b1d7942
nits
felipemadero Oct 17, 2024
7aa4b6d
lint
felipemadero Oct 17, 2024
4a0eb07
Merge branch 'main' into acp-77
sukantoraymond Oct 17, 2024
dc51ea7
fix merge
sukantoraymond Oct 17, 2024
cd8a6f1
Merge branch 'acp-77' into register-validator-local
felipemadero Oct 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
314 changes: 217 additions & 97 deletions cmd/blockchaincmd/add_validator.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cmd/blockchaincmd/change_weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
felipemadero marked this conversation as resolved.
Show resolved Hide resolved
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)")
Expand Down Expand Up @@ -166,13 +166,13 @@ func setWeight(_ *cobra.Command, args []string) error {
return err
}

changeAddr, err = getChangeAddrFromPChain()
remainingBalanceOwnerAddr, 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
Expand Down
133 changes: 92 additions & 41 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// / Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package blockchaincmd

Expand All @@ -13,6 +13,7 @@ import (
"time"

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

"github.com/ava-labs/avalanche-cli/pkg/evm"
"github.com/ava-labs/avalanche-cli/pkg/node"
Expand Down Expand Up @@ -81,6 +82,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")
Expand Down Expand Up @@ -136,6 +138,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")
cmd.Flags().BoolVar(&useLocalMachine, "use-local-machine", false, "use local machine as a blockchain validator")
cmd.Flags().StringVar(&localMachineCluster, "local-machine-cluster", "", "existing local machine to be used as a blockchain validator")

Expand Down Expand Up @@ -474,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 {
Expand Down Expand Up @@ -775,7 +780,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}

if !generateNodeID {
if !convertOnly {
clusterName := network.ClusterName
if clusterName == "" {
clusterName, err = node.GetClusterNameFromList(app)
Expand Down Expand Up @@ -842,7 +847,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
ux.Logger.GreenCheckmarkToUser("Proof of Authority Validator Manager contract successfully initialized on blockchain %s", blockchainName)
} 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)
Expand Down Expand Up @@ -1110,8 +1115,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 {
Expand All @@ -1134,9 +1185,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
}
37 changes: 37 additions & 0 deletions cmd/blockchaincmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
6 changes: 4 additions & 2 deletions cmd/blockchaincmd/prompt_genesis_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down
21 changes: 13 additions & 8 deletions cmd/contractcmd/init_poa_validator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -132,7 +137,7 @@ func initPOAManager(_ *cobra.Command, args []string) error {
privateKey,
common.HexToAddress(sc.PoAValidatorManagerOwner),
avaGoBootstrapValidators,
privateAggregatorEndpoints,
extraAggregatorPeers,
); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/nodecmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
stakingTLSKeyPath string
stakingCertKeyPath string
stakingSignerKeyPath string
numNodes uint32
)

// const snapshotName = "local_snapshot"
Expand Down Expand Up @@ -79,6 +80,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
}

Expand Down
Loading
Loading