Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c670c7
grouped flags
sukantoraymond Apr 24, 2025
d96b225
generalized grouped flags
sukantoraymond Apr 24, 2025
0bd96a2
lint
sukantoraymond Apr 24, 2025
1ee9561
lint
sukantoraymond Apr 24, 2025
7b73aec
lint
sukantoraymond Apr 25, 2025
b898179
flag groups
sukantoraymond Apr 25, 2025
816380e
lint
sukantoraymond Apr 25, 2025
d24de4c
dont show grouped flags in general flags
sukantoraymond Apr 28, 2025
3f8fc81
abstract functions
sukantoraymond Apr 28, 2025
40afac4
remove duplicate flags in deploy
sukantoraymond Apr 28, 2025
b830e08
More blockchain deploy groups
sukantoraymond Apr 28, 2025
5564014
update label
sukantoraymond Apr 28, 2025
1de5edc
Merge branch 'main' into grouped-flags
sukantoraymond May 1, 2025
6d4d9ec
lint
sukantoraymond May 1, 2025
6aea5a8
Merge branch 'main' into grouped-flags
sukantoraymond May 1, 2025
8a9848e
Merge branch 'main' into more-groups
sukantoraymond May 1, 2025
a40e0e4
remove duplicate flags (#2773)
sukantoraymond May 1, 2025
6cc12f7
Revert "remove duplicate flags (#2773)" (#2785)
sukantoraymond May 1, 2025
656d0ba
Merge branch 'main' into grouped-flags
sukantoraymond May 8, 2025
53b5c27
Merge branch 'grouped-flags' into remove-duplicate-flags
sukantoraymond May 8, 2025
1c501a1
Merge branch 'remove-duplicate-flags' into more-groups
sukantoraymond May 8, 2025
aa45433
sig agg flags
sukantoraymond May 8, 2025
11ce243
sig agg flag grouping
sukantoraymond May 9, 2025
f2ff62e
lint
sukantoraymond May 12, 2025
055e988
lint
sukantoraymond May 12, 2025
9f9552a
Merge branch 'main' into sig-agg-groups
sukantoraymond May 12, 2025
dff4d2e
lint
sukantoraymond May 12, 2025
a6634fa
lint
sukantoraymond May 12, 2025
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
8 changes: 4 additions & 4 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ staking token. Both processes will issue a RegisterL1ValidatorTx on the P-Chain.

This command currently only works on Blockchains deployed to either the Fuji
Testnet or Mainnet.`,
RunE: addValidator,
Args: cobrautils.MaximumNArgs(1),
RunE: addValidator,
PreRunE: cobrautils.MaximumNArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, networkoptions.DefaultSupportedNetworkOptions)
flags.AddRPCFlagToCmd(cmd, app, &addValidatorFlags.RPC)
flags.AddSignatureAggregatorFlagsToCmd(cmd, &addValidatorFlags.SigAggFlags)
sigAggGroup := flags.AddSignatureAggregatorFlagsToCmd(cmd, &addValidatorFlags.SigAggFlags)
cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet only]")
cmd.Flags().Float64Var(
&balanceAVAX,
Expand Down Expand Up @@ -131,7 +131,7 @@ Testnet or Mainnet.`,
cmd.Flags().StringVar(&initiateTxHash, "initiate-tx-hash", "", "initiate tx is already issued, with the given hash")
cmd.Flags().Uint32Var(&httpPort, "http-port", 0, "http port for node")
cmd.Flags().Uint32Var(&stakingPort, "staking-port", 0, "staking port for node")

cmd.SetHelpFunc(flags.WithGroupedHelp([]flags.GroupedFlags{sigAggGroup}))
return cmd
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/blockchaincmd/change_weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func newChangeWeightCmd() *cobra.Command {
Long: `The blockchain changeWeight command changes the weight of a L1 Validator.

The L1 has to be a Proof of Authority L1.`,
RunE: setWeight,
Args: cobrautils.ExactArgs(1),
RunE: setWeight,
PreRunE: cobrautils.ExactArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, networkoptions.DefaultSupportedNetworkOptions)
flags.AddRPCFlagToCmd(cmd, app, &changeWeightFlags.RPC)
flags.AddSignatureAggregatorFlagsToCmd(cmd, &changeWeightFlags.SigAggFlags)
sigAggGroup := flags.AddSignatureAggregatorFlagsToCmd(cmd, &changeWeightFlags.SigAggFlags)
cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet only]")
cmd.Flags().Uint64Var(&newWeight, "weight", 0, "set the new staking weight of the validator")
cmd.Flags().BoolVarP(&useEwoq, "ewoq", "e", false, "use ewoq key [fuji/devnet only]")
Expand All @@ -70,6 +70,7 @@ The L1 has to be a Proof of Authority L1.`,
cmd.Flags().BoolVar(&externalValidatorManagerOwner, "external-evm-signature", false, "set this value to true when signing validator manager tx outside of cli (for multisig or ledger)")
cmd.Flags().StringVar(&validatorManagerOwner, "validator-manager-owner", "", "force using this address to issue transactions to the validator manager")
cmd.Flags().StringVar(&initiateTxHash, "initiate-tx-hash", "", "initiate tx is already issued, with the given hash")
cmd.SetHelpFunc(flags.WithGroupedHelp([]flags.GroupedFlags{sigAggGroup}))
return cmd
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/blockchaincmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ Sovereign L1s require bootstrap validators. avalanche blockchain convert command
- or using remote nodes (we require the node's Node-ID and BLS info)`,
RunE: convertBlockchain,
PersistentPostRun: handlePostRun,
Args: cobrautils.ExactArgs(1),
PreRunE: cobrautils.ExactArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, networkoptions.DefaultSupportedNetworkOptions)
flags.AddSignatureAggregatorFlagsToCmd(cmd, &convertFlags.SigAggFlags)
sigAggGroup := flags.AddSignatureAggregatorFlagsToCmd(cmd, &convertFlags.SigAggFlags)
cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet convert to l1 tx only]")
cmd.Flags().StringSliceVar(&subnetAuthKeys, "auth-keys", nil, "control keys that will be used to authenticate convert to L1 tx")
cmd.Flags().StringVar(&outputTxPath, "output-tx-path", "", "file path of the convert to L1 tx (for multi-sig)")
Expand Down Expand Up @@ -112,6 +112,7 @@ Sovereign L1s require bootstrap validators. avalanche blockchain convert command
cmd.Flags().Uint64Var(&createFlags.rewardBasisPoints, "reward-basis-points", 100, "(PoS only) reward basis points for PoS Reward Calculator")
cmd.Flags().StringVar(&validatorManagerAddress, "validator-manager-address", "", "validator manager address")
cmd.Flags().BoolVar(&doStrongInputChecks, "verify-input", true, "check for input confirmation")
cmd.SetHelpFunc(flags.WithGroupedHelp([]flags.GroupedFlags{sigAggGroup}))
return cmd
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ so you can take your locally tested Blockchain and deploy it on Fuji or Mainnet.
PreRunE: cobrautils.ExactArgs(1),
}
networkGroup := networkoptions.GetNetworkFlagsGroup(cmd, &globalNetworkFlags, true, networkoptions.DefaultSupportedNetworkOptions)
flags.AddSignatureAggregatorFlagsToCmd(cmd, &deployFlags.SigAggFlags)
sigAggGroup := flags.AddSignatureAggregatorFlagsToCmd(cmd, &deployFlags.SigAggFlags)

cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet deploy only]")
cmd.Flags().StringVar(&outputTxPath, "output-tx-path", "", "file path of the blockchain creation tx")
cmd.Flags().StringVar(&outputTxPath, "output-tx-path", "", "file path of the blockchain creation tx (for multi-sig signing)")
cmd.Flags().BoolVarP(&useEwoq, "ewoq", "e", false, "use ewoq key [local/devnet deploy only]")
cmd.Flags().BoolVarP(&useLedger, "ledger", "g", false, "use ledger instead of key")
cmd.Flags().StringSliceVar(&ledgerAddresses, "ledger-addrs", []string{}, "use the given ledger addresses")
Expand Down Expand Up @@ -225,7 +225,7 @@ so you can take your locally tested Blockchain and deploy it on Fuji or Mainnet.
set.Uint64Var(&poSWeightToValueFactor, "pos-weight-to-value-factor", 1, "weight to value factor")
})

cmd.SetHelpFunc(flags.WithGroupedHelp([]flags.GroupedFlags{networkGroup, bootstrapValidatorGroup, localMachineGroup, localNetworkGroup, nonSovGroup, icmGroup, posGroup}))
cmd.SetHelpFunc(flags.WithGroupedHelp([]flags.GroupedFlags{networkGroup, bootstrapValidatorGroup, localMachineGroup, localNetworkGroup, nonSovGroup, icmGroup, posGroup, sigAggGroup}))
return cmd
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/blockchaincmd/remove_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ validating your deployed Blockchain.

