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

Validator prompt acp77 #2152

Merged
merged 50 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
63cb85b
prompt addresses
sukantoraymond Sep 11, 2024
22c18e8
fix lint
sukantoraymond Sep 11, 2024
ff53b08
fix lint
sukantoraymond Sep 11, 2024
39f17e0
fix lint
sukantoraymond Sep 11, 2024
aef7fc1
fix lint
sukantoraymond Sep 11, 2024
2866231
add flags
sukantoraymond Sep 11, 2024
4295956
validator prompt
sukantoraymond Sep 12, 2024
ee79685
bootstrap validators
sukantoraymond Sep 12, 2024
f586cb6
add mock
sukantoraymond Sep 12, 2024
d15757c
fix lint
sukantoraymond Sep 12, 2024
059519d
update prompt validator
sukantoraymond Sep 13, 2024
4809209
update prompt validator
sukantoraymond Sep 13, 2024
e87b8f1
implement prompts
sukantoraymond Sep 16, 2024
b12908d
fix prompt mock
sukantoraymond Sep 16, 2024
10a0377
update sidecar
sukantoraymond Sep 16, 2024
3d6ade0
update prompts
sukantoraymond Sep 16, 2024
1395511
update prompts
sukantoraymond Sep 17, 2024
b8a0a88
refactor
sukantoraymond Sep 17, 2024
7d829d7
update prompts
sukantoraymond Sep 18, 2024
4cbe6e7
update prompts
sukantoraymond Sep 18, 2024
3756c9d
use default balance and weight
sukantoraymond Sep 18, 2024
5042124
generate new node ids and bls
sukantoraymond Sep 18, 2024
f218939
fix lint
sukantoraymond Sep 18, 2024
773f313
add flags
sukantoraymond Sep 18, 2024
1dcf24c
add flags
sukantoraymond Sep 18, 2024
c8c4e5c
address comments
sukantoraymond Sep 19, 2024
a66cb32
address comments
sukantoraymond Sep 19, 2024
890d6db
address comments
sukantoraymond Sep 19, 2024
b55a792
move validator prompt to deploy
sukantoraymond Sep 19, 2024
58bfdae
address comments
sukantoraymond Sep 19, 2024
9fe693e
address comments
sukantoraymond Sep 19, 2024
bfb0c67
fix lint
sukantoraymond Sep 19, 2024
9d7bac8
address comments
sukantoraymond Sep 19, 2024
e27cfb7
Merge branch 'acp-77' into subnet-create-acp77
sukantoraymond Sep 19, 2024
4c7ee6f
Merge branch 'subnet-create-acp77' into validator-prompt-acp77
sukantoraymond Sep 19, 2024
9e2a87c
address comments
sukantoraymond Sep 19, 2024
b7408b3
fix test
sukantoraymond Sep 19, 2024
03e79d5
Merge branch 'subnet-create-acp77' into validator-prompt-acp77
sukantoraymond Sep 19, 2024
2a8c14d
address comments
sukantoraymond Sep 20, 2024
3168a79
Merge branch 'acp-77' into subnet-create-acp77
sukantoraymond Sep 20, 2024
b39b4ea
Merge branch 'subnet-create-acp77' into validator-prompt-acp77
sukantoraymond Sep 20, 2024
1cc8146
fix lint
sukantoraymond Sep 20, 2024
7e7618b
Merge branch 'acp-77' into validator-prompt-acp77
sukantoraymond Sep 23, 2024
b7f9df7
address coments
sukantoraymond Sep 23, 2024
1ea414f
address coments
sukantoraymond Sep 23, 2024
44bfcd7
fix test
sukantoraymond Sep 23, 2024
f0c44c1
Merge branch 'acp-77' into validator-prompt-acp77
sukantoraymond Sep 23, 2024
d40b767
fix test
sukantoraymond Sep 23, 2024
361bf60
fix test
sukantoraymond Sep 23, 2024
7cc625e
fix lint
sukantoraymond Sep 23, 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
13 changes: 4 additions & 9 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func CallAddValidator(
ux.Logger.PrintToUser("Your subnet auth keys for add validator tx creation: %s", subnetAuthKeys)

if nodeIDStr == "" {
nodeID, err = PromptNodeID()
nodeID, err = PromptNodeID("add as validator")
if err != nil {
return err
}
Expand All @@ -225,7 +225,7 @@ func CallAddValidator(
return err
}
if selectedWeight < constants.MinStakeWeight {
return fmt.Errorf("illegal weight, must be greater than or equal to %d: %d", constants.MinStakeWeight, selectedWeight)
return fmt.Errorf("invalid weight, must be greater than or equal to %d: %d", constants.MinStakeWeight, selectedWeight)
}

start, selectedDuration, err := getTimeParameters(network, nodeID, true)
Expand Down Expand Up @@ -406,13 +406,8 @@ func promptStart() (time.Time, error) {
return app.Prompt.CaptureDate(txt)
}

func PromptNodeID() (ids.NodeID, error) {
ux.Logger.PrintToUser("Next, we need the NodeID of the validator you want to whitelist.")
ux.Logger.PrintToUser("")
ux.Logger.PrintToUser("Check https://docs.avax.network/apis/avalanchego/apis/info#infogetnodeid for instructions about how to query the NodeID from your node")
ux.Logger.PrintToUser("(Edit host IP address and port to match your deployment, if needed).")

txt := "What is the NodeID of the validator you'd like to whitelist?"
func PromptNodeID(goal string) (ids.NodeID, error) {
txt := fmt.Sprintf("What is the NodeID of the node you want to %s?", goal)
return app.Prompt.CaptureNodeID(txt)
}

Expand Down
53 changes: 5 additions & 48 deletions cmd/blockchaincmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"strings"
"unicode"

"github.com/ava-labs/avalanche-cli/pkg/application"

"github.com/ava-labs/avalanche-cli/cmd/flags"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
Expand Down Expand Up @@ -52,12 +50,11 @@ type CreateFlags struct {
}

var (
createFlags CreateFlags
forceCreate bool
genesisFile string
vmFile string
useRepo bool

createFlags CreateFlags
forceCreate bool
genesisFile string
vmFile string
useRepo bool
errIllegalNameCharacter = errors.New(
"illegal name character: only letters, no special characters allowed")
errMutuallyExlusiveVersionOptions = errors.New("version flags --latest,--pre-release,vm-version are mutually exclusive")
Expand Down Expand Up @@ -437,43 +434,3 @@ func checkInvalidSubnetNames(name string) error {
}
return nil
}

// TODO: add explain the difference for different validator management type
func promptValidatorManagementType(
app *application.Avalanche,
sidecar *models.Sidecar,
) error {
proofOfAuthorityOption := "Proof of Authority"
proofOfStakeOption := "Proof of Stake"
explainOption := "Explain the difference"
if createFlags.proofOfStake {
sidecar.ValidatorManagement = models.ValidatorManagementTypeFromString(proofOfStakeOption)
return nil
}
if createFlags.proofOfAuthority {
sidecar.ValidatorManagement = models.ValidatorManagementTypeFromString(proofOfAuthorityOption)
return nil
}
options := []string{proofOfAuthorityOption, proofOfStakeOption, explainOption}
var subnetTypeStr string
for {
option, err := app.Prompt.CaptureList(
"Which validator management protocol would you like to use in your blockchain?",
options,
)
if err != nil {
return err
}
switch option {
case proofOfAuthorityOption:
subnetTypeStr = models.ProofOfAuthority
case proofOfStakeOption:
subnetTypeStr = models.ProofOfStake
case explainOption:
continue
}
break
}
sidecar.ValidatorManagement = models.ValidatorManagementTypeFromString(subnetTypeStr)
return nil
}
102 changes: 64 additions & 38 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ava-labs/avalanche-cli/pkg/utils"

"github.com/ava-labs/avalanche-cli/pkg/binutils"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
Expand Down Expand Up @@ -43,23 +43,24 @@ var deploySupportedNetworkOptions = []networkoptions.NetworkOption{
}

var (
sameControlKey bool
keyName string
threshold uint32
controlKeys []string
subnetAuthKeys []string
userProvidedAvagoVersion string
outputTxPath string
useLedger bool
useEwoq bool
ledgerAddresses []string
subnetIDStr string
mainnetChainID uint32
skipCreatePrompt bool
avagoBinaryPath string
subnetOnly bool
icmSpec subnet.ICMSpec
validatorManagerOwner string
sameControlKey bool
keyName string
threshold uint32
controlKeys []string
subnetAuthKeys []string
userProvidedAvagoVersion string
outputTxPath string
useLedger bool
useEwoq bool
ledgerAddresses []string
subnetIDStr string
mainnetChainID uint32
skipCreatePrompt bool
avagoBinaryPath string
subnetOnly bool
icmSpec subnet.ICMSpec
generateNodeID bool
bootstrapValidatorsJSONFilePath 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")
Expand Down Expand Up @@ -109,7 +110,8 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().StringVar(&icmSpec.MessengerDeployerAddressPath, "teleporter-messenger-deployer-address-path", "", "path to an interchain messenger deployer address file")
cmd.Flags().StringVar(&icmSpec.MessengerDeployerTxPath, "teleporter-messenger-deployer-tx-path", "", "path to an interchain messenger deployer tx file")
cmd.Flags().StringVar(&icmSpec.RegistryBydecodePath, "teleporter-registry-bytecode-path", "", "path to an interchain messenger registry bytecode file")
cmd.Flags().StringVar(&validatorManagerOwner, "validator-manager-owner", "", "EVM address that controls Validator Manager Controller (for Proof of Authority only)")
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)")
return cmd
}

Expand Down Expand Up @@ -284,6 +286,14 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
}

var bootstrapValidators []models.SubnetValidator
if bootstrapValidatorsJSONFilePath != "" {
bootstrapValidators, err = LoadBootstrapValidator(bootstrapValidatorsJSONFilePath)
if err != nil {
return err
}
}

chain := chains[0]

sidecar, err := app.LoadSidecar(chain)
Expand All @@ -295,10 +305,6 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return errors.New("unable to deploy subnets imported from a repo")
}

