Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
74082f2
validator manager flags
sukantoraymond Mar 17, 2025
8c8d665
validator manager flags
sukantoraymond Mar 17, 2025
96d874c
lint
sukantoraymond Mar 17, 2025
aaca645
lint
sukantoraymond Mar 17, 2025
0bd0dbe
logs
sukantoraymond Mar 18, 2025
6138faa
logs
sukantoraymond Mar 18, 2025
4ddcc73
fixed bug
sukantoraymond Mar 18, 2025
09520e3
lint
sukantoraymond Mar 18, 2025
9b37e4b
lint
sukantoraymond Mar 18, 2025
02d80b4
rename rpc
sukantoraymond Mar 18, 2025
de14ae6
remove private ip sig agg
sukantoraymond Mar 18, 2025
b3aceaf
fix test
sukantoraymond Mar 18, 2025
db5a674
fix bug
sukantoraymond Mar 18, 2025
a5d6789
lint
sukantoraymond Mar 18, 2025
7902334
node local
sukantoraymond Mar 18, 2025
225bb19
separate rpc
sukantoraymond Mar 19, 2025
3a31816
unify var
sukantoraymond Mar 19, 2025
217a03e
add validation input check
sukantoraymond Mar 20, 2025
5befbb6
lint
sukantoraymond Mar 20, 2025
9782ca1
lint
sukantoraymond Mar 20, 2025
d523864
chain pre run validation
sukantoraymond Mar 25, 2025
ac6ee98
Merge branch 'main' into validator-manager-falgs
sukantoraymond Mar 27, 2025
8334125
fix merge
sukantoraymond Mar 27, 2025
e377c10
update validate rpc
sukantoraymond Mar 27, 2025
c09efdc
fix validate rpc
sukantoraymond Mar 27, 2025
143512e
add test case for rpc validation
sukantoraymond Mar 27, 2025
631591c
lint
sukantoraymond Mar 27, 2025
0b23ce4
lint
sukantoraymond Mar 27, 2025
9c03b43
lint
sukantoraymond Mar 27, 2025
d1ab0ea
lint
sukantoraymond Mar 27, 2025
aac4455
update sig agg flags
sukantoraymond Apr 8, 2025
bcd19e3
update rpc flags
sukantoraymond Apr 8, 2025
4a3ce8a
Merge branch 'main' into validator-manager-falgs
sukantoraymond Apr 8, 2025
817ad66
Merge branch 'main' into validator-manager-falgs
sukantoraymond Apr 11, 2025
7daf566
fix ci
sukantoraymond Apr 11, 2025
b1436fa
update sig agg log
sukantoraymond Apr 14, 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
38 changes: 10 additions & 28 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strings"
"time"

"github.com/ava-labs/avalanche-cli/cmd/flags"