To remove the validator from the Subnet's allow list, provide the validator's unique NodeID. You can bypass
these prompts by providing the values with flags.`,
RunE: removeValidator,
Args: cobrautils.ExactArgs(1),
RunE: removeValidator,
PreRunE: cobrautils.ExactArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, false, networkoptions.DefaultSupportedNetworkOptions)
flags.AddRPCFlagToCmd(cmd, app, &removeValidatorFlags.RPC)
flags.AddSignatureAggregatorFlagsToCmd(cmd, &removeValidatorFlags.SigAggFlags)
sigAggGroup := flags.AddSignatureAggregatorFlagsToCmd(cmd, &removeValidatorFlags.SigAggFlags)
cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji deploy only]")
cmd.Flags().StringSliceVar(&subnetAuthKeys, "auth-keys", nil, "(for non-SOV blockchain only) control keys that will be used to authenticate the removeValidator tx")
cmd.Flags().StringVar(&outputTxPath, "output-tx-path", "", "(for non-SOV blockchain only) file path of the removeValidator tx")
Expand All @@ -74,6 +74,7 @@ these prompts by providing the values with flags.`,
cmd.Flags().BoolVar(&externalValidatorManagerOwner, "external-evm-signature", false, "set this value to true when signing validator manager tx outside of cli (for multisig or ledger)")
cmd.Flags().StringVar(&validatorManagerOwner, "validator-manager-owner", "", "force using this address to issue transactions to the validator manager")
cmd.Flags().StringVar(&initiateTxHash, "initiate-tx-hash", "", "initiate tx is already issued, with the given hash")
cmd.SetHelpFunc(flags.WithGroupedHelp([]flags.GroupedFlags{sigAggGroup}))
return cmd
}

Expand Down
13 changes: 7 additions & 6 deletions cmd/contractcmd/init_validator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ type ContractInitValidatorManagerFlags struct {
// avalanche contract initValidatorManager
func newInitValidatorManagerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "initValidatorManager blockchainName",
Short: "Initializes Proof of Authority(PoA) or Proof of Stake(PoS) Validator Manager on a given Network and Blockchain",
Long: "Initializes Proof of Authority(PoA) or Proof of Stake(PoS)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/icm-contracts/tree/main/contracts/validator-manager",
RunE: initValidatorManager,
Args: cobrautils.ExactArgs(1),
Use: "initValidatorManager blockchainName",
Short: "Initializes Proof of Authority(PoA) or Proof of Stake(PoS) Validator Manager on a given Network and Blockchain",
Long: "Initializes Proof of Authority(PoA) or Proof of Stake(PoS)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/icm-contracts/tree/main/contracts/validator-manager",
RunE: initValidatorManager,
PreRunE: cobrautils.ExactArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &network, true, networkoptions.DefaultSupportedNetworkOptions)
privateKeyFlags.AddToCmd(cmd, "as contract deployer")
flags.AddRPCFlagToCmd(cmd, app, &initValidatorManagerFlags.RPC)
flags.AddSignatureAggregatorFlagsToCmd(cmd, &initValidatorManagerFlags.SigAggFlags)
sigAggGroup := flags.AddSignatureAggregatorFlagsToCmd(cmd, &initValidatorManagerFlags.SigAggFlags)

