Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
35413e4
update tests
sukantoraymond Apr 14, 2025
9fae8d1
add more min subnet evm version check
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
933e24b
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
d7fb635
Merge branch 'min-version' into subnet-evm-min-version-check
sukantoraymond May 1, 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
13 changes: 13 additions & 0 deletions cmd/blockchaincmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ func StartLocalMachine(
if useLocalMachine && numLocalNodes == 0 {
numLocalNodes = constants.DefaultNumberOfLocalMachineNodes
}
if useLocalMachine {
if sidecar.VM == models.SubnetEvm {
if err = dependencies.CheckVersionIsOverMin(app, constants.SubnetEVMRepoName, network, sidecar.VMVersion); err != nil {
ux.Logger.PrintToUser(dependencies.UpdateSubnetEVMInstruction)
return false, err
}
}
}
// if no cluster provided - we create one with fmt.Sprintf("%s-local-node-%s", blockchainName, networkNameComponent) name
if useLocalMachine && clusterNameFlagValue == "" {
if localnet.LocalClusterExists(app, clusterName) {
Expand Down Expand Up @@ -193,6 +201,11 @@ func StartLocalMachine(
avagoVersionSettings := dependencies.AvalancheGoVersionSettings{}
// setup (install if needed) avalanchego binary
avagoVersion := userProvidedAvagoVersion
if userProvidedAvagoVersion != constants.DefaultAvalancheGoVersion {
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
6 changes: 4 additions & 2 deletions cmd/blockchaincmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,11 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {

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

// TODO: place this check in how we handle input and flags for dependency versioning
if err = dependencies.CheckVersionIsOverMin(app, constants.AvalancheGoRepoName, network, userProvidedAvagoVersion); err != nil {
return err
}
avagoVersion := userProvidedAvagoVersion

if avagoVersion == constants.DefaultAvalancheGoVersion && avagoBinaryPath == "" {
avagoVersion, err = dependencies.GetLatestCLISupportedDependencyVersion(app, constants.AvalancheGoRepoName, network, &sidecar.RPCVersion)
if err != nil {
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
3 changes: 1 addition & 2 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,9 @@ const (
UpgradeBytesLockExtension = ".lock"
NotAvailableLabel = "Not available"

FujiAvalancheGoV113 = "v1.13.0-fuji"
AvalancheGoCompatibilityURL = "https://raw.githubusercontent.com/ava-labs/avalanchego/master/version/compatibility.json"
SubnetEVMRPCCompatibilityURL = "https://raw.githubusercontent.com/ava-labs/subnet-evm/master/compatibility.json"
CLILatestDependencyURL = "https://raw.githubusercontent.com/ava-labs/avalanche-cli/main/versions/latest.json"
CLILatestDependencyURL = "https://raw.githubusercontent.com/ava-labs/avalanche-cli/subnet-evm-min-version-check/versions/latest.json"

YesLabel = "Yes"
NoLabel = "No"
Expand Down
9 changes: 8 additions & 1 deletion pkg/dependencies/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ func GetLatestCLISupportedDependencyVersion(app *application.Avalanche, dependen
}
return parsedDependency.AvalancheGo[network.Name()].LatestVersion, nil
case constants.SubnetEVMRepoName:
return parsedDependency.SubnetEVM, nil
// Currently we get latest subnet evm version during blockchain create, which we then use to update the sidecar.
// From the latest subnet evm version obtained, we then get the rpc version, which is also updated in the sidecar during blockchain create.
// Getting latest subnet evm version therefore is independent of rpc version and therefore there is no need for any rpc version checks here.
// We default to local network if network is undefined in argument.
if network == models.UndefinedNetwork {
network = models.NewLocalNetwork()
}
return parsedDependency.SubnetEVM[network.Name()].LatestVersion, nil
default:
return "", fmt.Errorf("unsupported dependency: %s", dependencyName)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dependencies/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var (
testAvagoCompat5 = []byte("{\"39\": [\"v1.12.2\", \"v1.13.0\"],\"38\": [\"v1.11.13\", \"v1.12.0\", \"v1.12.1\"]}")
testAvagoCompat6 = []byte("{\"39\": [\"v1.12.2\", \"v1.13.0\", \"v1.13.1\"],\"38\": [\"v1.11.13\", \"v1.12.0\", \"v1.12.1\"]}")
testAvagoCompat7 = []byte("{\"40\": [\"v1.13.2\"],\"39\": [\"v1.12.2\", \"v1.13.0\", \"v1.13.1\"]}")
testCLICompat = []byte(`{"subnet-evm":"v0.7.3","rpc":39,"avalanchego":{"Local Network":{"latest-version":"v1.13.0"},"DevNet":{"latest-version":"v1.13.0"},"Fuji":{"latest-version":"v1.13.0"},"Mainnet":{"latest-version":"v1.13.0"}}}`)
testCLICompat2 = []byte(`{"subnet-evm":"v0.7.3","rpc":39,"avalanchego":{"Local Network":{"latest-version":"v1.13.0"},"DevNet":{"latest-version":"v1.13.0"},"Fuji":{"latest-version":"v1.13.0-fuji"},"Mainnet":{"latest-version":"v1.13.0"}}}`)
testCLICompat = []byte(`{"subnet-evm":{"Local Network":{"latest-version":"v0.7.3", "minimum-version":""},"DevNet":{"latest-version":"v0.7.3", "minimum-version":""},"Fuji":{"latest-version":"v0.7.3", "minimum-version":"v0.7.2"},"Mainnet":{"latest-version":"v0.7.3", "minimum-version":"v0.7.2"}},"rpc":39,"avalanchego":{"Local Network":{"latest-version":"v1.13.0"},"DevNet":{"latest-version":"v1.13.0"},"Fuji":{"latest-version":"v1.13.0"},"Mainnet":{"latest-version":"v1.13.0"}}}`)
testCLICompat2 = []byte(`{"subnet-evm":{"Local Network":{"latest-version":"v0.7.3", "minimum-version":""},"DevNet":{"latest-version":"v0.7.3", "minimum-version":""},"Fuji":{"latest-version":"v0.7.3", "minimum-version":"v0.7.2"},"Mainnet":{"latest-version":"v0.7.3", "minimum-version":"v0.7.2"}},"rpc":39,"avalanchego":{"Local Network":{"latest-version":"v1.13.0"},"DevNet":{"latest-version":"v1.13.0"},"Fuji":{"latest-version":"v1.13.0-fuji"},"Mainnet":{"latest-version":"v1.13.0"}}}`)
)

func TestGetLatestAvalancheGoByProtocolVersion(t *testing.T) {
Expand Down
50 changes: 50 additions & 0 deletions pkg/dependencies/min_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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"
)

var UpdateSubnetEVMInstruction = "To update the blockchain's Subnet-EVM version, call avalanche blockchain upgrade vm <blockchainName> --config --version <version>"

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", dependencyName, minVersion)
}
return nil
case constants.SubnetEVMRepoName:
// version has to be at least higher than minimum version specified for the dependency
minVersion := parsedDependency.SubnetEVM[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", dependencyName, minVersion)
}
return nil
default:
return fmt.Errorf("can't check minimum version for dependency: %s", dependencyName)
}
}
120 changes: 120 additions & 0 deletions pkg/dependencies/min_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// 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":{"Local Network":{"latest-version":"v0.7.3", "minimum-version":""},"DevNet":{"latest-version":"v0.7.3", "minimum-version":""},"Fuji":{"latest-version":"v0.7.3", "minimum-version":"v0.7.2"},"Mainnet":{"latest-version":"v0.7.3", "minimum-version":"v0.7.2"}},"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 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(),
},
{
name: "custom subnetEVM dependency equal to cli minimum supported version of subnetEVM",
dependency: constants.SubnetEVMRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v0.7.2",
network: models.NewFujiNetwork(),
},
{
name: "custom subnetEVM dependency higher than cli minimum supported version of subnetEVM",
dependency: constants.SubnetEVMRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v0.7.3",
network: models.NewFujiNetwork(),
},
{
name: "custom subnetEVM dependency lower than cli minimum supported version of subnetEVM",
dependency: constants.SubnetEVMRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: true,
customVersion: "v0.7.1",
network: models.NewFujiNetwork(),
},
{
name: "custom subnetEVM dependency for network that doesn't have minimum supported version of subnetEVM",
dependency: constants.SubnetEVMRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v0.7.1",
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)
}
})
}
}
9 changes: 9 additions & 0 deletions pkg/localnet/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"fmt"
"os"

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

