Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a03b3d9
control default latest version for avago and subnetevm
sukantoraymond Apr 7, 2025
1ecb4fe
add rpc to json
sukantoraymond Apr 7, 2025
1adf4a3
get latest cli version
sukantoraymond Apr 7, 2025
79a9cc2
update json model
sukantoraymond Apr 7, 2025
6cc37fc
update evm prompts
sukantoraymond Apr 8, 2025
079b182
update evm prompt
sukantoraymond Apr 8, 2025
16ff987
update avalanchego latest
sukantoraymond Apr 8, 2025
36ccd1e
add e2e test
sukantoraymond Apr 9, 2025
1556b85
remove unncessary file
sukantoraymond Apr 9, 2025
cbbfe9e
lint
sukantoraymond Apr 9, 2025
f56b137
try with lower versions
sukantoraymond Apr 10, 2025
5eba446
update how we get newest avago version
sukantoraymond Apr 10, 2025
9b8b529
Merge branch 'main' into control-default-version
sukantoraymond Apr 10, 2025
8dd666f
fix lint
sukantoraymond Apr 10, 2025
f864a75
address comments
sukantoraymond Apr 10, 2025
3bb41a4
add min version
sukantoraymond Apr 11, 2025
06789f6
fix ci
sukantoraymond Apr 11, 2025
70add0b
fix ci
sukantoraymond Apr 11, 2025
55dc686
add test for min version
sukantoraymond Apr 11, 2025
64e4ed6
update tests
sukantoraymond Apr 11, 2025
1b82986
fix lint
sukantoraymond Apr 11, 2025
bbd6742
Merge branch 'main' into control-default-version
sukantoraymond Apr 14, 2025
cb591a9
fix lint
sukantoraymond Apr 14, 2025
207182d
Merge branch 'control-default-version' into min-version
sukantoraymond Apr 14, 2025
f65345b
Merge branch 'main' into control-default-version
sukantoraymond Apr 29, 2025
7d8b016
lint
sukantoraymond Apr 29, 2025
5b90883
move to dependencies pkg
sukantoraymond Apr 29, 2025
afb4852
lint
sukantoraymond Apr 29, 2025
ffbd276
lint
sukantoraymond Apr 29, 2025
2d8bd77
Merge branch 'control-default-version' into min-version
sukantoraymond Apr 29, 2025
4b45bff
lint
sukantoraymond Apr 29, 2025
f84e92d
Merge branch 'main' into min-version
sukantoraymond May 1, 2025
8d45f3e
fix merge
sukantoraymond May 1, 2025
6846f9a
address comments
sukantoraymond May 8, 2025
40deb5e
lint
sukantoraymond May 8, 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
3 changes: 3 additions & 0 deletions cmd/blockchaincmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ func StartLocalMachine(
avagoVersionSettings := dependencies.AvalancheGoVersionSettings{}
// setup (install if needed) avalanchego binary
avagoVersion := userProvidedAvagoVersion
if err = dependencies.CheckVersionIsOverMin(app, constants.AvalancheGoRepoName, network, userProvidedAvagoVersion); err != nil {
return false, err
}
if userProvidedAvagoVersion == constants.DefaultAvalancheGoVersion && avagoBinaryPath == "" {
// nothing given: get avago version from RPC compat using latest.json defined in
// https://raw.githubusercontent.com/ava-labs/avalanche-cli/control-default-version/versions/latest.json
Expand Down
2 changes: 0 additions & 2 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,7 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {

if network.Kind == models.Local {
app.Log.Debug("Deploy local")

avagoVersion := userProvidedAvagoVersion

if avagoVersion == constants.DefaultAvalancheGoVersion && avagoBinaryPath == "" {
avagoVersion, err = dependencies.GetLatestCLISupportedDependencyVersion(app, constants.AvalancheGoRepoName, network, &sidecar.RPCVersion)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions cmd/nodecmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ will apply to all nodes in the cluster`,
// override postrun function from root.go, so that we don't double send metrics for the same command
func handlePostRun(_ *cobra.Command, _ []string) {}

func preCreateChecks(clusterName string) error {
func preCreateChecks(clusterName string, network models.Network) error {
if useCustomAvalanchegoVersion != "" || useAvalanchegoVersionFromSubnet != "" {
if useCustomAvalanchegoVersion != "" {
if err := dependencies.CheckVersionIsOverMin(app, constants.AvalancheGoRepoName, network, useCustomAvalanchegoVersion); err != nil {
return err
}
}
useLatestAvalanchegoReleaseVersion = false
useLatestAvalanchegoPreReleaseVersion = false
}
Expand Down Expand Up @@ -305,7 +310,7 @@ func createNodes(cmd *cobra.Command, args []string) error {
"",
)
setGlobalNetworkFlags(network)
if err := preCreateChecks(clusterName); err != nil {
if err := preCreateChecks(clusterName, network); err != nil {
return err
}
network = models.NewNetworkFromCluster(network, clusterName)
Expand Down
4 changes: 4 additions & 0 deletions cmd/nodecmd/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ func localStartNode(_ *cobra.Command, args []string) error {
}

if useCustomAvalanchegoVersion != "" {
// TODO: we'll have to refactor all these when we consolidate input and flag handling for dependency versioning
if err = dependencies.CheckVersionIsOverMin(app, constants.AvalancheGoRepoName, network, useCustomAvalanchegoVersion); err != nil {
return err
}
latestAvagoPreReleaseVersion = false
latestAvagoReleaseVersion = false
}
Expand Down
40 changes: 40 additions & 0 deletions pkg/dependencies/min_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package dependencies

import (
"encoding/json"
"fmt"

"golang.org/x/mod/semver"

"github.com/ava-labs/avalanche-cli/pkg/models"

"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/constants"
)

func CheckVersionIsOverMin(app *application.Avalanche, dependencyName string, network models.Network, version string) error {
dependencyBytes, err := app.Downloader.Download(constants.CLILatestDependencyURL)
if err != nil {
return err
}

var parsedDependency models.CLIDependencyMap
if err = json.Unmarshal(dependencyBytes, &parsedDependency); err != nil {
return err
}

switch dependencyName {
case constants.AvalancheGoRepoName:
// version has to be at least higher than minimum version specified for the dependency
minVersion := parsedDependency.AvalancheGo[network.Name()].MinimumVersion
versionComparison := semver.Compare(version, minVersion)
if versionComparison == -1 {
return fmt.Errorf("minimum version of %s that is supported by CLI is %s, current version provided is %s", dependencyName, minVersion, version)
}
return nil
default:
return fmt.Errorf("minimum version check is unsupported %s dependency", dependencyName)
}
}
96 changes: 96 additions & 0 deletions pkg/dependencies/min_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package dependencies

import (
"testing"

"github.com/ava-labs/avalanche-cli/internal/mocks"
"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

var testCLIMinVersion = []byte(`{"subnet-evm":"v0.7.3","rpc":39,"avalanchego":{"Local Network":{"latest-version":"v1.13.0", "minimum-version":""},"DevNet":{"latest-version":"v1.13.0", "minimum-version":""},"Fuji":{"latest-version":"v1.13.0", "minimum-version":"v1.13.0-fuji"},"Mainnet":{"latest-version":"v1.13.0", "minimum-version":"v1.13.0"}}}`)

func TestCheckMinDependencyVersion(t *testing.T) {
tests := []struct {
name string
dependency string
expectedError bool
cliDependencyData []byte
customVersion string
network models.Network
}{
{
name: "custom avalanchego dependency equal to cli minimum supported version of avalanchego",
dependency: constants.AvalancheGoRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.13.0-fuji",
network: models.NewFujiNetwork(),
},
{
name: "custom avalanchego dependency higher than cli minimum supported version of avalanchego",
dependency: constants.AvalancheGoRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.13.0",
network: models.NewFujiNetwork(),
},
{
name: "custom avalanchego dependency equal to cli minimum supported version of avalanchego",
dependency: constants.AvalancheGoRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.13.0-fuji",
network: models.NewFujiNetwork(),
},
{
name: "custom avalanchego dependency higher than cli minimum supported version of avalanchego",
dependency: constants.AvalancheGoRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.13.1",
network: models.NewFujiNetwork(),
},
{
name: "custom avalanchego dependency lower than cli minimum supported version of avalanchego",
dependency: constants.AvalancheGoRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: true,
customVersion: "v1.12.2",
network: models.NewFujiNetwork(),
},
{
name: "custom avalanchego dependency for network that doesn't have minimum supported version of avalanchego",
dependency: constants.AvalancheGoRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.12.2",
network: models.NewLocalNetwork(),
},
}

for _, tt := range tests {
mockDownloader := &mocks.Downloader{}
mockDownloader.On("Download", mock.MatchedBy(func(url string) bool {
return url == constants.CLILatestDependencyURL
})).Return(tt.cliDependencyData, nil)

app := application.New()
app.Downloader = mockDownloader

t.Run(tt.name, func(t *testing.T) {
err := CheckVersionIsOverMin(app, tt.dependency, tt.network, tt.customVersion)
if tt.expectedError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}
3 changes: 2 additions & 1 deletion pkg/models/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type VMCompatibility struct {
type AvagoCompatiblity map[string][]string

type NetworkVersion struct {
LatestVersion string `json:"latest-version"`
LatestVersion string `json:"latest-version"`
MinimumVersion string `json:"minimum-version"`
}

type CLIDependencyMap struct {
Expand Down
12 changes: 4 additions & 8 deletions versions/latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
"avalanchego": {
"Local Network": {
"latest-version": "v1.13.0",
"require-prerelease": false,
"prerelease-version": ""
"minimum-version": ""
},
"DevNet": {
"latest-version": "v1.13.0",
"require-prerelease": false,
"prerelease-version": ""
"minimum-version": ""
},
"Fuji": {
"latest-version": "v1.13.0",
"require-prerelease": false,
"prerelease-version": ""
"minimum-version": "v1.13.0-fuji"
},
"Mainnet": {
"latest-version": "v1.13.0",
"require-prerelease": false,
"prerelease-version": ""
"minimum-version": "v1.13.0"
}
}
}
Loading