cmd.Flags().StringVar(&initPOSManagerFlags.rewardCalculatorAddress, "pos-reward-calculator-address", "", "(PoS only) initialize the ValidatorManager with reward calculator address")
cmd.Flags().Uint64Var(&initPOSManagerFlags.minimumStakeAmount, "pos-minimum-stake-amount", 1, "(PoS only) minimum stake amount")
Expand All @@ -72,6 +72,7 @@ func newInitValidatorManagerCmd() *cobra.Command {
cmd.Flags().Uint16Var(&initPOSManagerFlags.minimumDelegationFee, "pos-minimum-delegation-fee", 1, "(PoS only) minimum delegation fee")
cmd.Flags().Uint8Var(&initPOSManagerFlags.maximumStakeMultiplier, "pos-maximum-stake-multiplier", 1, "(PoS only )maximum stake multiplier")
cmd.Flags().Uint64Var(&initPOSManagerFlags.weightToValueFactor, "pos-weight-to-value-factor", 1, "(PoS only) weight to value factor")
cmd.SetHelpFunc(flags.WithGroupedHelp([]flags.GroupedFlags{sigAggGroup}))
return cmd
}

Expand Down
35 changes: 19 additions & 16 deletions cmd/flags/signature_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package flags
import (
"fmt"

"github.com/spf13/pflag"

"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,24 +40,25 @@ func validateSignatureAggregatorFlags(sigAggFlags SignatureAggregatorFlags) erro
return nil
}

