Skip to main content

v0.24.0

Cosmos SDK v0.46 upgrade notes

Update dependencies

Cosmos SDK v0.46 is compatible with the latest version of IBC Go v5. If you have a chain that is using an older version, update the dependencies in your project.

Throughout the code you might see the following dependencies:

package pkg_name

import (
"github.com/cosmos/ibc-go/v3/..."
)

Where v3 is the version of IBC Go and ... are different IBC Go packages.

To upgrade the version to v5, a global find-and-replace should work. Replace cosmos/ibc-go/v3 (or whicherver version you're using) with cosmos/ibc-go/v5 only in *.go files (to exclude unwated changes to files like go,sum).

Module keeper

Add an import:

// x/{{moduleName}}/keeper/keeper.go

package keeper

// ...

import (
//...
storetypes "github.com/cosmos/cosmos-sdk/store/types"
)

In the Keeper struct replace sdk.StoreKey with storetypes.StoreKey:

// x/{{moduleName}}/keeper/keeper.go

package keeper

// ...

type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
}
)

In the argument list of the NewKeeper function definition:


package keeper

// ...

// x/{{moduleName}}/keeper/keeper.go

func NewKeeper(
//...
memKey storetypes.StoreKey,
)

Store type aliases have been removed from the Cosmos SDK types package and now have to be imported from store/types, instead.

In the testutil/keeper/{{moduleName}}.go replace types.StoreKey with storetypes.StoreKey and types.MemStoreKey with storetypes.MemStoreKey.

// testutil/keeper/{{moduleName}}.go

package keeper

// ...

func {{moduleName}}Keeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(storetypes.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(storetypes.MemStoreKey)
//...
}

Testutil network package

Add the require package for testing and pruningtypes and remove storetypes:

// testutil/network/network.go

package network

// ...

import (
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
"github.com/stretchr/testify/require"
// storetypes "github.com/cosmos/cosmos-sdk/store/types" <-- remove this line
)

In the DefaultConfig function replace storetypes.NewPruningOptionsFromString with pruningtypes.NewPruningOptionsFromString

// testutil/network/network.go

package network

// ...

func DefaultConfig() network.Config {
//...
return network.Config{
AppConstructor: func(val network.Validator) servertypes.Application {
return app.New(
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
//...
)
},
//...
}

The New function in the Cosmos SDK testutil/network package now accepts three arguments instead of two.

In the New function add t.TempDir() as the second argument to network.New() and test that no error is thrown with require.NoError(t, err):

// testutil/network/network.go

package network

// ...

func New(t *testing.T, configs ...network.Config) *network.Network {
//...
net, err := network.New(t, t.TempDir(), cfg)
require.NoError(t, err)
//...
}

Testutil keeper package

In the {{moduleName}}Keeper function make the following replacements:

  • storetypes.StoreKeytypes.StoreKey
  • storetypes.MemStoreKeytypes.MemStoreKey
  • sdk.StoreTypeIAVLstoretypes.StoreTypeIAVL
  • sdk.StoreTypeMemorystoretypes.StoreTypeMemory
// testutil/keeper/{{moduleName}}.go

package keeper

// ...

func {{moduleName}}Keeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
//...
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
//...
}

IBC modules

If you have IBC-enabled modules (for example, added with ignite scaffold module ... --ibc or created manually), make the following changes to the source code.

Cosmos SDK expects IBC modules to implement the IBCModule interface. Create a IBCModule type that embeds the module's keeper and a method that returns a new IBCModule. Methods in this file will be defined on this type.

// x/{{moduleName}}/module_ibc.go

package module_name

// ...

type IBCModule struct {
keeper keeper.Keeper
}

func NewIBCModule(k keeper.Keeper) IBCModule {
return IBCModule{
keeper: k,
}
}

Replace receivers for all methods in this file from (am AppModule) to (im IBCModule). Replace all instances of am. with im. to fix the errors.

OnChanOpenInit now returns to values: a string and an error:

// x/{{moduleName}}/module_ibc.go

package module_name

// ...

func (im IBCModule) OnChanOpenInit(...) (string, error)

Ensure that all return statements (five, in the default template) in OnChanOpenInit return two values. For example:

// x/{{moduleName}}/module_ibc.go

package module_name

// ...

func (im IBCModule) OnChanOpenInit(...) (string, error) {
//...
return "", sdkerrors.Wrapf(porttypes.ErrInvalidPort, "invalid port: %s, expected %s", portID, boundPort)
//...
}

Error acknowledgments returned from Transfer OnRecvPacket now include a deterministic ABCI code and error message. Remove the .Error() call:

// x/{{moduleName}}/module_ibc.go

package module_name

// ...

func (im IBCModule) OnRecvPacket(...) {
//...
if err := modulePacketData.Unmarshal(modulePacket.GetData()); err != nil {
// return channeltypes.NewErrorAcknowledgement(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal packet data: %s", err.Error()).Error())
return channeltypes.NewErrorAcknowledgement(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal packet data: %s", err.Error()))
}

//...
default:
// errMsg := fmt.Sprintf("unrecognized %s packet type: %T", types.ModuleName, packet)
// return channeltypes.NewErrorAcknowledgement(errMsg)
err := fmt.Errorf("unrecognized %s packet type: %T", types.ModuleName, packet)
return channeltypes.NewErrorAcknowledgement(err)
}

After switching to using both AppModule and IBCModule, modifying the following line:

// x/{{moduleName}}/module.go

package module_name

// ...

var (
//...
_ porttypes.IBCModule = IBCModule{} // instead of "= AppModule{}"
)

Main

The Execute function in Cosmos SDK server/cmd package now accepts three arguments instead of two.

// cmd/{{projectName}}d/main.go

package projectNamed

// ...

func main() {
//...
if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
os.Exit(1)
}
}

Handler

Cosmos SDK v0.46 no longer needs a NewHandler function that was used to handle messages and call appropriate keeper methods based on message types. Feel free to remove x/{{moduleName}}/handler.go file.

Since there is no NewHandler now, modify the deprecated Route function to return sdk.Route{}:

// x/{{moduleName}}/module.go

package module_name

// ...

func (am AppModule) Route() sdk.Route { return sdk.Route{} }