if sidecar.ValidatorManagement != models.ProofOfAuthority && validatorManagerOwner != "" {
return errors.New("--validator-manager-controller flag cannot be used when blockchain validator management type is not Proof of Authority")
}

if outputTxPath != "" {
if _, err := os.Stat(outputTxPath); err == nil {
return fmt.Errorf("outputTxPath %q already exists", outputTxPath)
Expand Down Expand Up @@ -349,6 +355,13 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
}

if 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 {
Expand Down Expand Up @@ -400,7 +413,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
deployInfo.BlockchainID,
deployInfo.ICMMessengerAddress,
deployInfo.ICMRegistryAddress,
validatorManagerOwner,
bootstrapValidators,
); err != nil {
return err
}
Expand Down Expand Up @@ -503,15 +516,6 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
ux.Logger.PrintToUser("Your subnet auth keys for chain creation: %s", subnetAuthKeys)

if validatorManagerOwner == "" {
validatorManagerOwnerEVMAddress, err := getValidatorContractOwnerAddr()
if err != nil {
return err
}
validatorManagerOwner = validatorManagerOwnerEVMAddress.String()
}
ux.Logger.PrintToUser("Validator Manager Contract controller address %s", validatorManagerOwner)

// deploy to public network
deployer := subnet.NewPublicDeployer(app, kc, network)

Expand Down Expand Up @@ -576,11 +580,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {

// update sidecar
// TODO: need to do something for backwards compatibility?
return app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", validatorManagerOwner)
}

func getValidatorContractOwnerAddr() (common.Address, error) {
return app.Prompt.CaptureAddress("What is the EVM address that will control the Validator Manager Contract?")
return app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", bootstrapValidators)
}

func ValidateSubnetNameAndGetChains(args []string) ([]string, error) {
Expand Down Expand Up @@ -753,3 +753,29 @@ func CheckForInvalidDeployAndGetAvagoVersion(
}
return desiredAvagoVersion, nil
}

func LoadBootstrapValidator(filepath string) ([]models.SubnetValidator, error) {
if !utils.FileExists(filepath) {
return nil, fmt.Errorf("file path %q doesn't exist", filepath)
}
jsonBytes, err := os.ReadFile(filepath)
if err != nil {
return nil, err
}
var subnetValidators []models.SubnetValidator
if err = json.Unmarshal(jsonBytes, &subnetValidators); err != nil {
return nil, err
}
if err = validateSubnetValidatorsJSON(generateNodeID, subnetValidators); err != nil {
return nil, err
}
if generateNodeID {
for _, subnetValidator := range subnetValidators {
subnetValidator.NodeID, subnetValidator.BLSPublicKey, subnetValidator.BLSProofOfPossession, err = generateNewNodeAndBLS()
if err != nil {
return nil, err
}
}
}
return subnetValidators, nil
}
Loading
Loading