func AddSignatureAggregatorFlagsToCmd(cmd *cobra.Command, sigAggFlags *SignatureAggregatorFlags) {
cmd.Flags().StringVar(&sigAggFlags.AggregatorLogLevel, aggregatorLogLevelFlag, constants.DefaultAggregatorLogLevel, "log level to use with signature aggregator")
sigAggPreRun := func(_ *cobra.Command, _ []string) error {
if err := validateSignatureAggregatorFlags(*sigAggFlags); err != nil {
return err
}
return nil
}

existingPreRunE := cmd.PreRunE
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if existingPreRunE != nil {
if err := existingPreRunE(cmd, args); err != nil {
func AddSignatureAggregatorFlagsToCmd(cmd *cobra.Command, sigAggFlags *SignatureAggregatorFlags) GroupedFlags {
return RegisterFlagGroup(cmd, "Signature Aggregator Flags", "show-signature-aggregator-flags", false, func(set *pflag.FlagSet) {
set.StringVar(&sigAggFlags.AggregatorLogLevel, aggregatorLogLevelFlag, constants.DefaultAggregatorLogLevel, "log level to use with signature aggregator")
sigAggPreRun := func(_ *cobra.Command, _ []string) error {
if err := validateSignatureAggregatorFlags(*sigAggFlags); err != nil {
return err
}
return nil
}
return sigAggPreRun(cmd, args)
}

cmd.Flags().BoolVar(&sigAggFlags.AggregatorLogToStdout, aggregatorLogToStdoutFlag, false, "use stdout for signature aggregator logs")
existingPreRunE := cmd.PreRunE
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if existingPreRunE != nil {
if err := existingPreRunE(cmd, args); err != nil {
return err
}
}
return sigAggPreRun(cmd, args)
}
set.BoolVar(&sigAggFlags.AggregatorLogToStdout, aggregatorLogToStdoutFlag, false, "use stdout for signature aggregator logs")
})
}
8 changes: 4 additions & 4 deletions cmd/nodecmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ func newLocalValidateCmd() *cobra.Command {
RPC URL of the L1.

This command can only be used to validate Proof of Stake L1.`,
Args: cobra.ExactArgs(1),
RunE: localValidate,
RunE: localValidate,
PreRunE: cobra.ExactArgs(1),
}
flags.AddRPCFlagToCmd(cmd, app, &localValidateFlags.RPC)
flags.AddSignatureAggregatorFlagsToCmd(cmd, &localValidateFlags.SigAggFlags)
sigAggGroup := flags.AddSignatureAggregatorFlagsToCmd(cmd, &localValidateFlags.SigAggFlags)
cmd.Flags().StringVar(&blockchainName, "l1", "", "specify the blockchain the node is syncing with")
cmd.Flags().StringVar(&blockchainName, "blockchain", "", "specify the blockchain the node is syncing with")
cmd.Flags().Uint64Var(&stakeAmount, "stake-amount", 0, "amount of tokens to stake")
Expand All @@ -378,7 +378,7 @@ This command can only be used to validate Proof of Stake L1.`,
cmd.Flags().Uint64Var(&minimumStakeDuration, "minimum-stake-duration", constants.PoSL1MinimumStakeDurationSeconds, "minimum stake duration (in seconds)")
cmd.Flags().StringVar(&validatorManagerAddress, "validator-manager-address", "", "validator manager address")
cmd.Flags().BoolVar(&useACP99, "acp99", true, "use ACP99 contracts instead of v1.0.0 for validator managers")

cmd.SetHelpFunc(flags.WithGroupedHelp([]flags.GroupedFlags{sigAggGroup}))
return cmd
}

Expand Down
43 changes: 31 additions & 12 deletions pkg/cobrautils/cobra_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@
return fmt.Sprintf("Usage error: %s", e.err)
}

func ErrWrongArgCount(expected, got int) error {
return fmt.Errorf("requires %d arg(s), received %d args(s)", expected, got)
}

func ErrMaxArgCount(expected, got int) error {
return fmt.Errorf("max %d arg(s), received %d args(s)", expected, got)
}

func ErrMinArgCount(expected, got int) error {
return fmt.Errorf("min %d arg(s), received %d args(s)", expected, got)
}

func ErrRangeArgCount(expectedLow, expectedHigh, got int) error {
return fmt.Errorf("accepted number of arg(s) is %d to %d, received %d args(s)", expectedLow, expectedHigh, got)
}

func NewUsageError(cmd *cobra.Command, err error) UsageError {
return UsageError{
cmd: cmd,
Expand All @@ -43,31 +59,34 @@

func MaximumNArgs(n int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
err := cobra.MaximumNArgs(n)(cmd, args)
if err != nil {
err = NewUsageError(cmd, err)
if len(args) > n {
_ = cmd.Help() // show full help with flag grouping
fmt.Println("")

Check failure on line 64 in pkg/cobrautils/cobra_utils.go

View workflow job for this annotation

GitHub Actions / Lint

File is not properly formatted (gofmt)
return ErrMaxArgCount(n, len(args))
}
return err
return nil
}
}

func MinimumNArgs(n int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
err := cobra.MinimumNArgs(n)(cmd, args)
if err != nil {
err = NewUsageError(cmd, err)
if len(args) < n {
_ = cmd.Help() // show full help with flag grouping
fmt.Println("")
return ErrMinArgCount(n, len(args))
}
return err
return nil
}
}

func RangeArgs(min int, max int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
err := cobra.RangeArgs(min, max)(cmd, args)
if err != nil {
err = NewUsageError(cmd, err)
if len(args) < min || len(args) > max {
_ = cmd.Help() // show full help with flag grouping
fmt.Println("")
return ErrRangeArgCount(min, max, len(args))
}
return err
return nil
}
}

Expand Down
Loading