"github.com/ava-labs/avalanche-cli/pkg/blockchain"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
Expand Down Expand Up @@ -52,17 +54,12 @@ var (
pop string
remainingBalanceOwnerAddr string
disableOwnerAddr string
rpcURL string
aggregatorLogLevel string
aggregatorLogToStdout bool
delegationFee uint16
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")
errMutuallyExclusiveStartOptions = errors.New("--use-default-start-time/--use-default-validator-params and --start-time are mutually exclusive")
errMutuallyExclusiveWeightOptions = errors.New("--use-default-validator-params and --weight are mutually exclusive")
ErrNotPermissionedSubnet = errors.New("subnet is not permissioned")
aggregatorExtraEndpoints []string
aggregatorAllowPrivatePeers bool
clusterNameFlagValue string
createLocalValidator bool
externalValidatorManagerOwner bool
Expand Down Expand Up @@ -92,7 +89,8 @@ Testnet or Mainnet.`,
Args: cobrautils.MaximumNArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, networkoptions.DefaultSupportedNetworkOptions)

flags.AddRPCFlagToCmd(cmd, app)
flags.AddSignatureAggregatorFlagsToCmd(cmd)
cmd.Flags().StringVarP(&keyName, "key", "k", "", "select the key to use [fuji/devnet only]")
cmd.Flags().Float64Var(
&balanceAVAX,
Expand All @@ -111,11 +109,6 @@ Testnet or Mainnet.`,
cmd.Flags().BoolVar(&createLocalValidator, "create-local-validator", false, "create additional local validator and add it to existing running local node")
cmd.Flags().BoolVar(&partialSync, "partial-sync", true, "set primary network partial sync for new validators")
cmd.Flags().StringVar(&nodeEndpoint, "node-endpoint", "", "gather node id/bls from publicly available avalanchego apis on the given endpoint")
cmd.Flags().StringSliceVar(&aggregatorExtraEndpoints, "aggregator-extra-endpoints", nil, "endpoints for extra nodes that are needed in signature aggregation")
cmd.Flags().BoolVar(&aggregatorAllowPrivatePeers, "aggregator-allow-private-peers", true, "allow the signature aggregator to connect to peers with private IP")
cmd.Flags().StringVar(&rpcURL, "rpc", "", "connect to validator manager at the given rpc endpoint")
cmd.Flags().StringVar(&aggregatorLogLevel, "aggregator-log-level", constants.DefaultAggregatorLogLevel, "log level to use with signature aggregator")
cmd.Flags().BoolVar(&aggregatorLogToStdout, "aggregator-log-to-stdout", false, "use stdout for signature aggregator logs")
cmd.Flags().DurationVar(&duration, "staking-period", 0, "how long this validator will be staking")
cmd.Flags().BoolVar(&useDefaultStartTime, "default-start-time", false, "(for Subnets, not L1s) use default start time for subnet validator (5 minutes later for fuji & mainnet, 30 seconds later for devnet)")
cmd.Flags().StringVar(&startTimeStr, "start-time", "", "(for Subnets, not L1s) UTC start time when this validator starts validating, in 'YYYY-MM-DD HH:MM:SS' format")
Expand Down Expand Up @@ -186,13 +179,7 @@ func addValidator(cmd *cobra.Command, args []string) error {
}

if len(args) == 0 {
if rpcURL == "" {
rpcURL, err = app.Prompt.CaptureURL("What is the RPC endpoint?", false)
if err != nil {
return err
}
}
sc, err = importL1(blockchainIDStr, rpcURL, network)
sc, err = importL1(blockchainIDStr, flags.RPC, network)
if err != nil {
return err
}
Expand Down Expand Up @@ -293,8 +280,6 @@ func addValidator(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
// make sure extra validator endpoint added for the new node
aggregatorExtraEndpoints = append(aggregatorExtraEndpoints, constants.LocalAPIEndpoint)
}

if nodeIDStr == "" {
Expand Down Expand Up @@ -340,6 +325,7 @@ func addValidator(cmd *cobra.Command, args []string) error {
remainingBalanceOwnerAddr,
disableOwnerAddr,
sc,
flags.RPC,
); err != nil {
return err
}
Expand Down Expand Up @@ -372,6 +358,7 @@ func CallAddValidator(
remainingBalanceOwnerAddr string,
disableOwnerAddr string,
sc models.Sidecar,
rpcURL string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of passing this and other global variables (flags in this case) to this function as arguments as opposed to just using them directly?

Copy link
Collaborator

@felipemadero felipemadero Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the goal is to be able to call this command from another command, and pass to it only the needed values. this concept is best represented in the tokentransferrer deploy cmd, here the implementation is partial.
secondary goal is to avoid using global variables at all: refactoring of common code, and different dev styles, showed that the risk to use/set global variables among several functions is possible and happens, so, to avoid secondary effects, and difficultty to understand the code, it is best to just not use them.

) error {
nodeID, err := ids.NodeIDFromString(nodeIDStr)
if err != nil {
Expand Down Expand Up @@ -514,18 +501,15 @@ func CallAddValidator(
Threshold: 1,
Addresses: disableOwnerAddrID,
}

extraAggregatorPeers, err := blockchain.GetAggregatorExtraPeers(app, clusterNameFlagValue, aggregatorExtraEndpoints)
extraAggregatorPeers, err := blockchain.GetAggregatorExtraPeers(app, clusterNameFlagValue)
if err != nil {
return err
}
aggregatorLogger, err := utils.NewLogger(
constants.SignatureAggregatorLogName,
aggregatorLogLevel,
constants.DefaultAggregatorLogLevel,
flags.SigAggFlags.AggregatorLogLevel,
flags.SigAggFlags.AggregatorLogToStdout,
app.GetAggregatorLogDir(clusterNameFlagValue),
aggregatorLogToStdout,
ux.Logger.PrintToUser,
)
if err != nil {
return err
Expand All @@ -548,7 +532,6 @@ func CallAddValidator(
disableOwners,
weight,
extraAggregatorPeers,
aggregatorAllowPrivatePeers,
aggregatorLogger,
pos,
delegationFee,
Expand Down Expand Up @@ -593,7 +576,6 @@ func CallAddValidator(
ownerPrivateKey,
validationID,
extraAggregatorPeers,
aggregatorAllowPrivatePeers,
aggregatorLogger,
validatorManagerAddress,
)
Expand Down
34 changes: 15 additions & 19 deletions cmd/blockchaincmd/change_weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"strings"

"github.com/ava-labs/avalanche-cli/cmd/flags"

"github.com/ava-labs/avalanche-cli/pkg/blockchain"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
Expand Down Expand Up @@ -50,7 +52,8 @@ The L1 has to be a Proof of Authority L1.`,
Args: cobrautils.ExactArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, networkoptions.DefaultSupportedNetworkOptions)

flags.AddRPCFlagToCmd(cmd, app)
flags.AddSignatureAggregatorFlagsToCmd(cmd)
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 @@ -60,11 +63,6 @@ The L1 has to be a Proof of Authority L1.`,
cmd.Flags().StringSliceVar(&ledgerAddresses, "ledger-addrs", []string{}, "use the given ledger addresses")
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().StringSliceVar(&aggregatorExtraEndpoints, "aggregator-extra-endpoints", nil, "endpoints for extra nodes that are needed in signature aggregation")
cmd.Flags().BoolVar(&aggregatorAllowPrivatePeers, "aggregator-allow-private-peers", true, "allow the signature aggregator to connect to peers with private IP")
cmd.Flags().StringVar(&aggregatorLogLevel, "aggregator-log-level", constants.DefaultAggregatorLogLevel, "log level to use with signature aggregator")
cmd.Flags().BoolVar(&aggregatorLogToStdout, "aggregator-log-to-stdout", false, "use stdout for signature aggregator logs")
cmd.Flags().StringVar(&rpcURL, "rpc", "", "connect to validator manager at the given rpc endpoint")
cmd.Flags().StringVar(&initiateTxHash, "initiate-tx-hash", "", "initiate tx is already issued, with the given hash")
return cmd
}
Expand Down Expand Up @@ -150,8 +148,8 @@ func setWeight(_ *cobra.Command, args []string) error {
BlockchainName: blockchainName,
}

if rpcURL == "" {
rpcURL, _, err = contract.GetBlockchainEndpoints(
if flags.RPC == "" {
flags.RPC, _, err = contract.GetBlockchainEndpoints(
app,
network,
chainSpec,
Expand All @@ -166,7 +164,7 @@ func setWeight(_ *cobra.Command, args []string) error {
return fmt.Errorf("unable to find Validator Manager address")
}
validatorManagerAddress = sc.Networks[network.Name()].ValidatorManagerAddress
validationID, err := validator.GetValidationID(rpcURL, common.HexToAddress(validatorManagerAddress), nodeID)
validationID, err := validator.GetValidationID(flags.RPC, common.HexToAddress(validatorManagerAddress), nodeID)
if err != nil {
return err
}
Expand Down Expand Up @@ -274,6 +272,7 @@ func setWeight(_ *cobra.Command, args []string) error {
0, // automatic uptime
isBootstrapValidatorForNetwork(nodeID, sc.Networks[network.Name()]),
false, // don't force
flags.RPC,
)
if err != nil {
return err
Expand Down Expand Up @@ -304,6 +303,7 @@ func setWeight(_ *cobra.Command, args []string) error {
remainingBalanceOwnerAddr,
disableOwnerAddr,
sc,
flags.RPC,
)
}

Expand Down Expand Up @@ -350,20 +350,18 @@ func changeWeightACP99(
}
validatorManagerAddress = sc.Networks[network.Name()].ValidatorManagerAddress

ux.Logger.PrintToUser(logging.Yellow.Wrap("RPC Endpoint: %s"), rpcURL)
ux.Logger.PrintToUser(logging.Yellow.Wrap("RPC Endpoint: %s"), flags.RPC)

clusterName := sc.Networks[network.Name()].ClusterName
extraAggregatorPeers, err := blockchain.GetAggregatorExtraPeers(app, clusterName, aggregatorExtraEndpoints)
extraAggregatorPeers, err := blockchain.GetAggregatorExtraPeers(app, clusterName)
if err != nil {
return err
}
aggregatorLogger, err := utils.NewLogger(
constants.SignatureAggregatorLogName,
aggregatorLogLevel,
constants.DefaultAggregatorLogLevel,
flags.SigAggFlags.AggregatorLogLevel,
flags.SigAggFlags.AggregatorLogToStdout,
app.GetAggregatorLogDir(clusterName),
aggregatorLogToStdout,
ux.Logger.PrintToUser,
)
if err != nil {
return err
Expand All @@ -377,14 +375,13 @@ func changeWeightACP99(
ux.Logger.PrintToUser,
app,
network,
rpcURL,
flags.RPC,
chainSpec,
externalValidatorManagerOwner,
validatorManagerOwner,
ownerPrivateKey,
nodeID,
extraAggregatorPeers,
aggregatorAllowPrivatePeers,
aggregatorLogger,
validatorManagerAddress,
weight,
Expand Down Expand Up @@ -428,14 +425,13 @@ func changeWeightACP99(
aggregatorCtx,
app,
network,
rpcURL,
flags.RPC,
chainSpec,
externalValidatorManagerOwner,
validatorManagerOwner,
ownerPrivateKey,
validationID,
extraAggregatorPeers,
aggregatorAllowPrivatePeers,
aggregatorLogger,
validatorManagerAddress,
signedMessage,
Expand Down
19 changes: 8 additions & 11 deletions cmd/blockchaincmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

"github.com/ava-labs/avalanche-cli/cmd/flags"

"github.com/ava-labs/avalanche-cli/pkg/blockchain"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
Expand Down Expand Up @@ -59,6 +61,7 @@ Sovereign L1s require bootstrap validators. avalanche blockchain convert command
Args: cobrautils.ExactArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, networkoptions.DefaultSupportedNetworkOptions)
flags.AddSignatureAggregatorFlagsToCmd(cmd)
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 All @@ -69,10 +72,6 @@ Sovereign L1s require bootstrap validators. avalanche blockchain convert command
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)")
cmd.Flags().StringSliceVar(&bootstrapEndpoints, "bootstrap-endpoints", nil, "take validator node info from the given endpoints")
cmd.Flags().BoolVar(&convertOnly, "convert-only", false, "avoid node track, restart and poa manager setup")
cmd.Flags().StringVar(&aggregatorLogLevel, "aggregator-log-level", constants.DefaultAggregatorLogLevel, "log level to use with signature aggregator")
cmd.Flags().BoolVar(&aggregatorLogToStdout, "aggregator-log-to-stdout", false, "use stdout for signature aggregator logs")
cmd.Flags().StringSliceVar(&aggregatorExtraEndpoints, "aggregator-extra-endpoints", nil, "endpoints for extra nodes that are needed in signature aggregation")
cmd.Flags().BoolVar(&aggregatorAllowPrivatePeers, "aggregator-allow-private-peers", true, "allow the signature aggregator to connect to peers with private IP")
cmd.Flags().BoolVar(&useLocalMachine, "use-local-machine", false, "use local machine as a blockchain validator")
cmd.Flags().IntVar(&numBootstrapValidators, "num-bootstrap-validators", 0, "(only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)")
cmd.Flags().Float64Var(
Expand Down Expand Up @@ -268,6 +267,7 @@ func InitializeValidatorManager(
validatorManagerAddrStr string,
proxyContractOwner string,
useACP99 bool,
signatureAggregatorFlags flags.SignatureAggregatorFlags,
) (bool, error) {
if useACP99 {
ux.Logger.PrintToUser(logging.Yellow.Wrap("Validator Manager Protocol: ACP99"))
Expand Down Expand Up @@ -356,7 +356,7 @@ func InitializeValidatorManager(
}
}

extraAggregatorPeers, err := blockchain.GetAggregatorExtraPeers(app, clusterName, aggregatorExtraEndpoints)
extraAggregatorPeers, err := blockchain.GetAggregatorExtraPeers(app, clusterName)
if err != nil {
return tracked, err
}
Expand All @@ -371,11 +371,9 @@ func InitializeValidatorManager(
}
aggregatorLogger, err := utils.NewLogger(
constants.SignatureAggregatorLogName,
aggregatorLogLevel,
constants.DefaultAggregatorLogLevel,
signatureAggregatorFlags.AggregatorLogLevel,
signatureAggregatorFlags.AggregatorLogToStdout,
app.GetAggregatorLogDir(clusterName),
aggregatorLogToStdout,
ux.Logger.PrintToUser,
)
if err != nil {
return tracked, err
Expand All @@ -389,7 +387,6 @@ func InitializeValidatorManager(
network,
genesisPrivateKey,
extraAggregatorPeers,
aggregatorAllowPrivatePeers,
aggregatorLogger,
validatorManagerSDK.PoSParams{
MinimumStakeAmount: big.NewInt(int64(poSMinimumStakeAmount)),
Expand All @@ -413,7 +410,6 @@ func InitializeValidatorManager(
network,
genesisPrivateKey,
extraAggregatorPeers,
aggregatorAllowPrivatePeers,
aggregatorLogger,
validatorManagerAddrStr,
useACP99,
Expand Down Expand Up @@ -791,6 +787,7 @@ func convertBlockchain(_ *cobra.Command, args []string) error {
validatorManagerAddress,
sidecar.ProxyContractOwner,
sidecar.UseACP99,
flags.SigAggFlags,
); err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"

"github.com/ava-labs/avalanche-cli/cmd/flags"
"github.com/ava-labs/avalanche-cli/cmd/interchaincmd/messengercmd"
"github.com/ava-labs/avalanche-cli/cmd/interchaincmd/relayercmd"
"github.com/ava-labs/avalanche-cli/cmd/networkcmd"
Expand Down Expand Up @@ -118,6 +119,7 @@ so you can take your locally tested Blockchain and deploy it on Fuji or Mainnet.
Args: cobrautils.ExactArgs(1),
}
networkoptions.AddNetworkFlagsToCmd(cmd, &globalNetworkFlags, true, networkoptions.DefaultSupportedNetworkOptions)
flags.AddSignatureAggregatorFlagsToCmd(cmd)
cmd.Flags().StringVar(
&userProvidedAvagoVersion,
"avalanchego-version",
Expand Down Expand Up @@ -177,10 +179,6 @@ so you can take your locally tested Blockchain and deploy it on Fuji or Mainnet.
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)")
cmd.Flags().StringSliceVar(&bootstrapEndpoints, "bootstrap-endpoints", nil, "take validator node info from the given endpoints")
cmd.Flags().BoolVar(&convertOnly, "convert-only", false, "avoid node track, restart and poa manager setup")
cmd.Flags().StringVar(&aggregatorLogLevel, "aggregator-log-level", constants.DefaultAggregatorLogLevel, "log level to use with signature aggregator")
cmd.Flags().BoolVar(&aggregatorLogToStdout, "aggregator-log-to-stdout", false, "use stdout for signature aggregator logs")
cmd.Flags().StringSliceVar(&aggregatorExtraEndpoints, "aggregator-extra-endpoints", nil, "endpoints for extra nodes that are needed in signature aggregation")
cmd.Flags().BoolVar(&aggregatorAllowPrivatePeers, "aggregator-allow-private-peers", true, "allow the signature aggregator to connect to peers with private IP")
cmd.Flags().BoolVar(&useLocalMachine, "use-local-machine", false, "use local machine as a blockchain validator")
cmd.Flags().IntVar(&numBootstrapValidators, "num-bootstrap-validators", 0, "(only if --generate-node-id is true) number of bootstrap validators to set up in sovereign L1 validator)")
cmd.Flags().Float64Var(
Expand Down Expand Up @@ -829,6 +827,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
validatorManagerStr,
sidecar.ProxyContractOwner,
sidecar.UseACP99,
flags.SigAggFlags,
)
if err != nil {
return err
Expand Down
Loading
Loading