diff --git a/changelog.md b/changelog.md index df179f6ffc..1fb8daf425 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,7 @@ - [#3497](https://github.com/ignite/cli/pull/3497) Use corret bank balance query url in faucet openapi - [#3481](https://github.com/ignite/cli/pull/3481) Use correct checksum format in release checksum file - [#3470](https://github.com/ignite/cli/pull/3470) Prevent overriding minimum-gas-prices with default value +- [#3523](https://github.com/ignite/cli/pull/3523) Upgrade Cosmos SDK compatibility check for scaffolded apps ## [`v0.26.1`](https://github.com/ignite/cli/releases/tag/v0.26.1) diff --git a/ignite/cmd/chain_build.go b/ignite/cmd/chain_build.go index f2ac1fdbcb..7ba3ff5194 100644 --- a/ignite/cmd/chain_build.go +++ b/ignite/cmd/chain_build.go @@ -117,6 +117,7 @@ func chainBuildHandler(cmd *cobra.Command, _ []string) error { chain.KeyringBackend(chaincmd.KeyringBackendTest), chain.WithOutputer(session), chain.CollectEvents(session.EventBus()), + chain.CheckCosmosSDKVersion(), } if flagGetCheckDependencies(cmd) { diff --git a/ignite/cmd/chain_init.go b/ignite/cmd/chain_init.go index dedcd325a7..d2132e6552 100644 --- a/ignite/cmd/chain_init.go +++ b/ignite/cmd/chain_init.go @@ -105,6 +105,7 @@ func chainInitHandler(cmd *cobra.Command, _ []string) error { chain.KeyringBackend(chaincmd.KeyringBackendTest), chain.WithOutputer(session), chain.CollectEvents(session.EventBus()), + chain.CheckCosmosSDKVersion(), } if flagGetCheckDependencies(cmd) { diff --git a/ignite/cmd/chain_serve.go b/ignite/cmd/chain_serve.go index 8df886b1f5..eead20a263 100644 --- a/ignite/cmd/chain_serve.go +++ b/ignite/cmd/chain_serve.go @@ -127,6 +127,7 @@ func chainServe(cmd *cobra.Command, session *cliui.Session) error { chainOption := []chain.Option{ chain.WithOutputer(session), chain.CollectEvents(session.EventBus()), + chain.CheckCosmosSDKVersion(), } if flagGetCheckDependencies(cmd) { diff --git a/ignite/cmd/generate_go.go b/ignite/cmd/generate_go.go index 80806dba72..c04693458a 100644 --- a/ignite/cmd/generate_go.go +++ b/ignite/cmd/generate_go.go @@ -29,6 +29,7 @@ func generateGoHandler(cmd *cobra.Command, _ []string) error { cmd, chain.WithOutputer(session), chain.CollectEvents(session.EventBus()), + chain.CheckCosmosSDKVersion(), ) if err != nil { return err diff --git a/ignite/pkg/cosmosanalysis/cosmosanalysis.go b/ignite/pkg/cosmosanalysis/cosmosanalysis.go index 1ddca74027..da6aa30dfe 100644 --- a/ignite/pkg/cosmosanalysis/cosmosanalysis.go +++ b/ignite/pkg/cosmosanalysis/cosmosanalysis.go @@ -13,11 +13,11 @@ import ( "github.com/pkg/errors" "golang.org/x/mod/modfile" + "github.com/ignite/cli/ignite/pkg/cosmosver" "github.com/ignite/cli/ignite/pkg/gomodule" ) const ( - cosmosModulePath = "github.com/cosmos/cosmos-sdk" tendermintModulePath = "github.com/cometbft/cometbft" appFileName = "app.go" defaultAppFilePath = "app/" + appFileName @@ -193,8 +193,8 @@ func IsChainPath(path string) error { // ValidateGoMod check if the cosmos-sdk and the tendermint packages are imported. func ValidateGoMod(module *modfile.File) error { moduleCheck := map[string]bool{ - cosmosModulePath: true, - tendermintModulePath: true, + cosmosver.CosmosModulePath: true, + tendermintModulePath: true, } for _, r := range module.Require { delete(moduleCheck, r.Mod.Path) diff --git a/ignite/pkg/cosmosgen/generate.go b/ignite/pkg/cosmosgen/generate.go index adba60d4fa..ac09180caf 100644 --- a/ignite/pkg/cosmosgen/generate.go +++ b/ignite/pkg/cosmosgen/generate.go @@ -12,12 +12,12 @@ import ( "github.com/ignite/cli/ignite/pkg/cmdrunner" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosanalysis/module" + "github.com/ignite/cli/ignite/pkg/cosmosver" "github.com/ignite/cli/ignite/pkg/gomodule" "github.com/ignite/cli/ignite/pkg/xfilepath" ) const ( - defaultSDKImport = "github.com/cosmos/cosmos-sdk" moduleCacheNamespace = "generate.setup.module" ) @@ -54,12 +54,12 @@ func (g *generator) setup() (err error) { return err } - g.sdkImport = defaultSDKImport + g.sdkImport = cosmosver.CosmosModulePath // Check if the Cosmos SDK import path points to a different path // and if so change the default one to the new location. for _, r := range modFile.Replace { - if r.Old.Path == defaultSDKImport { + if r.Old.Path == cosmosver.CosmosModulePath { g.sdkImport = r.New.Path break } diff --git a/ignite/pkg/cosmosver/cosmosver.go b/ignite/pkg/cosmosver/cosmosver.go index 8e9194ee45..d04585e6eb 100644 --- a/ignite/pkg/cosmosver/cosmosver.go +++ b/ignite/pkg/cosmosver/cosmosver.go @@ -21,6 +21,7 @@ var ( StargateFortyVersion = newVersion("0.40.0") StargateFortyFourVersion = newVersion("0.44.0-alpha") StargateFortyFiveThreeVersion = newVersion("0.45.3") + StargateFortySevenTwoVersion = newVersion("0.47.2") ) var ( @@ -28,6 +29,8 @@ var ( Versions = []Version{ StargateFortyVersion, StargateFortyFourVersion, + StargateFortyFiveThreeVersion, + StargateFortySevenTwoVersion, } // Latest is the latest known version of the Cosmos-SDK. diff --git a/ignite/pkg/cosmosver/detect.go b/ignite/pkg/cosmosver/detect.go index 000a3b40c7..f280084829 100644 --- a/ignite/pkg/cosmosver/detect.go +++ b/ignite/pkg/cosmosver/detect.go @@ -5,7 +5,8 @@ import ( ) const ( - cosmosModulePath = "github.com/cosmos/cosmos-sdk" + // CosmosModulePath defines Cosmos SDK import path. + CosmosModulePath = "github.com/cosmos/cosmos-sdk" ) // Detect detects major version of Cosmos. @@ -18,7 +19,7 @@ func Detect(appPath string) (version Version, err error) { for _, r := range parsed.Require { v := r.Mod - if v.Path == cosmosModulePath { + if v.Path == CosmosModulePath { if version, err = Parse(v.Version); err != nil { return version, err } diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index 7edf809b70..2bc222ab57 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -20,6 +20,7 @@ import ( "github.com/ignite/cli/ignite/pkg/repoversion" "github.com/ignite/cli/ignite/pkg/xexec" "github.com/ignite/cli/ignite/pkg/xurl" + igniteversion "github.com/ignite/cli/ignite/version" ) var appBackendSourceWatchPaths = []string{ @@ -68,6 +69,10 @@ type chainOptions struct { // been modified since they were downloaded. checkDependencies bool + // checkCosmosSDKVersion checks that the app was scaffolded with version of + // the Cosmos SDK that is supported by Ignite CLI. + checkCosmosSDKVersion bool + // printGeneratedPaths prints the output paths of the generated code printGeneratedPaths bool @@ -129,6 +134,14 @@ func CheckDependencies() Option { } } +// CheckCosmosSDKVersion checks that the app was scaffolded with a version of +// the Cosmos SDK that is supported by Ignite CLI. +func CheckCosmosSDKVersion() Option { + return func(c *Chain) { + c.options.checkCosmosSDKVersion = true + } +} + // PrintGeneratedPaths prints the output paths of the generated code. func PrintGeneratedPaths() Option { return func(c *Chain) { @@ -163,6 +176,12 @@ func New(path string, options ...Option) (*Chain, error) { return nil, err } + if c.options.checkCosmosSDKVersion { + if err := igniteversion.AssertSupportedCosmosSDKVersion(c.Version); err != nil { + return nil, err + } + } + return c, nil } diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index 3d226fce90..78eb6520d4 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -4,7 +4,6 @@ package scaffolder import ( "context" - "fmt" "path/filepath" chainconfig "github.com/ignite/cli/ignite/config/chain" @@ -14,6 +13,7 @@ import ( "github.com/ignite/cli/ignite/pkg/cosmosver" "github.com/ignite/cli/ignite/pkg/gocmd" "github.com/ignite/cli/ignite/pkg/gomodulepath" + "github.com/ignite/cli/ignite/version" ) // Scaffolder is Ignite CLI app scaffolder. @@ -30,44 +30,32 @@ type Scaffolder struct { // New creates a new scaffold app. func New(appPath string) (Scaffolder, error) { - sc, err := newScaffolder(appPath) + path, err := filepath.Abs(appPath) if err != nil { - return sc, err - } - - if sc.Version.LT(cosmosver.StargateFortyFourVersion) { - return sc, fmt.Errorf( - `⚠️ Your chain has been scaffolded with an old version of Cosmos SDK: %[1]v. -Please, follow the migration guide to upgrade your chain to the latest version: - -https://docs.ignite.com/migration`, sc.Version.String(), - ) + return Scaffolder{}, err } - return sc, nil -} -// newScaffolder creates a new Scaffolder for an existent app. -func newScaffolder(path string) (Scaffolder, error) { - path, err := filepath.Abs(path) + modpath, path, err := gomodulepath.Find(path) if err != nil { return Scaffolder{}, err } - modpath, path, err := gomodulepath.Find(path) + ver, err := cosmosver.Detect(path) if err != nil { return Scaffolder{}, err } - if err := cosmosanalysis.IsChainPath(path); err != nil { + + // Make sure that the app was scaffolded with a supported Cosmos SDK version + if err := version.AssertSupportedCosmosSDKVersion(ver); err != nil { return Scaffolder{}, err } - version, err := cosmosver.Detect(path) - if err != nil { + if err := cosmosanalysis.IsChainPath(path); err != nil { return Scaffolder{}, err } s := Scaffolder{ - Version: version, + Version: ver, path: path, modpath: modpath, } diff --git a/ignite/version/version.go b/ignite/version/version.go index 189352abc0..5a2d71cc75 100644 --- a/ignite/version/version.go +++ b/ignite/version/version.go @@ -16,11 +16,16 @@ import ( chainconfig "github.com/ignite/cli/ignite/config/chain" "github.com/ignite/cli/ignite/pkg/cmdrunner/exec" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" + "github.com/ignite/cli/ignite/pkg/cosmosver" "github.com/ignite/cli/ignite/pkg/gitpod" "github.com/ignite/cli/ignite/pkg/xexec" ) const ( + errOldCosmosSDKVersion = `your chain has been scaffolded with an older version of Cosmos SDK: %s + +Please, follow the migration guide to upgrade your chain to the latest version at https://docs.ignite.com/migration` + versionDev = "development" versionNightly = "nightly" ) @@ -105,7 +110,7 @@ func Long(ctx context.Context) string { ) if info, ok := debug.ReadBuildInfo(); ok { for _, dep := range info.Deps { - if dep.Path == "github.com/cosmos/cosmos-sdk" { + if dep.Path == cosmosver.CosmosModulePath { sdkVersion = dep.Version break } @@ -181,3 +186,11 @@ func Long(ctx context.Context) string { return b.String() } + +// AssertSupportedCosmosSDKVersion asserts that a Cosmos SDK version is supported by Ignite CLI. +func AssertSupportedCosmosSDKVersion(v cosmosver.Version) error { + if v.LT(cosmosver.StargateFortySevenTwoVersion) { + return fmt.Errorf(errOldCosmosSDKVersion, v) + } + return nil +}