"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/ux"
Expand Down Expand Up @@ -43,6 +46,12 @@ func TrackSubnet(
blockchainConfig []byte
subnetConfig []byte
)
if sc.VM == models.SubnetEvm {
if err = dependencies.CheckVersionIsOverMin(app, constants.SubnetEVMRepoName, networkModel, sc.VMVersion); err != nil {
ux.Logger.PrintToUser(dependencies.UpdateSubnetEVMInstruction)
Copy link
Collaborator

Choose a reason for hiding this comment

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

use printFunc

return err
}
}
vmBinaryPath, err := SetupVMBinary(app, blockchainName)
if err != nil {
return fmt.Errorf("failed to setup VM binary: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/models/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ 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 {
RPC int `json:"rpc"`
SubnetEVM string `json:"subnet-evm"`
SubnetEVM map[string]NetworkVersion `json:"subnet-evm"`
AvalancheGo map[string]NetworkVersion `json:"avalanchego"`
}
13 changes: 13 additions & 0 deletions pkg/node/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"fmt"
"sync"

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

"github.com/ava-labs/avalanche-cli/pkg/ansible"
"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/models"
Expand All @@ -29,6 +32,16 @@ func SyncSubnet(app *application.Avalanche, clusterName, blockchainName string,
if _, err := subnet.ValidateSubnetNameAndGetChains(app, []string{blockchainName}); err != nil {
return err
}
sc, err := app.LoadSidecar(blockchainName)
if err != nil {
return err
}
if sc.VM == models.SubnetEvm {
if err = dependencies.CheckVersionIsOverMin(app, constants.SubnetEVMRepoName, clusterConfig.Network, sc.VMVersion); err != nil {
ux.Logger.PrintToUser(dependencies.UpdateSubnetEVMInstruction)
return err
}
}
hosts, err := ansible.GetInventoryFromAnsibleInventoryFile(app.GetAnsibleInventoryDirPath(clusterName))
if err != nil {
return err
Expand Down
31 changes: 22 additions & 9 deletions versions/latest.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
{
"subnet-evm": "v0.7.3",
"subnet-evm": {
"Local Network": {
"latest-version": "v0.7.3",
"minimum-version": ""
},
"DevNet": {
"latest-version": "v0.7.3",
"minimum-version": ""
},
"Fuji": {
"latest-version": "v0.7.3",
"minimum-version": "v0.7.2"
},
"Mainnet": {
"latest-version": "v0.7.3",
"minimum-version": "v0.7.2"
}
},
"rpc": 39,
"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