-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add poa setup to blockchain deploy (#2219)
* add setup poa to blockchain deploy * add command * add proposervm update * proposervm flag for nodes * nit * nit * fixed dynamic fees params calculation * only adding tracked apis to apis in sidecar * improve prompts * fixing various stuff * add upgrade file * use anr etna enabled * keep upgrade on sync * workin * almost working * working1 * Update cmd/keycmd/transfer.go Co-authored-by: Meaghan FitzGerald <meag.fitz@avalabs.org> Signed-off-by: felipemadero <felipe.madero@gmail.com> * fix some lint * address PR comments * missing file * nit --------- Signed-off-by: felipemadero <felipe.madero@gmail.com> Signed-off-by: sukantoraymond <rsukanto@umich.edu> Co-authored-by: Meaghan FitzGerald <meag.fitz@avalabs.org> Co-authored-by: sukantoraymond <rsukanto@umich.edu>
- Loading branch information
1 parent
ae81087
commit 971693f
Showing
36 changed files
with
791 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
package contractcmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ava-labs/avalanche-cli/cmd/blockchaincmd" | ||
"github.com/ava-labs/avalanche-cli/pkg/cobrautils" | ||
"github.com/ava-labs/avalanche-cli/pkg/contract" | ||
"github.com/ava-labs/avalanche-cli/pkg/networkoptions" | ||
"github.com/ava-labs/avalanche-cli/pkg/prompts" | ||
"github.com/ava-labs/avalanche-cli/pkg/ux" | ||
"github.com/ava-labs/avalanche-cli/pkg/validatormanager" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
"github.com/ethereum/go-ethereum/common" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
type InitPOAManagerFlags struct { | ||
Network networkoptions.NetworkFlags | ||
PrivateKeyFlags contract.PrivateKeyFlags | ||
rpcEndpoint string | ||
} | ||
|
||
var ( | ||
initPOAManagerSupportedNetworkOptions = []networkoptions.NetworkOption{ | ||
networkoptions.Local, | ||
networkoptions.Devnet, | ||
networkoptions.Fuji, | ||
} | ||
initPOAManagerFlags InitPOAManagerFlags | ||
) | ||
|
||
// avalanche contract initpoamanager | ||
func newInitPOAManagerCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "initPoaManager", | ||
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, | ||
Args: cobrautils.ExactArgs(1), | ||
} | ||
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") | ||
return cmd | ||
} | ||
|
||
func initPOAManager(_ *cobra.Command, args []string) error { | ||
blockchainName := args[0] | ||
chainSpec := contract.ChainSpec{ | ||
BlockchainName: blockchainName, | ||
} | ||
network, err := networkoptions.GetNetworkFromCmdLineFlags( | ||
app, | ||
"", | ||
initPOAManagerFlags.Network, | ||
true, | ||
false, | ||
initPOAManagerSupportedNetworkOptions, | ||
"", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if initPOAManagerFlags.rpcEndpoint == "" { | ||
initPOAManagerFlags.rpcEndpoint, _, err = contract.GetBlockchainEndpoints( | ||
app, | ||
network, | ||
chainSpec, | ||
true, | ||
false, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
ux.Logger.PrintToUser(logging.Yellow.Wrap("RPC Endpoint: %s"), initPOAManagerFlags.rpcEndpoint) | ||
genesisAddress, genesisPrivateKey, err := contract.GetEVMSubnetPrefundedKey( | ||
app, | ||
network, | ||
chainSpec, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
privateKey, err := initPOAManagerFlags.PrivateKeyFlags.GetPrivateKey(app, genesisPrivateKey) | ||
if err != nil { | ||
return err | ||
} | ||
if privateKey == "" { | ||
privateKey, err = prompts.PromptPrivateKey( | ||
app.Prompt, | ||
"Which key to you want to use to pay for initializing Proof of Authority Validator Manager contract? (Uses Blockchain gas token)", | ||
app.GetKeyDir(), | ||
app.GetKey, | ||
genesisAddress, | ||
genesisPrivateKey, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
sc, err := app.LoadSidecar(chainSpec.BlockchainName) | ||
if err != nil { | ||
return fmt.Errorf("failed to load sidecar: %w", err) | ||
} | ||
if sc.Networks[network.Name()].BlockchainID == ids.Empty { | ||
return fmt.Errorf("blockchain has not been deployed to %s", network.Name()) | ||
} | ||
bootstrapValidators := sc.Networks[network.Name()].BootstrapValidators | ||
avaGoBootstrapValidators, err := blockchaincmd.ConvertToAvalancheGoSubnetValidator(bootstrapValidators) | ||
if err != nil { | ||
return err | ||
} | ||
if err := validatormanager.SetupPoA( | ||
app, | ||
network, | ||
initPOAManagerFlags.rpcEndpoint, | ||
chainSpec, | ||
privateKey, | ||
common.HexToAddress(sc.PoAValidatorManagerOwner), | ||
avaGoBootstrapValidators, | ||
); err != nil { | ||
return err | ||
} | ||
ux.Logger.GreenCheckmarkToUser("Proof of Authority Validator Manager contract successfully initialized on blockchain %s", blockchainName) | ||
return nil | ||
} |
Oops, something went wrong.