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

ACP 77 new commands #2172

Merged
merged 91 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 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
6fd7726
adding teleporter contract to genesis
felipemadero Sep 12, 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
606c4fc
fixes for icm on genesis
felipemadero Sep 16, 2024
29966df
add icm from a given embedded file
felipemadero Sep 16, 2024
dfa8bfa
add function to deploy ICM registry
felipemadero Sep 16, 2024
26ef2fa
creating mapping values
felipemadero Sep 16, 2024
78c58a6
add consts
felipemadero Sep 16, 2024
d39a8e8
make local deploy to work
felipemadero Sep 16, 2024
857f815
do not print info for icm support addrs
felipemadero Sep 16, 2024
c868707
nit
felipemadero Sep 16, 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
e2757a7
nit
felipemadero Sep 17, 2024
d26b4b5
Merge branch 'main' into genesis-icm
felipemadero Sep 18, 2024
7d829d7
update prompts
sukantoraymond Sep 18, 2024
5cd3e16
fix wiz stuff
felipemadero 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
fcda44c
add a function to initialize PoA manager
felipemadero Sep 18, 2024
dc0b321
add lib folder
felipemadero Sep 19, 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
0659211
address PR comments
felipemadero Sep 19, 2024
0663e48
Merge branch 'main' into genesis-icm
felipemadero Sep 19, 2024
03e79d5
Merge branch 'subnet-create-acp77' into validator-prompt-acp77
sukantoraymond Sep 19, 2024
a613ece
Merge branch 'acp-77' into genesis-icm
felipemadero Sep 19, 2024
a377ee1
Merge branch 'genesis-icm' into genesis-poa
felipemadero Sep 20, 2024
723f0b4
Merge branch 'validator-prompt-acp77' into genesis-poa
felipemadero Sep 20, 2024
4bc4e5d
basic PoA manager setting
felipemadero Sep 20, 2024
3f0eca7
lint
felipemadero Sep 20, 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
1cf6851
Merge branch 'validator-prompt-acp77' into genesis-poa
felipemadero Sep 21, 2024
64580c9
fix e2e
felipemadero Sep 21, 2024
b2815f2
Merge branch 'acp-77' into genesis-poa
sukantoraymond Sep 23, 2024
b6f65ca
fix merge
sukantoraymond Sep 23, 2024
7bddc67
Merge branch 'acp-77' into genesis-poa
sukantoraymond Sep 23, 2024
3962f81
fix merge
sukantoraymond Sep 23, 2024
5438ec7
convert Subnet Tx
sukantoraymond Sep 24, 2024
ca2af0d
convert subnet
sukantoraymond Sep 24, 2024
00df2a8
register validator
sukantoraymond Sep 25, 2024
2c3c7c0
add validator
sukantoraymond Sep 25, 2024
8770e4d
mock
sukantoraymond Sep 25, 2024
f5f2e37
remove validator
sukantoraymond Sep 25, 2024
68eeec1
update weight
sukantoraymond Sep 26, 2024
0e74db6
update weight
sukantoraymond Sep 26, 2024
0793c89
add flags add validator
sukantoraymond Sep 26, 2024
3dff1e0
remove validator update
sukantoraymond Sep 26, 2024
b5b7ee2
refactor addvalidator
sukantoraymond Sep 26, 2024
d8e3917
use node id as arg in addvalidator
sukantoraymond Sep 26, 2024
048cb92
fix change weight arg
sukantoraymond Sep 26, 2024
2f70a8a
Merge branch 'acp-77' into convertSubnetTx3
sukantoraymond Sep 26, 2024
b14481b
resolve merge conflict
sukantoraymond Sep 26, 2024
b77683b
fix lint
sukantoraymond Sep 26, 2024
2141d55
Merge branch 'acp-77' into convertSubnetTx3
sukantoraymond Sep 30, 2024
a05a1b6
Merge branch 'acp-77' into convertSubnetTx3
sukantoraymond Sep 30, 2024
46286ca
Merge branch 'acp-77' into convertSubnetTx3
sukantoraymond Oct 1, 2024
031128c
address comments
sukantoraymond Oct 8, 2024
136fd35
fix lint
sukantoraymond Oct 8, 2024
b60d4ad
Enable non sov subnets (#2203)
sukantoraymond Oct 8, 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
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 @@
"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 @@
}

nodeIDStr string
balance uint64
weight uint64
startTimeStr string
duration time.Duration
Expand All @@ -40,6 +45,9 @@
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 @@
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 @@
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)
felipemadero marked this conversation as resolved.
Show resolved Hide resolved
}

func CallAddValidator(
deployer *subnet.PublicDeployer,
network models.Network,
kc *keychain.Keychain,
useLedgerSetting bool,
blockchainName string,
nodeIDStrFormat string,
) error {
felipemadero marked this conversation as resolved.
Show resolved Hide resolved
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()

Check failure on line 195 in cmd/blockchaincmd/add_validator.go

View workflow job for this annotation

GitHub Actions / Lint

commentFormatting: put a space between `//` and comment text (gocritic)
//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 @@
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 @@
}
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 @@
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
Loading