-
Notifications
You must be signed in to change notification settings - Fork 98
add poa setup to blockchain deploy #2219
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
68c82aa
add setup poa to blockchain deploy
felipemadero e8de962
add command
felipemadero 5c78520
add proposervm update
felipemadero 96090a2
proposervm flag for nodes
felipemadero 2703495
nit
felipemadero f93c053
nit
felipemadero 134a2d2
fixed dynamic fees params calculation
felipemadero e818afb
only adding tracked apis to apis in sidecar
felipemadero 1f91a46
improve prompts
felipemadero 5e39b32
fixing various stuff
felipemadero 99b183a
add upgrade file
felipemadero c804530
use anr etna enabled
felipemadero b49390b
keep upgrade on sync
felipemadero 3e2d624
workin
felipemadero 5dad17f
almost working
felipemadero c4a1d1f
working1
felipemadero e0c7052
Update cmd/keycmd/transfer.go
felipemadero 65f6df6
fix some lint
felipemadero 6fd0482
Merge branch 'convertSubnetAvaGo' into add-poa-setup-call
sukantoraymond 3c25c3b
address PR comments
felipemadero d5b9ee7
missing file
felipemadero 8ab610e
nit
felipemadero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 { | ||
felipemadero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return fmt.Errorf("blockchain has not been deployed to %s", network.Name()) | ||
} | ||
bootstrapValidators := sc.Networks[network.Name()].BootstrapValidators | ||
felipemadero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
} | ||
felipemadero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ux.Logger.GreenCheckmarkToUser("Proof of Authority Validator Manager contract successfully initialized on blockchain %s", blockchainName) | ||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.