Skip to content

Commit

Permalink
ACP 77 new commands (#2172)
Browse files Browse the repository at this point in the history
* prompt addresses

* fix lint

* fix lint

* fix lint

* fix lint

* add flags

* adding teleporter contract to genesis

* validator prompt

* bootstrap validators

* add mock

* fix lint

* update prompt validator

* update prompt validator

* fixes for icm on genesis

* add icm from a given embedded file

* add function to deploy ICM registry

* creating mapping values

* add consts

* make local deploy to work

* do not print info for icm support addrs

* nit

* implement prompts

* fix prompt mock

* update sidecar

* update prompts

* update prompts

* refactor

* nit

* update prompts

* fix wiz stuff

* update prompts

* use default balance and weight

* generate new node ids and bls

* fix lint

* add flags

* add flags

* add a function to initialize PoA manager

* add lib folder

* address comments

* address comments

* address comments

* move validator prompt to deploy

* address comments

* address comments

* fix lint

* address comments

* address comments

* fix test

* address PR comments

* basic PoA manager setting

* lint

* address comments

* fix lint

* fix e2e

* fix merge

* fix merge

* convert Subnet Tx

* convert subnet

* register validator

* add validator

* mock

* remove validator

* update weight

* update weight

* add flags add validator

* remove validator update

* refactor addvalidator

* use node id as arg in addvalidator

* fix change weight arg

* resolve merge conflict

* fix lint

* address comments

* fix lint

* Enable non sov subnets (#2203)

* subnet create non sov

* support non sov blockchain

* update test

* update tests

* update tests

* update test

* update tests

* update tests

* fix test

* update tests

* Rename Subnet to L1 for new commands ACP77 (#2209)

* rename convert subnet

* rename to l1

* fix lint

* fix lint

* fix lint

* fix lint

* Integrate ConvertSubnetTx AvalancheGo  (#2213)

* complete implementation of avalanche go convertsubnet

* update relayer

* update convertsubnettx

* update avalanchego

* update avalanche go

* update avalanche go

* dont prompt control key for sov

* add tx cases for convert subnet tx (#2218)

* Poa integration (#2212)

* use latest contract

* point to latest convert subnet avago PR

* nit

* use fixed anr

* nit

* add subnet conversion id calculation

* created unsigned warp message

* fixed local network deploy

* added signing

* now this is working

* using latest avago master + awm relayer

* working pretty well

* ready

* lint

* address PR comments

* nit

---------

Signed-off-by: sukantoraymond <rsukanto@umich.edu>
Co-authored-by: sukantoraymond <rsukanto@umich.edu>

* fix lint

* reverse sidecar sov logic

* fix merge

* 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>

---------

Signed-off-by: sukantoraymond <rsukanto@umich.edu>
Signed-off-by: felipemadero <felipe.madero@gmail.com>
Co-authored-by: felipemadero <felipe.madero@gmail.com>
Co-authored-by: Meaghan FitzGerald <meag.fitz@avalabs.org>

* fix lint

---------

Signed-off-by: sukantoraymond <rsukanto@umich.edu>
Signed-off-by: felipemadero <felipe.madero@gmail.com>
Co-authored-by: felipemadero <felipe.madero@gmail.com>
Co-authored-by: Meaghan FitzGerald <meag.fitz@avalabs.org>

---------

Signed-off-by: sukantoraymond <rsukanto@umich.edu>
Signed-off-by: felipemadero <felipe.madero@gmail.com>
Co-authored-by: Felipe Madero <felipe.madero@gmail.com>
Co-authored-by: Meaghan FitzGerald <meag.fitz@avalabs.org>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent 58fdeb2 commit 3dbca8b
Show file tree
Hide file tree
Showing 63 changed files with 3,909 additions and 445 deletions.
199 changes: 163 additions & 36 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"fmt"
"time"

"github.com/ava-labs/avalanchego/utils/formatting/address"
warpPlatformVM "github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"

"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/keychain"
Expand All @@ -32,6 +36,7 @@ var (
}

nodeIDStr string
balance uint64
weight uint64
startTimeStr string
duration time.Duration
Expand All @@ -40,6 +45,9 @@ var (
useDefaultDuration bool
useDefaultWeight bool
waitForTxAcceptance bool
publicKey string
pop string
changeAddr 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")
Expand Down Expand Up @@ -69,28 +77,26 @@ 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().StringVar(&nodeIDStr, "nodeID", "", "set the NodeID of the validator to add")
cmd.Flags().Uint64Var(&weight, "weight", 0, "set the staking weight of the validator to add")

cmd.Flags().BoolVar(&useDefaultStartTime, "default-start-time", false, "use default start time for subnet validator (5 minutes later for fuji & mainnet, 30 seconds later for devnet)")
cmd.Flags().StringVar(&startTimeStr, "start-time", "", "UTC start time when this validator starts validating, in 'YYYY-MM-DD HH:MM:SS' format")

cmd.Flags().BoolVar(&useDefaultDuration, "default-duration", false, "set duration so as to validate until primary validator ends its period")
cmd.Flags().DurationVar(&duration, "staking-period", 0, "how long this validator will be staking")

cmd.Flags().BoolVar(&defaultValidatorParams, "default-validator-params", false, "use default weight/start/duration params for subnet validator")

cmd.Flags().StringSliceVar(&subnetAuthKeys, "subnet-auth-keys", nil, "control keys that will be used to authenticate add validator tx")
cmd.Flags().StringVar(&outputTxPath, "output-tx-path", "", "file path of the add validator tx")
cmd.Flags().Uint64Var(&weight, "weight", constants.BootstrapValidatorWeight, "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)")
cmd.Flags().StringSliceVar(&ledgerAddresses, "ledger-addrs", []string{}, "use the given ledger addresses")
cmd.Flags().BoolVar(&waitForTxAcceptance, "wait-for-tx-acceptance", true, "just issue the add validator tx, without waiting for its acceptance")
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")
cmd.Flags().StringVar(&changeAddr, "change-address", "", "P-Chain address that will receive any leftover AVAX from the validator when it is removed from Subnet")
return cmd
}

func addValidator(_ *cobra.Command, args []string) error {
blockchainName := args[0]
err := prompts.ValidateNodeID(nodeIDStr)
if err != nil {
return err
}

network, err := networkoptions.GetNetworkFromCmdLineFlags(
app,
"",
Expand Down Expand Up @@ -118,14 +124,148 @@ func addValidator(_ *cobra.Command, args []string) error {
return err
}
network.HandlePublicNetworkSimulation()
if err := UpdateKeychainWithSubnetControlKeys(kc, network, blockchainName); err != nil {
return err
if !sovereign {
if err := UpdateKeychainWithSubnetControlKeys(kc, network, blockchainName); err != nil {
return err
}
}
deployer := subnet.NewPublicDeployer(app, kc, network)
return CallAddValidator(deployer, network, kc, useLedger, blockchainName, nodeIDStr, defaultValidatorParams, waitForTxAcceptance)
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("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...")

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())
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,
kc *keychain.Keychain,
Expand All @@ -135,12 +275,11 @@ func CallAddValidator(
defaultValidatorParamsSetting bool,
waitForTxAcceptanceSetting bool,
) error {
var (
nodeID ids.NodeID
start time.Time
err error
)

var start time.Time
nodeID, err := ids.NodeIDFromString(nodeIDStr)
if err != nil {
return err
}
useLedger = useLedgerSetting
defaultValidatorParams = defaultValidatorParamsSetting
waitForTxAcceptance = waitForTxAcceptanceSetting
Expand Down Expand Up @@ -208,18 +347,6 @@ func CallAddValidator(
}
ux.Logger.PrintToUser("Your subnet auth keys for add validator tx creation: %s", subnetAuthKeys)

if nodeIDStr == "" {
nodeID, err = PromptNodeID("add as validator")
if err != nil {
return err
}
} else {
nodeID, err = ids.NodeIDFromString(nodeIDStr)
if err != nil {
return err
}
}

selectedWeight, err := getWeight()
if err != nil {
return err
Expand All @@ -240,7 +367,7 @@ func CallAddValidator(
ux.Logger.PrintToUser("Weight: %d", selectedWeight)
ux.Logger.PrintToUser("Inputs complete, issuing transaction to add the provided validator information...")

isFullySigned, tx, remainingSubnetAuthKeys, err := deployer.AddValidator(
isFullySigned, tx, remainingSubnetAuthKeys, err := deployer.AddValidatorNonSOV(
waitForTxAcceptance,
controlKeys,
subnetAuthKeys,
Expand Down
2 changes: 2 additions & 0 deletions cmd/blockchaincmd/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ manage your Blockchain configurations and live deployments.`,
cmd.AddCommand(newValidatorsCmd())
// subnet changeOwner
cmd.AddCommand(newChangeOwnerCmd())
// subnet changeWeight
cmd.AddCommand(newChangeWeightCmd())
return cmd
}
Loading

0 comments on commit 3dbca8b

Please sign in to comment.