Skip to content

Commit

Permalink
Merge branch 'acp-77' into acp-77-sdk-pos
Browse files Browse the repository at this point in the history
  • Loading branch information
arturrez committed Nov 15, 2024
2 parents 93277a3 + 92f4ad9 commit 4afb263
Show file tree
Hide file tree
Showing 36 changed files with 657 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-public-ami.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
aws-region: us-east-1

- name: Clean up old AMIs
run: npx aws-amicleaner --include-name 'public-avalanchecli-ubuntu-*' --exclude-newest 1 --exclude-days 2 --region="*" --force
run: npx aws-amicleaner --include-name 'public-avalanchecli-ubuntu-*' --exclude-newest 1 --region="*" --force
env:
AWS_REGION: us-east-1

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
version: 'v2.3.2'
args: release --clean
env:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.7
1.7.8
8 changes: 6 additions & 2 deletions cmd/blockchaincmd/add_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (
errMutuallyExclusiveWeightOptions = errors.New("--use-default-validator-params and --weight are mutually exclusive")
ErrNotPermissionedSubnet = errors.New("subnet is not permissioned")
aggregatorExtraEndpoints []string
clusterNameFlagValue string
)

// avalanche blockchain addValidator
Expand Down Expand Up @@ -141,6 +142,10 @@ func addValidator(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
if network.ClusterName != "" {
clusterNameFlagValue = network.ClusterName
network = models.ConvertClusterToNetwork(network)
}

fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.AddSubnetValidatorFee
kc, err := keychain.GetKeychainFromCmdLineFlags(
Expand Down Expand Up @@ -354,11 +359,10 @@ func CallAddValidator(
Addresses: disableOwnerAddrID,
}

extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints)
extraAggregatorPeers, err := GetAggregatorExtraPeers(clusterNameFlagValue, aggregatorExtraEndpoints)
if err != nil {
return err
}

signedMessage, validationID, err := validatormanager.InitValidatorRegistration(
app,
network,
Expand Down
51 changes: 27 additions & 24 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var (
avagoBinaryPath string
numBootstrapValidators int
numLocalNodes int
partialSync bool
changeOwnerAddress string
subnetOnly bool
icmSpec subnet.ICMSpec
Expand Down Expand Up @@ -167,6 +168,7 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().Uint8Var(&poSMaximumStakeMultiplier, "pos-maximum-stake-multiplier", 1, "maximum stake multiplier")
cmd.Flags().Uint64Var(&poSWeightToValueFactor, "pos-weight-to-value-factor", 1, "weight to value factor")

cmd.Flags().BoolVar(&partialSync, "partial-sync", true, "set primary network partial sync for new validators")
return cmd
}

Expand Down Expand Up @@ -401,7 +403,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

clusterNameFlagValue = globalNetworkFlags.ClusterName
isEVMGenesis, validationErr, err := app.HasSubnetEVMGenesis(chain)
if err != nil {
return err
Expand Down Expand Up @@ -464,7 +466,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
userProvidedAvagoVersion = avagoVersion
}

deployer := subnet.NewLocalDeployer(app, userProvidedAvagoVersion, avagoBinaryPath, vmBin)
deployer := subnet.NewLocalDeployer(app, userProvidedAvagoVersion, avagoBinaryPath, vmBin, true)
deployInfo, err := deployer.DeployToLocalNetwork(
chain,
genesisPath,
Expand Down Expand Up @@ -495,6 +497,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
deployInfo.ICMMessengerAddress,
deployInfo.ICMRegistryAddress,
nil,
clusterNameFlagValue,
); err != nil {
return err
}
Expand All @@ -504,8 +507,8 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
if sidecar.Sovereign {
if !generateNodeID {
clusterName := fmt.Sprintf("%s-local-node", blockchainName)
if globalNetworkFlags.ClusterName != "" {
clusterName = globalNetworkFlags.ClusterName
if clusterNameFlagValue != "" {
clusterName = clusterNameFlagValue
clusterConfig, err := app.GetClusterConfig(clusterName)
if err != nil {
return err
Expand All @@ -520,11 +523,11 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
"please create your local node again and call subnet deploy command again", err)
}
}
network = models.NewNetworkFromCluster(network, clusterName)
network = models.ConvertClusterToNetwork(network)
}
}
// ask user if we want to use local machine if cluster is not provided
if !useLocalMachine && globalNetworkFlags.ClusterName == "" {
if !useLocalMachine && clusterNameFlagValue == "" {
ux.Logger.PrintToUser("You can use your local machine as a bootstrap validator on the blockchain")
ux.Logger.PrintToUser("This means that you don't have to to set up a remote server on a cloud service (e.g. AWS / GCP) to be a validator on the blockchain.")

Expand All @@ -534,7 +537,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
}
// if no cluster provided - we create one with fmt.Sprintf("%s-local-node", blockchainName) name
if useLocalMachine && globalNetworkFlags.ClusterName == "" {
if useLocalMachine && clusterNameFlagValue == "" {
// stop local avalanchego process so that we can generate new local cluster
_ = node.StopLocalNode(app)
anrSettings := node.ANRSettings{}
Expand All @@ -549,14 +552,12 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
}
network = models.NewNetworkFromCluster(network, clusterName)
nodeConfig := ""
nodeConfig := map[string]interface{}{}
if app.AvagoNodeConfigExists(blockchainName) {
nodeConfigBytes, err := os.ReadFile(app.GetAvagoNodeConfigPath(blockchainName))
nodeConfig, err = utils.ReadJSON(app.GetAvagoNodeConfigPath(blockchainName))
if err != nil {
return err
}
nodeConfig = string(nodeConfigBytes)
}
// anrSettings, avagoVersionSettings, globalNetworkFlags are empty
if err = node.StartLocalNode(
Expand All @@ -565,6 +566,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
useEtnaDevnet,
avagoBinaryPath,
uint32(numLocalNodes),
partialSync,
nodeConfig,
anrSettings,
avagoVersionSettings,
Expand All @@ -573,6 +575,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
); err != nil {
return err
}
clusterNameFlagValue = clusterName
if len(bootstrapEndpoints) == 0 {
bootstrapEndpoints, err = getLocalBootstrapEndpoints()
if err != nil {
Expand Down Expand Up @@ -610,11 +613,11 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
ChangeOwnerAddr: changeOwnerAddress,
})
}
case globalNetworkFlags.ClusterName != "":
case clusterNameFlagValue != "":
// for remote clusters we don't need to ask for bootstrap validators and can read it from filesystem
bootstrapValidators, err = getClusterBootstrapValidators(globalNetworkFlags.ClusterName, network)
bootstrapValidators, err = getClusterBootstrapValidators(clusterNameFlagValue, network)
if err != nil {
return fmt.Errorf("error getting bootstrap validators from cluster %s: %w", globalNetworkFlags.ClusterName, err)
return fmt.Errorf("error getting bootstrap validators from cluster %s: %w", clusterNameFlagValue, err)
}

default:
Expand Down Expand Up @@ -830,12 +833,12 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
}
fmt.Println()

if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", bootstrapValidators); err != nil {
if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", bootstrapValidators, clusterNameFlagValue); err != nil {
return err
}

if !convertOnly && !generateNodeID {
clusterName := network.ClusterName
clusterName := clusterNameFlagValue
if clusterName == "" {
clusterName, err = node.GetClusterNameFromList(app)
if err != nil {
Expand Down Expand Up @@ -886,7 +889,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
return err
}
evm.WaitForChainID(client)
extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints)
extraAggregatorPeers, err := GetAggregatorExtraPeers(clusterName, aggregatorExtraEndpoints)
if err != nil {
return err
}
Expand Down Expand Up @@ -952,7 +955,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
ux.Logger.PrintToUser("Once the Avalanche Node(s) are created and are tracking the blockchain, call `avalanche contract initPoaManager %s` to finish conversion to sovereign L1", blockchainName)
}
} else {
if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", nil); err != nil {
if err := app.UpdateSidecarNetworks(&sidecar, network, subnetID, blockchainID, "", "", nil, clusterNameFlagValue); err != nil {
return err
}
}
Expand Down Expand Up @@ -1285,7 +1288,7 @@ func ConvertURIToPeers(uris []string) ([]info.Peer, error) {
infoClient := info.NewClient(uri)
ctx, cancel := utils.GetAPILargeContext()
defer cancel()
peers, err := infoClient.Peers(ctx)
peers, err := infoClient.Peers(ctx, nil)
if err != nil {
return nil, err
}
Expand All @@ -1300,10 +1303,10 @@ func ConvertURIToPeers(uris []string) ([]info.Peer, error) {
}

func GetAggregatorExtraPeers(
network models.Network,
clusterName string,
extraURIs []string,
) ([]info.Peer, error) {
uris, err := GetAggregatorNetworkUris(network)
uris, err := GetAggregatorNetworkUris(clusterName)
if err != nil {
return nil, err
}
Expand All @@ -1313,14 +1316,14 @@ func GetAggregatorExtraPeers(
return ConvertURIToPeers(uris)
}

func GetAggregatorNetworkUris(network models.Network) ([]string, error) {
func GetAggregatorNetworkUris(clusterName string) ([]string, error) {
aggregatorExtraPeerEndpointsUris := []string{}
if network.ClusterName != "" {
if clusterName != "" {
clustersConfig, err := app.LoadClustersConfig()
if err != nil {
return nil, err
}
clusterConfig := clustersConfig.Clusters[network.ClusterName]
clusterConfig := clustersConfig.Clusters[clusterName]
if clusterConfig.Local {
cli, err := binutils.NewGRPCClientWithEndpoint(
binutils.LocalClusterGRPCServerEndpoint,
Expand Down
8 changes: 5 additions & 3 deletions cmd/blockchaincmd/remove_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func removeValidator(_ *cobra.Command, args []string) error {
if err != nil {
return err
}

if network.ClusterName != "" {
network = models.ConvertClusterToNetwork(network)
}
fee := network.GenesisParams().TxFeeConfig.StaticFeeConfig.TxFee
kc, err := keychain.GetKeychainFromCmdLineFlags(
app,
Expand Down Expand Up @@ -215,8 +217,8 @@ func removeValidatorSOV(
}
}
ux.Logger.PrintToUser(logging.Yellow.Wrap("RPC Endpoint: %s"), rpcURL)

extraAggregatorPeers, err := GetAggregatorExtraPeers(network, aggregatorExtraEndpoints)
clusterName := sc.Networks[network.Name()].ClusterName
extraAggregatorPeers, err := GetAggregatorExtraPeers(clusterName, aggregatorExtraEndpoints)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/contractcmd/init_poa_validator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ava-labs/avalanche-cli/cmd/blockchaincmd"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/contract"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
"github.com/ava-labs/avalanche-cli/pkg/prompts"
"github.com/ava-labs/avalanche-cli/pkg/ux"
Expand All @@ -31,6 +32,7 @@ var (
initPOAManagerSupportedNetworkOptions = []networkoptions.NetworkOption{
networkoptions.Local,
networkoptions.Devnet,
networkoptions.EtnaDevnet,
networkoptions.Fuji,
}
initPOAManagerFlags InitPOAManagerFlags
Expand Down Expand Up @@ -70,6 +72,9 @@ func initPOAManager(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
if network.ClusterName != "" {
network = models.ConvertClusterToNetwork(network)
}
if initPOAManagerFlags.rpcEndpoint == "" {
initPOAManagerFlags.rpcEndpoint, _, err = contract.GetBlockchainEndpoints(
app,
Expand Down Expand Up @@ -120,7 +125,8 @@ func initPOAManager(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
extraAggregatorPeers, err := blockchaincmd.GetAggregatorExtraPeers(network, initPOAManagerFlags.aggregatorExtraEndpoints)
clusterName := sc.Networks[network.Name()].ClusterName
extraAggregatorPeers, err := blockchaincmd.GetAggregatorExtraPeers(clusterName, initPOAManagerFlags.aggregatorExtraEndpoints)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/networkcmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func clean(*cobra.Command, []string) error {

configSingleNodeEnabled := app.Conf.GetConfigBoolValue(constants.ConfigSingleNodeEnabledKey)

if _, err := subnet.SetDefaultSnapshot(app.GetSnapshotsDir(), true, "", configSingleNodeEnabled); err != nil {
if _, err := subnet.SetDefaultSnapshot(app.GetSnapshotsDir(), true, true, "", configSingleNodeEnabled); err != nil {
app.Log.Warn("failed resetting default snapshot", zap.Error(err))
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/networkcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func StartNetwork(*cobra.Command, []string) error {
return err
}
}
sd := subnet.NewLocalDeployer(app, avagoVersion, avagoBinaryPath, "")
sd := subnet.NewLocalDeployer(app, avagoVersion, avagoBinaryPath, "", false)

if err := sd.StartServer(
constants.ServerRunFileLocalNetworkPrefix,
Expand Down
9 changes: 8 additions & 1 deletion cmd/nodecmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ will apply to all nodes in the cluster`,
cmd.Flags().StringArrayVar(&bootstrapIPs, "bootstrap-ips", []string{}, "IP:port pairs of bootstrap nodes")
cmd.Flags().StringVar(&genesisPath, "genesis", "", "path to genesis file")
cmd.Flags().StringVar(&upgradePath, "upgrade", "", "path to upgrade file")
cmd.Flags().BoolVar(&partialSync, "partial-sync", true, "primary network partial sync")
return cmd
}

Expand Down Expand Up @@ -231,6 +232,10 @@ func preCreateChecks(clusterName string) error {
return fmt.Errorf("invalid ip:port pair %s", ipPortPair)
}
}
if globalNetworkFlags.UseDevnet {
partialSync = false
ux.Logger.PrintToUser("disabling partial sync default for devnet")
}

return nil
}
Expand Down Expand Up @@ -790,10 +795,12 @@ func createNodes(cmd *cobra.Command, args []string) error {
avalancheGoVersion,
bootstrapIDs,
bootstrapIPs,
partialSync,
genesisPath,
upgradePath,
addMonitoring,
publicAccessToHTTPPort); err != nil {
publicAccessToHTTPPort,
); err != nil {
nodeResults.AddResult(host.NodeID, nil, err)
ux.SpinFailWithError(spinner, "", err)
return
Expand Down
10 changes: 7 additions & 3 deletions cmd/nodecmd/create_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func getAWSCloudConfig(awsProfile string, singleNode bool, clusterSgRegions []st
switch {
case len(numValidatorsNodes) != len(utils.Unique(cmdLineRegion)):
return nil, nil, nil, fmt.Errorf("number of nodes and regions should be the same")
case (globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji) && len(numAPINodes) != len(utils.Unique(cmdLineRegion)):
case (globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji) && len(numAPINodes) != 0 && len(numAPINodes) != len(utils.Unique(cmdLineRegion)):
return nil, nil, nil, fmt.Errorf("number of api nodes and regions should be the same")
case (globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji) && len(numAPINodes) != len(numValidatorsNodes):
case (globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji) && len(numAPINodes) != 0 && len(numAPINodes) != len(numValidatorsNodes):
return nil, nil, nil, fmt.Errorf("number of api nodes and validator nodes should be the same")
case len(cmdLineRegion) == 0 && len(numValidatorsNodes) == 0 && len(numAPINodes) == 0:
var err error
Expand All @@ -127,8 +127,12 @@ func getAWSCloudConfig(awsProfile string, singleNode bool, clusterSgRegions []st
}
default:
for i, region := range cmdLineRegion {
numAPINodesInRegion := 0
if len(numAPINodes) > 0 {
numAPINodesInRegion = numAPINodes[i]
}
if globalNetworkFlags.UseDevnet || globalNetworkFlags.UseFuji {
finalRegions[region] = NumNodes{numValidatorsNodes[i], numAPINodes[i]}
finalRegions[region] = NumNodes{numValidatorsNodes[i], numAPINodesInRegion}
} else {
finalRegions[region] = NumNodes{numValidatorsNodes[i], 0}
}
Expand Down
Loading

0 comments on commit 4afb263

Please sign in to comment.