Skip to content

Commit

Permalink
Merge branch 'main' into add-validator-local
Browse files Browse the repository at this point in the history
Signed-off-by: sukantoraymond <[email protected]>
  • Loading branch information
sukantoraymond authored Dec 5, 2024
2 parents 95af894 + b775332 commit 8bb5178
Show file tree
Hide file tree
Showing 42 changed files with 574 additions and 275 deletions.
22 changes: 12 additions & 10 deletions .github/ISSUE_TEMPLATE/feature_spec.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
---
name: Feature specification
name: Feature
about: Discussion on design and implementation of new features for the Avalanche CLI.
title: ''
labels: enhancement
assignees: ''

---

**Context and scope**
Include a short description of the context and scope of the suggested feature.
Include goals the change will accomplish if relevant.
## Goal

### Assumptions and Scope

## Example Usage

### Requirements:

### Current Limitations

**Discussion and alternatives**
Include a description of the changes to be made to the code along with alternatives that were considered.
### Nice to Have, but Not Required

**Open questions**
Questions that are still being discussed.
## Open Questions
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
1.8.0
23 changes: 18 additions & 5 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func addValidator(_ *cobra.Command, args []string) error {

if err := preAddChecks(network, sc.Sovereign); err != nil {
return err

if sc.Networks[network.Name()].ClusterName != "" {
clusterNameFlagValue = sc.Networks[network.Name()].ClusterName
}

fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee
Expand Down Expand Up @@ -319,7 +322,11 @@ func CallAddValidator(
return fmt.Errorf("failure parsing BLS info: %w", err)
}

expiry := uint64(time.Now().Add(constants.DefaultValidationIDExpiryDuration).Unix())
blockchainTimestamp, err := getBlockchainTimestamp(network)
if err != nil {
return fmt.Errorf("failed to get blockchain timestamp: %w", err)
}
expiry := uint64(blockchainTimestamp.Add(constants.DefaultValidationIDExpiryDuration).Unix())

chainSpec := contract.ChainSpec{
BlockchainName: blockchainName,
Expand Down Expand Up @@ -388,13 +395,13 @@ func CallAddValidator(
if err != nil {
return err
}
balanceAVAX, err := promptValidatorBalance(availableBalance)
balance, err = promptValidatorBalance(availableBalance)
if err != nil {
return err
}
// convert to nanoAVAX
balance = balanceAVAX * units.Avax
}
// convert to nanoAVAX
balance *= units.Avax

if remainingBalanceOwnerAddr == "" {
remainingBalanceOwnerAddr, err = getKeyForChangeOwner(network)
Expand Down Expand Up @@ -667,7 +674,6 @@ func getMaxValidationTime(network models.Network, nodeID ids.NodeID, startTime t
defer cancel()
platformCli := platformvm.NewClient(network.Endpoint)
vs, err := platformCli.GetCurrentValidators(ctx, avagoconstants.PrimaryNetworkID, nil)
cancel()
if err != nil {
return 0, err
}
Expand All @@ -679,6 +685,13 @@ func getMaxValidationTime(network models.Network, nodeID ids.NodeID, startTime t
return 0, errors.New("nodeID not found in validator set: " + nodeID.String())
}

func getBlockchainTimestamp(network models.Network) (time.Time, error) {

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

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (macos-14)

syntax error: unexpected getBlockchainTimestamp, expected (

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

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (ubuntu-22.04)

syntax error: unexpected getBlockchainTimestamp, expected (

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

View workflow job for this annotation

GitHub Actions / Lint

syntax error: unexpected getBlockchainTimestamp, expected (
ctx, cancel := utils.GetAPIContext()
defer cancel()
platformCli := platformvm.NewClient(network.Endpoint)
return platformCli.GetTimestamp(ctx)
}

func getTimeParameters(network models.Network, nodeID ids.NodeID, isValidator bool) (time.Time, time.Duration, error) {

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

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (macos-14)

syntax error: unexpected getTimeParameters, expected (

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

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (ubuntu-22.04)

syntax error: unexpected getTimeParameters, expected (

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

View workflow job for this annotation

GitHub Actions / Lint

syntax error: unexpected getTimeParameters, expected (
defaultStakingStartLeadTime := constants.StakingStartLeadTime
if network.Kind == models.Devnet {
Expand Down
31 changes: 31 additions & 0 deletions cmd/blockchaincmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"strings"
"unicode"

"github.com/ava-labs/avalanche-cli/pkg/key"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ethereum/go-ethereum/common"

"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 @@ -251,6 +255,12 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {

if vmType == models.SubnetEvm {
if sovereign {
// if validatorManagerOwner flag is used, we get the C Chain address of the key used
if createFlags.validatorManagerOwner != "" {
if err = validateValidatorManagerOwnerFlag(createFlags.validatorManagerOwner); err != nil {
return err
}
}
if createFlags.validatorManagerOwner == "" {
createFlags.validatorManagerOwner, err = getValidatorContractManagerAddr()
if err != nil {
Expand All @@ -262,6 +272,9 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {

// use the validator manager owner as the transparent proxy contract owner unless specified via cmd flag
if createFlags.proxyContractOwner != "" {
if err = validateValidatorManagerOwnerFlag(createFlags.proxyContractOwner); err != nil {
return err
}
sc.ProxyContractOwner = createFlags.proxyContractOwner
} else {
sc.ProxyContractOwner = sc.ValidatorManagerOwner
Expand Down Expand Up @@ -510,6 +523,24 @@ func sendMetrics(cmd *cobra.Command, repoName, blockchainName string) error {
return nil
}

func validateValidatorManagerOwnerFlag(input string) error {
// check that flag value is not P Chain or X Chain address
_, _, _, err := address.Parse(input)
if err == nil {
return fmt.Errorf("validator manager owner has to be EVM address (in 0x format)")
}
// if flag value is a key name, we get the C Chain address of the key and set it as the value of
// the validator manager address
if !common.IsHexAddress(input) {
k, err := key.LoadSoft(models.UndefinedNetwork.ID, app.GetKeyPath(input))
if err != nil {
return err
}
createFlags.validatorManagerOwner = k.C()
}
return nil
}

func checkInvalidSubnetNames(name string) error {
if name == "" {
return errEmptyBlockchainName
Expand Down
26 changes: 22 additions & 4 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,18 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().BoolVar(&icmSpec.SkipICMDeploy, "skip-local-teleporter", false, "skip automatic teleporter deploy on local networks [to be deprecated]")
cmd.Flags().BoolVar(&icmSpec.SkipICMDeploy, "skip-teleporter-deploy", false, "skip automatic teleporter deploy")
cmd.Flags().BoolVar(&icmSpec.SkipRelayerDeploy, skipRelayerFlagName, false, "skip relayer deploy")
cmd.Flags().StringVar(&icmSpec.ICMVersion, "teleporter-version", "latest", "teleporter version to deploy")
cmd.Flags().StringVar(&icmSpec.RelayerVersion, "relayer-version", "latest", "relayer version to deploy")
cmd.Flags().StringVar(
&icmSpec.ICMVersion,
"teleporter-version",
constants.LatestReleaseVersionTag,
"teleporter version to deploy",
)
cmd.Flags().StringVar(
&icmSpec.RelayerVersion,
"relayer-version",
constants.LatestPreReleaseVersionTag,
"relayer version to deploy",
)
cmd.Flags().StringVar(&icmSpec.RelayerBinPath, "relayer-path", "", "relayer binary to use")
cmd.Flags().StringVar(&icmSpec.RelayerLogLevel, "relayer-log-level", "info", "log level to be used for relayer logs")
cmd.Flags().Float64Var(&relayerAmount, "relayer-amount", 0, "automatically fund relayer fee payments with the given amount")
Expand All @@ -182,7 +192,7 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().StringSliceVar(&aggregatorExtraEndpoints, "aggregator-extra-endpoints", nil, "endpoints for extra nodes that are needed in signature aggregation")
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().IntVar(&numLocalNodes, "num-local-nodes", 1, "number of nodes to be created on local machine")
cmd.Flags().IntVar(&numLocalNodes, "num-local-nodes", 0, "number of nodes to be created on local machine")
cmd.Flags().StringVar(&changeOwnerAddress, "change-owner-address", "", "address that will receive change if node is no longer L1 validator")

cmd.Flags().Uint64Var(&poSMinimumStakeAmount, "pos-minimum-stake-amount", 1, "minimum stake amount")
Expand Down Expand Up @@ -616,6 +626,9 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
network = models.ConvertClusterToNetwork(network)
}
}
if numLocalNodes > 0 {
useLocalMachine = true
}
// ask user if we want to use local machine if cluster is not provided
if network.Kind != models.Local && !useLocalMachine && clusterNameFlagValue == "" {
ux.Logger.PrintToUser("You can use your local machine as a bootstrap validator on the blockchain")
Expand All @@ -626,6 +639,11 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
}
// default number of local machine nodes to be 1
// we set it here instead of at flag level so that we don't prompt if user wants to use local machine when they set numLocalNodes flag value
if useLocalMachine && numLocalNodes == 0 {
numLocalNodes = constants.DefaultNumberOfLocalMachineNodes
}
// if no cluster provided - we create one with fmt.Sprintf("%s-local-node", blockchainName) name
if useLocalMachine && clusterNameFlagValue == "" {
// stop local avalanchego process so that we can generate new local cluster
Expand Down Expand Up @@ -1123,7 +1141,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
Amount: relayerAmount,
}
if network.Kind == models.Local || useLocalMachine {
deployRelayerFlags.Key = constants.AWMRelayerKeyName
deployRelayerFlags.Key = constants.ICMRelayerKeyName
deployRelayerFlags.Amount = constants.DefaultRelayerAmount
deployRelayerFlags.BlockchainFundingKey = constants.ICMKeyName
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/interchaincmd/relayercmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,17 @@ func CallDeploy(_ []string, flags DeployFlags, network models.Network) error {
configPath := app.GetLocalRelayerConfigPath(network.Kind, localNetworkRootDir)
logPath := app.GetLocalRelayerLogPath(network.Kind)

metricsPort := constants.RemoteAWMRelayerMetricsPort
metricsPort := constants.RemoteICMRelayerMetricsPort
if !deployToRemote {
switch network.Kind {
case models.Local:
metricsPort = constants.LocalNetworkLocalAWMRelayerMetricsPort
metricsPort = constants.LocalNetworkLocalICMRelayerMetricsPort
case models.Devnet:
metricsPort = constants.DevnetLocalAWMRelayerMetricsPort
metricsPort = constants.DevnetLocalICMRelayerMetricsPort
case models.EtnaDevnet:
metricsPort = constants.EtnaDevnetLocalAWMRelayerMetricsPort
metricsPort = constants.EtnaDevnetLocalICMRelayerMetricsPort
case models.Fuji:
metricsPort = constants.FujiLocalAWMRelayerMetricsPort
metricsPort = constants.FujiLocalICMRelayerMetricsPort
}
}

Expand Down Expand Up @@ -466,7 +466,7 @@ func CallDeploy(_ []string, flags DeployFlags, network models.Network) error {
binPath, err := teleporter.DeployRelayer(
flags.Version,
flags.BinPath,
app.GetAWMRelayerBinDir(),
app.GetICMRelayerBinDir(),
configPath,
logPath,
runFilePath,
Expand Down
6 changes: 3 additions & 3 deletions cmd/interchaincmd/relayercmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func start(_ *cobra.Command, _ []string) error {
}
switch {
case network.ClusterName != "":
host, err := node.GetAWMRelayerHost(app, network.ClusterName)
host, err := node.GetICMRelayerHost(app, network.ClusterName)
if err != nil {
return err
}
if err := ssh.RunSSHStartAWMRelayerService(host); err != nil {
if err := ssh.RunSSHStartICMRelayerService(host); err != nil {
return err
}
ux.Logger.GreenCheckmarkToUser("Remote AWM Relayer on %s successfully started", host.GetCloudID())
Expand Down Expand Up @@ -95,7 +95,7 @@ func start(_ *cobra.Command, _ []string) error {
} else if binPath, err := teleporter.DeployRelayer(
"latest",
binPath,
app.GetAWMRelayerBinDir(),
app.GetICMRelayerBinDir(),
relayerConfigPath,
app.GetLocalRelayerLogPath(network.Kind),
app.GetLocalRelayerRunPath(network.Kind),
Expand Down
4 changes: 2 additions & 2 deletions cmd/interchaincmd/relayercmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func stop(_ *cobra.Command, _ []string) error {
}
switch {
case network.ClusterName != "":
host, err := node.GetAWMRelayerHost(app, network.ClusterName)
host, err := node.GetICMRelayerHost(app, network.ClusterName)
if err != nil {
return err
}
if err := ssh.RunSSHStopAWMRelayerService(host); err != nil {
if err := ssh.RunSSHStopICMRelayerService(host); err != nil {
return err
}
ux.Logger.GreenCheckmarkToUser("Remote AWM Relayer on %s successfully stopped", host.GetCloudID())
Expand Down
2 changes: 1 addition & 1 deletion cmd/networkcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func Start(flags StartFlags, printEndpoints bool) error {
if relayerBinPath, err := teleporter.DeployRelayer(
"latest",
relayerBinPath,
app.GetAWMRelayerBinDir(),
app.GetICMRelayerBinDir(),
relayerConfigPath,
app.GetLocalRelayerLogPath(models.Local),
app.GetLocalRelayerRunPath(models.Local),
Expand Down
2 changes: 1 addition & 1 deletion cmd/nodecmd/create_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func grantAccessToPublicIPViaFirewall(gcpClient *gcpAPI.GcpCloud, projectName st
return nil
}

func setGCPAWMRelayerSecurityGroupRule(awmRelayerHost *models.Host) error {
func setGCPICMRelayerSecurityGroupRule(awmRelayerHost *models.Host) error {
gcpClient, _, _, _, projectName, err := getGCPConfig(true)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 8bb5178

Please sign in to comment.