From bd37d18a3bebb06ec9a6836ed0a0e0dbeeea9d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 14:43:30 +0100 Subject: [PATCH 01/20] refactor: add tendermint manual pruning function --- modules/core/02-client/migrations/store.go | 71 +++++++++ .../core/02-client/migrations/store_test.go | 150 ++++++++++++++++++ modules/core/24-host/parse.go | 23 +++ modules/core/24-host/parse_test.go | 30 ++++ 4 files changed, 274 insertions(+) create mode 100644 modules/core/02-client/migrations/store.go create mode 100644 modules/core/02-client/migrations/store_test.go diff --git a/modules/core/02-client/migrations/store.go b/modules/core/02-client/migrations/store.go new file mode 100644 index 00000000000..f5a07def82d --- /dev/null +++ b/modules/core/02-client/migrations/store.go @@ -0,0 +1,71 @@ +package migrations + +import ( + "fmt" + "strings" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + "github.com/cosmos/ibc-go/v6/modules/core/exported" + ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" +) + +// PruneTendermintConsensusStates prunes all expired tendermint consensus states. This function +// may optionally be called during in-place store migrations. The 02-client store key must be provided. +func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { + store := ctx.KVStore(storeKey) + + // iterate over 02-client store with prefix: clients/07-tendermint, + // example iterator.Key = -100/clientState (second half of the clientID + clientStore specific keys) + tendermintClientPrefix := []byte(fmt.Sprintf("%s/%s", host.KeyClientStorePrefix, exported.Tendermint)) + iterator := sdk.KVStorePrefixIterator(store, tendermintClientPrefix) + + var clients []string + + // collect all clients to avoid performing store state changes during iteration + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + path := string(iterator.Key()) + if !strings.Contains(path, host.KeyClientState) { + // skip non client state keys + continue + } + + clientID, err := host.ParseClientStatePath(path) + if err != nil { + return err + } + + clients = append(clients, clientID) + } + + for _, clientID := range clients { + clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) + clientStore := prefix.NewStore(ctx.KVStore(storeKey), clientPrefix) + + bz := clientStore.Get(host.ClientStateKey()) + if bz == nil { + return clienttypes.ErrClientNotFound + } + + var clientState exported.ClientState + if err := cdc.UnmarshalInterface(bz, &clientState); err != nil { + return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into tendermint client state") + } + + tmClientState, ok := clientState.(*ibctm.ClientState) + if !ok { + return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") + } + + ibctm.PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) + } + + return nil +} diff --git a/modules/core/02-client/migrations/store_test.go b/modules/core/02-client/migrations/store_test.go new file mode 100644 index 00000000000..bd01fb5a663 --- /dev/null +++ b/modules/core/02-client/migrations/store_test.go @@ -0,0 +1,150 @@ +package migrations_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/suite" + + "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations" + "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + "github.com/cosmos/ibc-go/v6/modules/core/exported" + ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" + ibctesting "github.com/cosmos/ibc-go/v6/testing" +) + +type MigrationsTestSuite struct { + suite.Suite + + coordinator *ibctesting.Coordinator + + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain +} + +// TestMigrationsTestSuite runs all the tests within this package. +func TestMigrationsTestSuite(t *testing.T) { + suite.Run(t, new(MigrationsTestSuite)) +} + +// SetupTest creates a coordinator with 2 test chains. +func (suite *MigrationsTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) +} + +// test pruning of multiple expired tendermint consensus states +func (suite *MigrationsTestSuite) TestMigrateStoreTendermint() { + // create path and setup clients + path1 := ibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(path1) + + path2 := ibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(path2) + + pruneHeightMap := make(map[*ibctesting.Path][]exported.Height) + unexpiredHeightMap := make(map[*ibctesting.Path][]exported.Height) + + for _, path := range []*ibctesting.Path{path1, path2} { + // collect all heights expected to be pruned + var pruneHeights []exported.Height + pruneHeights = append(pruneHeights, path.EndpointA.GetClientState().GetLatestHeight()) + + // these heights will be expired and also pruned + for i := 0; i < 3; i++ { + err := path.EndpointA.UpdateClient() + suite.Require().NoError(err) + + pruneHeights = append(pruneHeights, path.EndpointA.GetClientState().GetLatestHeight()) + } + + // double chedck all information is currently stored + for _, pruneHeight := range pruneHeights { + consState, ok := suite.chainA.GetConsensusState(path.EndpointA.ClientID, pruneHeight) + suite.Require().True(ok) + suite.Require().NotNil(consState) + + ctx := suite.chainA.GetContext() + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) + + processedTime, ok := ibctm.GetProcessedTime(clientStore, pruneHeight) + suite.Require().True(ok) + suite.Require().NotNil(processedTime) + + processedHeight, ok := ibctm.GetProcessedHeight(clientStore, pruneHeight) + suite.Require().True(ok) + suite.Require().NotNil(processedHeight) + + expectedConsKey := ibctm.GetIterationKey(clientStore, pruneHeight) + suite.Require().NotNil(expectedConsKey) + } + pruneHeightMap[path] = pruneHeights + } + + // Increment the time by a week + suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) + + for _, path := range []*ibctesting.Path{path1, path2} { + // create the consensus state that can be used as trusted height for next update + var unexpiredHeights []exported.Height + err := path.EndpointA.UpdateClient() + suite.Require().NoError(err) + unexpiredHeights = append(unexpiredHeights, path.EndpointA.GetClientState().GetLatestHeight()) + + err = path.EndpointA.UpdateClient() + suite.Require().NoError(err) + unexpiredHeights = append(unexpiredHeights, path.EndpointA.GetClientState().GetLatestHeight()) + + unexpiredHeightMap[path] = unexpiredHeights + } + + // Increment the time by another week, then update the client. + // This will cause the consensus states created before the first time increment + // to be expired + suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) + err := migrations.PruneTendermintConsensusStates(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().GetKey(host.StoreKey)) + suite.Require().NoError(err) + + for _, path := range []*ibctesting.Path{path1, path2} { + ctx := suite.chainA.GetContext() + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) + + // ensure everything has been pruned + for i, pruneHeight := range pruneHeightMap[path] { + consState, ok := suite.chainA.GetConsensusState(path.EndpointA.ClientID, pruneHeight) + suite.Require().False(ok, i) + suite.Require().Nil(consState, i) + + processedTime, ok := ibctm.GetProcessedTime(clientStore, pruneHeight) + suite.Require().False(ok, i) + suite.Require().Equal(uint64(0), processedTime, i) + + processedHeight, ok := ibctm.GetProcessedHeight(clientStore, pruneHeight) + suite.Require().False(ok, i) + suite.Require().Nil(processedHeight, i) + + expectedConsKey := ibctm.GetIterationKey(clientStore, pruneHeight) + suite.Require().Nil(expectedConsKey, i) + } + + // ensure metadata is set for unexpired consensus state + for _, height := range unexpiredHeightMap[path] { + consState, ok := suite.chainA.GetConsensusState(path.EndpointA.ClientID, height) + suite.Require().True(ok) + suite.Require().NotNil(consState) + + processedTime, ok := ibctm.GetProcessedTime(clientStore, height) + suite.Require().True(ok) + suite.Require().NotEqual(uint64(0), processedTime) + + processedHeight, ok := ibctm.GetProcessedHeight(clientStore, height) + suite.Require().True(ok) + suite.Require().NotEqual(types.ZeroHeight(), processedHeight) + + consKey := ibctm.GetIterationKey(clientStore, height) + suite.Require().Equal(host.ConsensusStateKey(height), consKey) + } + } +} diff --git a/modules/core/24-host/parse.go b/modules/core/24-host/parse.go index 8c3459500d9..37ae8e1460d 100644 --- a/modules/core/24-host/parse.go +++ b/modules/core/24-host/parse.go @@ -32,6 +32,29 @@ func ParseIdentifier(identifier, prefix string) (uint64, error) { return sequence, nil } +// ParseClientStatePath returns the client ID from a client state path. It returns +// an error if the provided path is invalid. +func ParseClientStatePath(path string) (string, error) { + split := strings.Split(path, "/") + if len(split) != 3 { + return "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse client state path %s", path) + } + + if split[0] != string(KeyClientStorePrefix) { + return "", sdkerrors.Wrapf(ErrInvalidPath, "path does not begin with client store prefix: expected %s, got %s", KeyClientStorePrefix, split[0]) + } + + if split[2] != KeyClientState { + return "", sdkerrors.Wrapf(ErrInvalidPath, "path does not end with client state key: expected %s, got %s", KeyClientState, split[2]) + } + + if strings.TrimSpace(split[1]) == "" { + return "", sdkerrors.Wrap(ErrInvalidPath, "clientID is empty") + } + + return split[1], nil +} + // ParseConnectionPath returns the connection ID from a full path. It returns // an error if the provided path is invalid. func ParseConnectionPath(path string) (string, error) { diff --git a/modules/core/24-host/parse_test.go b/modules/core/24-host/parse_test.go index ea30f671cde..7e39cfdfc47 100644 --- a/modules/core/24-host/parse_test.go +++ b/modules/core/24-host/parse_test.go @@ -1,6 +1,7 @@ package host_test import ( + "fmt" "math" "testing" @@ -8,6 +9,7 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + ibctesting "github.com/cosmos/ibc-go/v6/testing" ) func TestParseIdentifier(t *testing.T) { @@ -46,3 +48,31 @@ func TestParseIdentifier(t *testing.T) { } } } + +func TestParseClientStatePath(t *testing.T) { + testCases := []struct { + name string + path string + expPass bool + }{ + {"valid", host.FullClientStatePath(ibctesting.FirstClientID), true}, + {"path too large", fmt.Sprintf("clients/clients/%s/clientState", ibctesting.FirstClientID), false}, + {"path too small", fmt.Sprintf("clients/%s", ibctesting.FirstClientID), false}, + {"path does not begin with client store", fmt.Sprintf("cli/%s/%s", ibctesting.FirstClientID, host.KeyClientState), false}, + {"path does not end with client state key", fmt.Sprintf("%s/%s/consensus", string(host.KeyClientStorePrefix), ibctesting.FirstClientID), false}, + {"client ID is empty", host.FullClientStatePath(""), false}, + {"client ID is only spaces", host.FullClientStatePath(" "), false}, + } + + for _, tc := range testCases { + clientID, err := host.ParseClientStatePath(tc.path) + + if tc.expPass { + require.NoError(t, err, tc.name) + require.Equal(t, ibctesting.FirstClientID, clientID) + } else { + require.Error(t, err, tc.name) + require.Equal(t, "", clientID) + } + } +} From 7ad76de262f73dab34273df80d133783e2120633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 14:57:48 +0100 Subject: [PATCH 02/20] chore: add extra checks into pruning test ensure the pruning function does not modify non tendermint client types --- .../core/02-client/migrations/store_test.go | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/modules/core/02-client/migrations/store_test.go b/modules/core/02-client/migrations/store_test.go index bd01fb5a663..f2bda003d2d 100644 --- a/modules/core/02-client/migrations/store_test.go +++ b/modules/core/02-client/migrations/store_test.go @@ -36,18 +36,38 @@ func (suite *MigrationsTestSuite) SetupTest() { } // test pruning of multiple expired tendermint consensus states -func (suite *MigrationsTestSuite) TestMigrateStoreTendermint() { - // create path and setup clients - path1 := ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.SetupClients(path1) +func (suite *MigrationsTestSuite) TestPruneTendermintConsensusStates() { + // create multiple tendermint clients and a solo machine client + // the solo machine is used to verify this pruning function only modifies + // the tendermint store. - path2 := ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.SetupClients(path2) + numTMClients := 3 + paths := make([]*ibctesting.Path, numTMClients) + + for i := 0; i < numTMClients; i++ { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(path) + + paths[i] = path + } + + solomachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "06-solomachine-0", "testing", 1) + smClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), solomachine.ClientID) + + // set client state + bz, err := suite.chainA.App.AppCodec().MarshalInterface(solomachine.ClientState()) + suite.Require().NoError(err) + smClientStore.Set(host.ClientStateKey(), bz) + + bz, err = suite.chainA.App.AppCodec().MarshalInterface(solomachine.ConsensusState()) + suite.Require().NoError(err) + smHeight := types.NewHeight(0, 1) + smClientStore.Set(host.ConsensusStateKey(smHeight), bz) pruneHeightMap := make(map[*ibctesting.Path][]exported.Height) unexpiredHeightMap := make(map[*ibctesting.Path][]exported.Height) - for _, path := range []*ibctesting.Path{path1, path2} { + for _, path := range paths { // collect all heights expected to be pruned var pruneHeights []exported.Height pruneHeights = append(pruneHeights, path.EndpointA.GetClientState().GetLatestHeight()) @@ -86,7 +106,7 @@ func (suite *MigrationsTestSuite) TestMigrateStoreTendermint() { // Increment the time by a week suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - for _, path := range []*ibctesting.Path{path1, path2} { + for _, path := range paths { // create the consensus state that can be used as trusted height for next update var unexpiredHeights []exported.Height err := path.EndpointA.UpdateClient() @@ -104,10 +124,10 @@ func (suite *MigrationsTestSuite) TestMigrateStoreTendermint() { // This will cause the consensus states created before the first time increment // to be expired suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - err := migrations.PruneTendermintConsensusStates(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().GetKey(host.StoreKey)) + err = migrations.PruneTendermintConsensusStates(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().GetKey(host.StoreKey)) suite.Require().NoError(err) - for _, path := range []*ibctesting.Path{path1, path2} { + for _, path := range paths { ctx := suite.chainA.GetContext() clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) @@ -147,4 +167,12 @@ func (suite *MigrationsTestSuite) TestMigrateStoreTendermint() { suite.Require().Equal(host.ConsensusStateKey(height), consKey) } } + + // verify that solomachine client and consensus state were not removed + smClientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), solomachine.ClientID) + bz = smClientStore.Get(host.ClientStateKey()) + suite.Require().NotEmpty(bz) + + bz = smClientStore.Get(host.ConsensusStateKey(smHeight)) + suite.Require().NotEmpty(bz) } From 5e9f208fac8755c323c2b102a0c3480a766dd419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 15:17:47 +0100 Subject: [PATCH 03/20] chore: add docs and logging for tendermint pruning --- docs/migrations/v6-to-v7.md | 61 ++++++++------------ modules/core/02-client/migrations/store.go | 14 +++-- modules/light-clients/07-tendermint/store.go | 6 +- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/docs/migrations/v6-to-v7.md b/docs/migrations/v6-to-v7.md index 70e9519f4e3..65e3c35b7c2 100644 --- a/docs/migrations/v6-to-v7.md +++ b/docs/migrations/v6-to-v7.md @@ -13,7 +13,31 @@ There are four sections based on the four potential user groups of this document ## Chains -- No relevant changes were made in this release. +Chains will perform automatic migrations to remove a localhost client, if it exists and to migrate the solomachine to the v3 of the protobuf definition. + +An optional upgrade handler has been added to prune expired tendermint consensus states. +Add the following to the function call to the upgrade handler in `app/app.go`, to perform the optional state pruning. + +```go +import ( + // ... + ibcclientmigrations "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations" +) + +// ... + +app.UpgradeKeeper.SetUpgradeHandler( + upgradeName, + func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { + // prune expired tendermint consensus states + ibcclientmigrations.PruneTendermintExpiredConsensusStates(ctx, app.Codec, appCodec, keys[ibchost.StoreKey]) + + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, +) +``` + +Checkout the logs to see how many consensus states are pruned. ## IBC Apps @@ -55,41 +79,6 @@ The function `GetTimestampAtHeight` has been added to the `ClientState` interfac The `GetRoot` function has been removed from consensus state interface since it was not used by core IBC. -### Light client implementations - -The `09-localhost` light client implementation has been removed because it is currently non-functional. - -An upgrade handler has been added to supply chain developers with the logic needed to prune the ibc client store and successfully complete the removal of `09-localhost`. -Add the following to the application upgrade handler in `app/app.go`, calling `MigrateToV6` to perform store migration logic. - -```go -import ( - // ... - ibcv6 "github.com/cosmos/ibc-go/v6/modules/core/migrations/v6" -) - -// ... - -app.UpgradeKeeper.SetUpgradeHandler( - upgradeName, - func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { - // prune the 09-localhost client from the ibc client store - ibcv6.MigrateToV6(ctx, app.IBCKeeper.ClientKeeper) - - return app.mm.RunMigrations(ctx, app.configurator, fromVM) - }, -) -``` - -Please note the above upgrade handler is optional and should only be run if chains have an existing `09-localhost` client stored in state. -A simple query can be performed to check for a `09-localhost` client on chain. - -For example: - -``` -simd query ibc client states | grep 09-localhost -``` - ### Client Keeper Keeper function `CheckMisbehaviourAndUpdateState` has been removed since function `UpdateClient` can now handle updating `ClientState` on `ClientMessage` type which can be any `Misbehaviour` implementations. diff --git a/modules/core/02-client/migrations/store.go b/modules/core/02-client/migrations/store.go index f5a07def82d..7f847ca0923 100644 --- a/modules/core/02-client/migrations/store.go +++ b/modules/core/02-client/migrations/store.go @@ -10,7 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" "github.com/cosmos/ibc-go/v6/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" @@ -45,13 +45,15 @@ func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, stor clients = append(clients, clientID) } + var totalPruned int + for _, clientID := range clients { clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) clientStore := prefix.NewStore(ctx.KVStore(storeKey), clientPrefix) bz := clientStore.Get(host.ClientStateKey()) if bz == nil { - return clienttypes.ErrClientNotFound + return types.ErrClientNotFound } var clientState exported.ClientState @@ -61,11 +63,15 @@ func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, stor tmClientState, ok := clientState.(*ibctm.ClientState) if !ok { - return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") + return sdkerrors.Wrap(types.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") } - ibctm.PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) + amtPruned := ibctm.PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) + totalPruned = totalPruned + amtPruned } + clientLogger := ctx.Logger().With("module", "x/"+host.ModuleName+"/"+types.SubModuleName) + clientLogger.Info("pruned expired tendermint consensus states", "total", totalPruned) + return nil } diff --git a/modules/light-clients/07-tendermint/store.go b/modules/light-clients/07-tendermint/store.go index d46d9b01796..ce513c2cd68 100644 --- a/modules/light-clients/07-tendermint/store.go +++ b/modules/light-clients/07-tendermint/store.go @@ -273,11 +273,11 @@ func GetPreviousConsensusState(clientStore sdk.KVStore, cdc codec.BinaryCodec, h // PruneAllExpiredConsensusStates iterates over all consensus states for a given // client store. If a consensus state is expired, it is deleted and its metadata -// is deleted. +// is deleted. The number of consensus states pruned is returned. func PruneAllExpiredConsensusStates( ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec, clientState *ClientState, -) { +) int { var heights []exported.Height pruneCb := func(height exported.Height) bool { @@ -299,6 +299,8 @@ func PruneAllExpiredConsensusStates( deleteConsensusState(clientStore, height) deleteConsensusMetadata(clientStore, height) } + + return len(heights) } // Helper function for GetNextConsensusState and GetPreviousConsensusState From 5cb1262f11fdf9b9c2e1333c608eb80dedbb4946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 15:24:55 +0100 Subject: [PATCH 04/20] Apply suggestions from code review --- modules/core/02-client/migrations/store.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/core/02-client/migrations/store.go b/modules/core/02-client/migrations/store.go index 7f847ca0923..b7c4eb8646b 100644 --- a/modules/core/02-client/migrations/store.go +++ b/modules/core/02-client/migrations/store.go @@ -17,12 +17,11 @@ import ( ) // PruneTendermintConsensusStates prunes all expired tendermint consensus states. This function -// may optionally be called during in-place store migrations. The 02-client store key must be provided. +// may optionally be called during in-place store migrations. The ibc store key must be provided. func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { store := ctx.KVStore(storeKey) - // iterate over 02-client store with prefix: clients/07-tendermint, - // example iterator.Key = -100/clientState (second half of the clientID + clientStore specific keys) + // iterate over ibc store with prefix: host.ClientStoreKeyPrefix/07-tendermint, tendermintClientPrefix := []byte(fmt.Sprintf("%s/%s", host.KeyClientStorePrefix, exported.Tendermint)) iterator := sdk.KVStorePrefixIterator(store, tendermintClientPrefix) From 33c64d64726cd6b51e8cf77ad89320daa4882934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 15:25:27 +0100 Subject: [PATCH 05/20] Apply suggestions from code review --- docs/migrations/v6-to-v7.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/migrations/v6-to-v7.md b/docs/migrations/v6-to-v7.md index 65e3c35b7c2..dba1e46bbc1 100644 --- a/docs/migrations/v6-to-v7.md +++ b/docs/migrations/v6-to-v7.md @@ -13,9 +13,9 @@ There are four sections based on the four potential user groups of this document ## Chains -Chains will perform automatic migrations to remove a localhost client, if it exists and to migrate the solomachine to the v3 of the protobuf definition. +Chains will perform automatic migrations to remove existing localhost clients and to migrate the solomachine to the v3 of the protobuf definition. -An optional upgrade handler has been added to prune expired tendermint consensus states. +An optional upgrade handler has been added to prune expired tendermint consensus states. It may be used during any upgrade (not just to v7) Add the following to the function call to the upgrade handler in `app/app.go`, to perform the optional state pruning. ```go From f6bbe6fcfea49cba2973bfa207ffd9d1f2dc3c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:16:03 +0100 Subject: [PATCH 06/20] Apply suggestions from code review Co-authored-by: Damian Nolan --- docs/migrations/v6-to-v7.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/migrations/v6-to-v7.md b/docs/migrations/v6-to-v7.md index dba1e46bbc1..6bcc87cecd8 100644 --- a/docs/migrations/v6-to-v7.md +++ b/docs/migrations/v6-to-v7.md @@ -13,9 +13,9 @@ There are four sections based on the four potential user groups of this document ## Chains -Chains will perform automatic migrations to remove existing localhost clients and to migrate the solomachine to the v3 of the protobuf definition. +Chains will perform automatic migrations to remove existing localhost clients and to migrate the solomachine to v3 of the protobuf definition. -An optional upgrade handler has been added to prune expired tendermint consensus states. It may be used during any upgrade (not just to v7) +An optional upgrade handler has been added to prune expired tendermint consensus states. It may be used during any upgrade (from v7 onwards). Add the following to the function call to the upgrade handler in `app/app.go`, to perform the optional state pruning. ```go From f7d8871dfb6d528a2376b87a205d1dfa7d2d0f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:16:23 +0100 Subject: [PATCH 07/20] Update modules/core/02-client/migrations/store.go --- modules/core/02-client/migrations/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/02-client/migrations/store.go b/modules/core/02-client/migrations/store.go index b7c4eb8646b..cec42d05672 100644 --- a/modules/core/02-client/migrations/store.go +++ b/modules/core/02-client/migrations/store.go @@ -21,7 +21,7 @@ import ( func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, storeKey storetypes.StoreKey) error { store := ctx.KVStore(storeKey) - // iterate over ibc store with prefix: host.ClientStoreKeyPrefix/07-tendermint, + // iterate over ibc store with prefix: clients/07-tendermint, tendermintClientPrefix := []byte(fmt.Sprintf("%s/%s", host.KeyClientStorePrefix, exported.Tendermint)) iterator := sdk.KVStorePrefixIterator(store, tendermintClientPrefix) From 348b21e3f07fe33e3e2a5ee2eed27862821ba082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:25:09 +0100 Subject: [PATCH 08/20] chore: move tendermint migrations to 07-tendermint directory --- docs/migrations/v6-to-v7.md | 6 ++-- .../07-tendermint/migrations.go} | 10 +++---- .../07-tendermint/migrations_test.go} | 28 ++----------------- 3 files changed, 10 insertions(+), 34 deletions(-) rename modules/{core/02-client/migrations/store.go => light-clients/07-tendermint/migrations.go} (89%) rename modules/{core/02-client/migrations/store_test.go => light-clients/07-tendermint/migrations_test.go} (88%) diff --git a/docs/migrations/v6-to-v7.md b/docs/migrations/v6-to-v7.md index 65e3c35b7c2..e2fbbf39d13 100644 --- a/docs/migrations/v6-to-v7.md +++ b/docs/migrations/v6-to-v7.md @@ -21,7 +21,7 @@ Add the following to the function call to the upgrade handler in `app/app.go`, t ```go import ( // ... - ibcclientmigrations "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations" + ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" ) // ... @@ -29,8 +29,8 @@ import ( app.UpgradeKeeper.SetUpgradeHandler( upgradeName, func(ctx sdk.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { - // prune expired tendermint consensus states - ibcclientmigrations.PruneTendermintExpiredConsensusStates(ctx, app.Codec, appCodec, keys[ibchost.StoreKey]) + // prune expired tendermint consensus states to save storage space + ibctm.PruneTendermintConsensusStates(ctx, app.Codec, appCodec, keys[ibchost.StoreKey]) return app.mm.RunMigrations(ctx, app.configurator, fromVM) }, diff --git a/modules/core/02-client/migrations/store.go b/modules/light-clients/07-tendermint/migrations.go similarity index 89% rename from modules/core/02-client/migrations/store.go rename to modules/light-clients/07-tendermint/migrations.go index 7f847ca0923..0b94793a0f2 100644 --- a/modules/core/02-client/migrations/store.go +++ b/modules/light-clients/07-tendermint/migrations.go @@ -1,4 +1,4 @@ -package migrations +package tendermint import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" "github.com/cosmos/ibc-go/v6/modules/core/exported" - ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" ) // PruneTendermintConsensusStates prunes all expired tendermint consensus states. This function @@ -45,6 +44,8 @@ func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, stor clients = append(clients, clientID) } + // keep track of the total consensus states pruned so chains can + // understand how much space is saved when the migration is run var totalPruned int for _, clientID := range clients { @@ -61,13 +62,12 @@ func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, stor return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into tendermint client state") } - tmClientState, ok := clientState.(*ibctm.ClientState) + tmClientState, ok := clientState.(*ClientState) if !ok { return sdkerrors.Wrap(types.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") } - amtPruned := ibctm.PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) - totalPruned = totalPruned + amtPruned + totalPruned += PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) } clientLogger := ctx.Logger().With("module", "x/"+host.ModuleName+"/"+types.SubModuleName) diff --git a/modules/core/02-client/migrations/store_test.go b/modules/light-clients/07-tendermint/migrations_test.go similarity index 88% rename from modules/core/02-client/migrations/store_test.go rename to modules/light-clients/07-tendermint/migrations_test.go index f2bda003d2d..f9b6f2edc53 100644 --- a/modules/core/02-client/migrations/store_test.go +++ b/modules/light-clients/07-tendermint/migrations_test.go @@ -1,11 +1,8 @@ -package migrations_test +package tendermint_test import ( - "testing" "time" - "github.com/stretchr/testify/suite" - "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations" "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" @@ -14,29 +11,8 @@ import ( ibctesting "github.com/cosmos/ibc-go/v6/testing" ) -type MigrationsTestSuite struct { - suite.Suite - - coordinator *ibctesting.Coordinator - - chainA *ibctesting.TestChain - chainB *ibctesting.TestChain -} - -// TestMigrationsTestSuite runs all the tests within this package. -func TestMigrationsTestSuite(t *testing.T) { - suite.Run(t, new(MigrationsTestSuite)) -} - -// SetupTest creates a coordinator with 2 test chains. -func (suite *MigrationsTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) -} - // test pruning of multiple expired tendermint consensus states -func (suite *MigrationsTestSuite) TestPruneTendermintConsensusStates() { +func (suite *TendermintTestSuite) TestPruneTendermintConsensusStates() { // create multiple tendermint clients and a solo machine client // the solo machine is used to verify this pruning function only modifies // the tendermint store. From 4399a427dc04704b179b88843130f27891ceae1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:27:00 +0100 Subject: [PATCH 09/20] chore: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f70c712e94f..ace7aea41b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (light-clients/07-tendermint) [\#2800](https://github.com/cosmos/ibc-go/pull/2800) Add optional in-place store migration function to prune all expired tendermint consensus states. * (apps/27-interchain-accounts) [\#2147](https://github.com/cosmos/ibc-go/pull/2147) Adding a `SubmitTx` gRPC endpoint for the ICS27 Controller module which allows owners of interchain accounts to submit transactions. This replaces the previously existing need for authentication modules to implement this standard functionality. * (testing/simapp) [\#2190](https://github.com/cosmos/ibc-go/pull/2190) Adding the new `x/group` cosmos-sdk module to simapp. From 78fd0a31e5f28c326a833a0d003953eb508f5d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:29:27 +0100 Subject: [PATCH 10/20] chore: update imports --- modules/light-clients/07-tendermint/migrations.go | 8 ++++---- modules/light-clients/07-tendermint/migrations_test.go | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/light-clients/07-tendermint/migrations.go b/modules/light-clients/07-tendermint/migrations.go index a62b24eb81a..ba1ef6e2661 100644 --- a/modules/light-clients/07-tendermint/migrations.go +++ b/modules/light-clients/07-tendermint/migrations.go @@ -10,7 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" "github.com/cosmos/ibc-go/v6/modules/core/exported" ) @@ -53,7 +53,7 @@ func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, stor bz := clientStore.Get(host.ClientStateKey()) if bz == nil { - return types.ErrClientNotFound + return clienttypes.ErrClientNotFound } var clientState exported.ClientState @@ -63,13 +63,13 @@ func PruneTendermintConsensusStates(ctx sdk.Context, cdc codec.BinaryCodec, stor tmClientState, ok := clientState.(*ClientState) if !ok { - return sdkerrors.Wrap(types.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") + return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") } totalPruned += PruneAllExpiredConsensusStates(ctx, clientStore, cdc, tmClientState) } - clientLogger := ctx.Logger().With("module", "x/"+host.ModuleName+"/"+types.SubModuleName) + clientLogger := ctx.Logger().With("module", "x/"+host.ModuleName+"/"+clienttypes.SubModuleName) clientLogger.Info("pruned expired tendermint consensus states", "total", totalPruned) return nil diff --git a/modules/light-clients/07-tendermint/migrations_test.go b/modules/light-clients/07-tendermint/migrations_test.go index f9b6f2edc53..c7fe56af5db 100644 --- a/modules/light-clients/07-tendermint/migrations_test.go +++ b/modules/light-clients/07-tendermint/migrations_test.go @@ -3,8 +3,7 @@ package tendermint_test import ( "time" - "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations" - "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" "github.com/cosmos/ibc-go/v6/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" @@ -37,7 +36,7 @@ func (suite *TendermintTestSuite) TestPruneTendermintConsensusStates() { bz, err = suite.chainA.App.AppCodec().MarshalInterface(solomachine.ConsensusState()) suite.Require().NoError(err) - smHeight := types.NewHeight(0, 1) + smHeight := clienttypes.NewHeight(0, 1) smClientStore.Set(host.ConsensusStateKey(smHeight), bz) pruneHeightMap := make(map[*ibctesting.Path][]exported.Height) @@ -100,7 +99,7 @@ func (suite *TendermintTestSuite) TestPruneTendermintConsensusStates() { // This will cause the consensus states created before the first time increment // to be expired suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - err = migrations.PruneTendermintConsensusStates(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().GetKey(host.StoreKey)) + err = ibctm.PruneTendermintConsensusStates(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), suite.chainA.GetSimApp().GetKey(host.StoreKey)) suite.Require().NoError(err) for _, path := range paths { @@ -137,7 +136,7 @@ func (suite *TendermintTestSuite) TestPruneTendermintConsensusStates() { processedHeight, ok := ibctm.GetProcessedHeight(clientStore, height) suite.Require().True(ok) - suite.Require().NotEqual(types.ZeroHeight(), processedHeight) + suite.Require().NotEqual(clienttypes.ZeroHeight(), processedHeight) consKey := ibctm.GetIterationKey(clientStore, height) suite.Require().Equal(host.ConsensusStateKey(height), consKey) From 0f90c1ec39ab4e915aca716e93a096cbcc6ab215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:25:52 +0100 Subject: [PATCH 11/20] refactor: add automatic migrations for 02-client-refactor --- modules/core/02-client/keeper/migrations.go | 12 + .../02-client/migrations/v7/solomachine.go | 263 ++++++++++++++++++ .../migrations/{v6 => v7}/solomachine.pb.go | 176 ++++++------ modules/core/02-client/migrations/v7/store.go | 219 +++++++++++++++ .../02-client/migrations/v7/store_test.go | 148 ++++++++++ modules/core/24-host/parse.go | 23 ++ modules/core/keeper/migrations.go | 10 + modules/core/module.go | 6 +- .../solomachine/v2/solomachine.proto | 2 +- 9 files changed, 769 insertions(+), 90 deletions(-) create mode 100644 modules/core/02-client/migrations/v7/solomachine.go rename modules/core/02-client/migrations/{v6 => v7}/solomachine.pb.go (92%) create mode 100644 modules/core/02-client/migrations/v7/store.go create mode 100644 modules/core/02-client/migrations/v7/store_test.go diff --git a/modules/core/02-client/keeper/migrations.go b/modules/core/02-client/keeper/migrations.go index 0bf8cbd1875..31e294ea5da 100644 --- a/modules/core/02-client/keeper/migrations.go +++ b/modules/core/02-client/keeper/migrations.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" v100 "github.com/cosmos/ibc-go/v6/modules/core/02-client/legacy/v100" + "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v7" ) // Migrator is a struct for handling in-place store migrations. @@ -25,3 +26,14 @@ func NewMigrator(keeper Keeper) Migrator { func (m Migrator) Migrate1to2(ctx sdk.Context) error { return v100.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) } + +// Migrate2to3 migrates from version 2 to 3. +// This migration +// - migrates solo machine client states from v2 to v3 protobuf definition +// - prunes solo machine consensus states +// - removes the localhost client +// - asserts that existing tendermint clients are properly registered on the chain codec +// - adds iteration and processed height keys for unexpired tendermint consensus states +func (m Migrator) Migrate2to3(ctx sdk.Context) error { + return v7.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) +} diff --git a/modules/core/02-client/migrations/v7/solomachine.go b/modules/core/02-client/migrations/v7/solomachine.go new file mode 100644 index 00000000000..17520cd0065 --- /dev/null +++ b/modules/core/02-client/migrations/v7/solomachine.go @@ -0,0 +1,263 @@ +package v7 + +import ( + ics23 "github.com/confio/ics23/go" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v6/modules/core/exported" +) + +// NOTE: this is a mock implmentation for exported.ClientState. This implementation +// should only be registered on the InterfaceRegistry during cli command genesis migration. +// This implementation is only used to successfully unmarshal the previous solo machine +// client state and consensus state and migrate them to the new implementations. When the proto +// codec unmarshals, it calls UnpackInterfaces() to create a cached value of the any. The +// UnpackInterfaces function for IdenitifiedClientState will attempt to unpack the any to +// exported.ClientState. If the solomachine v1 type is not registered against the exported.ClientState +// the unmarshal will fail. This implementation will panic on every interface function. +// The same is done for the ConsensusState. + +// Interface implementation checks. +var ( + _, _ codectypes.UnpackInterfacesMessage = &ClientState{}, &ConsensusState{} + _ exported.ClientState = (*ClientState)(nil) + _ exported.ConsensusState = &ConsensusState{} +) + +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*exported.ClientState)(nil), + &ClientState{}, + ) + registry.RegisterImplementations( + (*exported.ConsensusState)(nil), + &ConsensusState{}, + ) +} + +// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method +func (cs ClientState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + return cs.ConsensusState.UnpackInterfaces(unpacker) +} + +// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method +func (cs ConsensusState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + return unpacker.UnpackAny(cs.PublicKey, new(cryptotypes.PubKey)) +} + +// ClientType panics! +func (cs ClientState) ClientType() string { + panic("legacy solo machine is deprecated!") +} + +// GetLatestHeight panics! +func (cs ClientState) GetLatestHeight() exported.Height { + panic("legacy solo machine is deprecated!") +} + +// Status panics! +func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) exported.Status { + panic("legacy solo machine is deprecated!") +} + +// Validate panics! +func (cs ClientState) Validate() error { + panic("legacy solo machine is deprecated!") +} + +// GetProofSpecs panics! +func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec { + panic("legacy solo machine is deprecated!") +} + +// ZeroCustomFields panics! +func (cs ClientState) ZeroCustomFields() exported.ClientState { + panic("legacy solo machine is deprecated!") +} + +// Initialize panics! +func (cs ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, consState exported.ConsensusState) error { + panic("legacy solo machine is deprecated!") +} + +// ExportMetadata panics! +func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata { + panic("legacy solo machine is deprecated!") +} + +// CheckForMisbehaviour panics! +func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, msg exported.ClientMessage) bool { + panic("legacy solo machine is deprecated!") +} + +// UpdateStateOnMisbehaviour panics! +func (cs *ClientState) UpdateStateOnMisbehaviour( + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, +) { + panic("legacy solo machine is deprecated!") +} + +// VerifyClientMessage panics! +func (cs *ClientState) VerifyClientMessage( + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, +) error { + panic("legacy solo machine is deprecated!") +} + +// UpdateState panis! +func (cs *ClientState) UpdateState(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage) []exported.Height { + panic("legacy solo machine is deprecated!") +} + +// CheckHeaderAndUpdateState panics! +func (cs *ClientState) CheckHeaderAndUpdateState( + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, +) (exported.ClientState, exported.ConsensusState, error) { + panic("legacy solo machine is deprecated!") +} + +// CheckMisbehaviourAndUpdateState panics! +func (cs ClientState) CheckMisbehaviourAndUpdateState( + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, +) (exported.ClientState, error) { + panic("legacy solo machine is deprecated!") +} + +// CheckSubstituteAndUpdateState panics! +func (cs ClientState) CheckSubstituteAndUpdateState( + ctx sdk.Context, _ codec.BinaryCodec, _, _ sdk.KVStore, + _ exported.ClientState, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyUpgradeAndUpdateState panics! +func (cs ClientState) VerifyUpgradeAndUpdateState( + _ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, + _ exported.ClientState, _ exported.ConsensusState, _, _ []byte, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyClientState panics! +func (cs ClientState) VerifyClientState( + store sdk.KVStore, cdc codec.BinaryCodec, + _ exported.Height, _ exported.Prefix, _ string, _ []byte, clientState exported.ClientState, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyClientConsensusState panics! +func (cs ClientState) VerifyClientConsensusState( + sdk.KVStore, codec.BinaryCodec, + exported.Height, string, exported.Height, exported.Prefix, + []byte, exported.ConsensusState, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyConnectionState panics! +func (cs ClientState) VerifyConnectionState( + sdk.KVStore, codec.BinaryCodec, exported.Height, + exported.Prefix, []byte, string, exported.ConnectionI, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyChannelState panics! +func (cs ClientState) VerifyChannelState( + sdk.KVStore, codec.BinaryCodec, exported.Height, exported.Prefix, + []byte, string, string, exported.ChannelI, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyPacketCommitment panics! +func (cs ClientState) VerifyPacketCommitment( + sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height, + uint64, uint64, exported.Prefix, []byte, + string, string, uint64, []byte, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyPacketAcknowledgement panics! +func (cs ClientState) VerifyPacketAcknowledgement( + sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height, + uint64, uint64, exported.Prefix, []byte, + string, string, uint64, []byte, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyPacketReceiptAbsence panics! +func (cs ClientState) VerifyPacketReceiptAbsence( + sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height, + uint64, uint64, exported.Prefix, []byte, + string, string, uint64, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyNextSequenceRecv panics! +func (cs ClientState) VerifyNextSequenceRecv( + sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height, + uint64, uint64, exported.Prefix, []byte, + string, string, uint64, +) error { + panic("legacy solo machine is deprecated!") +} + +// GetTimestampAtHeight panics! +func (cs ClientState) GetTimestampAtHeight( + sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height, +) (uint64, error) { + panic("legacy solo machine is deprecated!") +} + +// VerifyMembership panics! +func (cs *ClientState) VerifyMembership( + ctx sdk.Context, + clientStore sdk.KVStore, + cdc codec.BinaryCodec, + height exported.Height, + delayTimePeriod uint64, + delayBlockPeriod uint64, + proof []byte, + path exported.Path, + value []byte, +) error { + panic("legacy solo machine is deprecated!") +} + +// VerifyNonMembership panics! +func (cs *ClientState) VerifyNonMembership( + ctx sdk.Context, + clientStore sdk.KVStore, + cdc codec.BinaryCodec, + height exported.Height, + delayTimePeriod uint64, + delayBlockPeriod uint64, + proof []byte, + path exported.Path, +) error { + panic("legacy solo machine is deprecated") +} + +// ClientType panics! +func (ConsensusState) ClientType() string { + panic("legacy solo machine is deprecated!") +} + +// GetTimestamp panics! +func (cs ConsensusState) GetTimestamp() uint64 { + panic("legacy solo machine is deprecated!") +} + +// ValidateBasic panics! +func (cs ConsensusState) ValidateBasic() error { + panic("legacy solo machine is deprecated!") +} diff --git a/modules/core/02-client/migrations/v6/solomachine.pb.go b/modules/core/02-client/migrations/v7/solomachine.pb.go similarity index 92% rename from modules/core/02-client/migrations/v6/solomachine.pb.go rename to modules/core/02-client/migrations/v7/solomachine.pb.go index 573b0b577b9..bd6d9d61657 100644 --- a/modules/core/02-client/migrations/v6/solomachine.pb.go +++ b/modules/core/02-client/migrations/v7/solomachine.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: ibc/lightclients/solomachine/v2/solomachine.proto -package v6 +package v7 import ( fmt "fmt" @@ -823,93 +823,93 @@ func init() { } var fileDescriptor_141333b361aae010 = []byte{ - // 1374 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0xdf, 0x8e, 0xdb, 0x44, - 0x17, 0x5f, 0xa7, 0xe9, 0x76, 0x33, 0xd9, 0xee, 0xe6, 0x73, 0xd3, 0x36, 0xeb, 0x56, 0x89, 0x3f, - 0x23, 0xca, 0x82, 0x68, 0xcc, 0x2e, 0x62, 0x85, 0x2a, 0x04, 0x75, 0x1c, 0x97, 0xa6, 0xdd, 0xf5, -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0x20, 0xb1, - 0xbf, 0x27, 0xb6, 0x91, 0xdd, 0x6b, 0x41, 0x8f, 0xfc, 0xd2, 0xbc, 0xb5, 0x7b, 0x93, 0x8c, 0x44, - 0xb1, 0xed, 0x34, 0xba, 0xa6, 0x3f, 0x13, 0x3c, 0xb1, 0xbf, 0x57, 0x5f, 0x0d, 0x26, 0xd9, 0xdb, - 0x7f, 0x06, 0x00, 0x00, 0xff, 0xff, 0x29, 0x02, 0x33, 0x3e, 0x7a, 0x0d, 0x00, 0x00, + // 1373 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x5f, 0x8f, 0xdb, 0x44, + 0x10, 0x3f, 0xa7, 0xe9, 0xf5, 0xb2, 0xb9, 0xde, 0x05, 0x37, 0x6d, 0x73, 0x6e, 0x95, 0x18, 0x23, + 0xca, 0x81, 0x68, 0xcc, 0x1d, 0xa2, 0xa0, 0x0a, 0x41, 0x1d, 0xc7, 0xa5, 0x69, 0xef, 0x7c, 0xc1, + 0xf1, 0x01, 0xad, 0x90, 0x2c, 0xc7, 0xde, 0x4b, 0xac, 0x26, 0xde, 0x34, 0xde, 0x24, 0x0d, 0x12, + 0x12, 0xe2, 0xa9, 0x44, 0x3c, 0xf0, 0x05, 0x22, 0x21, 0x10, 0x9f, 0x83, 0x37, 0xe0, 0xb1, 0x8f, + 0x3c, 0x05, 0xd4, 0x7e, 0x83, 0x7c, 0x02, 0x64, 0xef, 0x26, 0xb6, 0x73, 0xbd, 0x9c, 0xf8, 0xf7, + 0xb6, 0x3b, 0xbf, 0x99, 0xdf, 0xcc, 0xce, 0x8c, 0x67, 0xd7, 0x60, 0xc7, 0xa9, 0x5b, 0x62, 0xcb, + 0x69, 0x34, 0xb1, 0xd5, 0x72, 0xa0, 0x8b, 0x3d, 0xd1, 0x43, 0x2d, 0xd4, 0x36, 0xad, 0xa6, 0xe3, + 0x42, 0xb1, 0xbf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59, 0x82, 0x52, 0x90, 0x62, 0xec, 0x0d, + 0x70, 0x35, 0xb4, 0x57, 0x95, 0xcf, 0x74, 0xa3, 0xa6, 0x7c, 0x7c, 0xe8, 0x43, 0x3e, 0xcd, 0x27, + 0x99, 0x35, 0x12, 0xb8, 0x8f, 0xcc, 0x00, 0x5f, 0xce, 0xf2, 0x20, 0x13, 0xda, 0xdd, 0x51, 0xa4, + 0xb2, 0xa2, 0x65, 0x52, 0xa4, 0x32, 0x64, 0xc7, 0x25, 0x9f, 0xfc, 0x98, 0x5f, 0x29, 0x3d, 0xf8, + 0xed, 0x59, 0x9e, 0x79, 0xfa, 0x2c, 0xcf, 0xfc, 0xf9, 0x2c, 0xcf, 0x7c, 0xf7, 0x3c, 0xbf, 0xf2, + 0xf4, 0x79, 0x7e, 0xe5, 0xf7, 0xe7, 0xf9, 0x95, 0x07, 0xb7, 0x1a, 0x0e, 0x6e, 0xf6, 0xea, 0x45, + 0x0b, 0xb5, 0x45, 0x0b, 0x79, 0x6d, 0xe4, 0x89, 0x4e, 0xdd, 0xba, 0xde, 0x40, 0x62, 0xff, 0x86, + 0xd8, 0x46, 0x76, 0xaf, 0x05, 0x3d, 0xf2, 0x4b, 0xf3, 0xd6, 0xee, 0x75, 0x32, 0x12, 0xc5, 0xb6, + 0xd3, 0xe8, 0x9a, 0xfe, 0x4c, 0xf0, 0xc4, 0xfe, 0xbb, 0xf5, 0xd5, 0x60, 0x92, 0xbd, 0xfd, 0x57, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x6a, 0x16, 0x48, 0x29, 0x7a, 0x0d, 0x00, 0x00, } func (m *ClientState) Marshal() (dAtA []byte, err error) { diff --git a/modules/core/02-client/migrations/v7/store.go b/modules/core/02-client/migrations/v7/store.go new file mode 100644 index 00000000000..d478c190e81 --- /dev/null +++ b/modules/core/02-client/migrations/v7/store.go @@ -0,0 +1,219 @@ +package v7 + +import ( + "fmt" + "strings" + + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + "github.com/cosmos/ibc-go/v6/modules/core/exported" + solomachine "github.com/cosmos/ibc-go/v6/modules/light-clients/06-solomachine" + ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" +) + +// Localhost is the client type for a localhost client. It is also used as the clientID +// for the localhost client. +const Localhost string = "09-localhost" + +// MigrateStore performs in-place store migrations from ibc-go v6 to ibc-go v7. +// The migration includes: +// +// - Migrating solo machine client states from v2 to v3 protobuf definition +// - Pruning all solo machine consensus states +// - Removing the localhost client +// - Asserting existing tendermint clients are properly registered on the chain codec +func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { + store := ctx.KVStore(storeKey) + + if err := handleSolomachineMigration(ctx, store, cdc); err != nil { + return err + } + + if err := handleTendermintMigration(ctx, store, cdc); err != nil { + return err + } + + if err := handleLocalhostMigration(ctx, store, cdc); err != nil { + return err + } + + return nil +} + +// handleSolomachineMigration iterates over the solo machine clients and migrates client state from +// protobuf definition v2 to v3. All associated consensus states stored separately are pruned. +func handleSolomachineMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec) error { + clients, err := collectClients(ctx, store, exported.Solomachine) + if err != nil { + return err + } + + for _, clientID := range clients { + clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) + clientStore := prefix.NewStore(store, clientPrefix) + + bz := clientStore.Get(host.ClientStateKey()) + if bz == nil { + return clienttypes.ErrClientNotFound + } + + any := &codectypes.Any{} + if err := cdc.Unmarshal(bz, any); err != nil { + return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + } + + clientState := &ClientState{} + if err := cdc.Unmarshal(any.Value, clientState); err != nil { + return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + } + + updatedClientState := migrateSolomachine(clientState) + + bz, err := clienttypes.MarshalClientState(cdc, updatedClientState) + if err != nil { + return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state") + } + + // update solomachine in store + clientStore.Set(host.ClientStateKey(), bz) + + pruneClientConsensusStates(clientStore) + } + + return nil +} + +// handlerTendermintMigration asserts that the tendermint client in state can be decoded properly. +// This ensures the upgrading chain properly registered the tendermint client types on the chain codec. +func handleTendermintMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec) error { + clients, err := collectClients(ctx, store, exported.Tendermint) + if err != nil { + return err + } + + if len(clients) > 1 { + return sdkerrors.Wrap(sdkerrors.ErrLogic, "too many tendermint clients collected") + } + + clientID := clients[0] + + clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) + clientStore := prefix.NewStore(store, clientPrefix) + + bz := clientStore.Get(host.ClientStateKey()) + if bz == nil { + return clienttypes.ErrClientNotFound + } + + var clientState exported.ClientState + if err := cdc.UnmarshalInterface(bz, &clientState); err != nil { + return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into tendermint client state") + } + + _, ok := clientState.(*ibctm.ClientState) + if !ok { + return sdkerrors.Wrap(clienttypes.ErrInvalidClient, "client state is not tendermint even though client id contains 07-tendermint") + } + + return nil +} + +// handleLocalhostMigration removes all client and consensus states associated with the localhost client type. +func handleLocalhostMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec) error { + clients, err := collectClients(ctx, store, Localhost) + if err != nil { + return err + } + + for _, clientID := range clients { + clientPrefix := []byte(fmt.Sprintf("%s/%s/", host.KeyClientStorePrefix, clientID)) + clientStore := prefix.NewStore(store, clientPrefix) + + // delete the client state + clientStore.Delete(host.ClientStateKey()) + + pruneClientConsensusStates(clientStore) + } + + return nil +} + +// collectClients will iterate over the provided client type prefix in the client store +// and return a list of clientIDs associated with the client type. This is necessary to +// avoid state corruption as modifying state during iteration is unsafe. A special case +// for tendermint clients is included as only one tendermint clientID is required for +// this migration.. +func collectClients(ctx sdk.Context, store sdk.KVStore, clientType string) (clients []string, err error) { + clientPrefix := []byte(fmt.Sprintf("%s/%s", host.KeyClientStorePrefix, clientType)) + iterator := sdk.KVStorePrefixIterator(store, clientPrefix) + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + path := string(iterator.Key()) + if !strings.Contains(path, host.KeyClientState) { + // skip non client state keys + continue + } + + clientID, err := host.ParseClientStatePath(path) + if err != nil { + return nil, err + } + + clients = append(clients, clientID) + + // optimization: exist after a single tendermint client iteration + if strings.Contains(clientID, exported.Tendermint) { + return clients, nil + } + } + + return clients, nil +} + +// pruneClientConsensusStates removes all client consensus states from the associated +// client store which is keyed by the clientID. +func pruneClientConsensusStates(clientStore sdk.KVStore) { + iterator := sdk.KVStorePrefixIterator(clientStore, []byte(host.KeyConsensusStatePrefix)) + var heights []exported.Height + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + keySplit := strings.Split(string(iterator.Key()), "/") + // key is in the format "consensusStates/" + if len(keySplit) != 2 || keySplit[0] != string(host.KeyConsensusStatePrefix) { + continue + } + + // collect consensus states to be pruned + heights = append(heights, clienttypes.MustParseHeight(keySplit[1])) + } + + // delete all consensus states + for _, height := range heights { + clientStore.Delete(host.ConsensusStateKey(height)) + } +} + +// migrateSolomachine migrates the solomachine from v2 to v3 solo machine protobuf definition. +// Notably it drops the AllowUpdateAfterProposal field. +func migrateSolomachine(clientState *ClientState) *solomachine.ClientState { + consensusState := &solomachine.ConsensusState{ + PublicKey: clientState.ConsensusState.PublicKey, + Diversifier: clientState.ConsensusState.Diversifier, + Timestamp: clientState.ConsensusState.Timestamp, + } + + return &solomachine.ClientState{ + Sequence: clientState.Sequence, + IsFrozen: clientState.IsFrozen, + ConsensusState: consensusState, + } +} diff --git a/modules/core/02-client/migrations/v7/store_test.go b/modules/core/02-client/migrations/v7/store_test.go new file mode 100644 index 00000000000..e7b7308aa5b --- /dev/null +++ b/modules/core/02-client/migrations/v7/store_test.go @@ -0,0 +1,148 @@ +package v7_test + +import ( + "strconv" + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v7" + "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + ibctesting "github.com/cosmos/ibc-go/v6/testing" +) + +// numCreations is the number of clients/consensus states created for +// solo machine and localhost clients +const numCreations = 10 + +type MigrationsV7TestSuite struct { + suite.Suite + + coordinator *ibctesting.Coordinator + + chainA *ibctesting.TestChain + chainB *ibctesting.TestChain +} + +func (suite *MigrationsV7TestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) + + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) +} + +func TestIBCTestSuite(t *testing.T) { + suite.Run(t, new(MigrationsV7TestSuite)) +} + +// create multiple solo machine clients, tendermint and localhost clients +// ensure that solo machine clients are migrated and their cosnensus states are removed +// ensure the localhost is deleted entirely. +func (suite *MigrationsV7TestSuite) TestMigrateStore() { + paths := []*ibctesting.Path{ + ibctesting.NewPath(suite.chainA, suite.chainB), + ibctesting.NewPath(suite.chainA, suite.chainB), + } + + // create tendermint clients + for _, path := range paths { + suite.coordinator.SetupClients(path) + } + + solomachines := []*ibctesting.Solomachine{ + ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "06-solomachine-0", "testing", 1), + ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "06-solomachine-1", "testing", 4), + } + + suite.createSolomachineClients(solomachines) + suite.createLocalhostClients() + + err := v7.MigrateStore(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetKey(host.StoreKey), suite.chainA.App.AppCodec()) + suite.Require().NoError(err) + + suite.assertSolomachineClients(solomachines) + suite.assertLocalhostClients() +} + +func (suite *MigrationsV7TestSuite) createSolomachineClients(solomachines []*ibctesting.Solomachine) { + // manually generate old proto buf definitions and set in store + // NOTE: we cannot use 'CreateClient' and 'UpdateClient' functions since we are + // using client states and consensus states which do not implement the exported.ClientState + // and exported.ConsensusState interface + for _, sm := range solomachines { + clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), sm.ClientID) + clientState := sm.ClientState() + + // generate old client state proto definition + legacyClientState := &v7.ClientState{ + Sequence: clientState.Sequence, + ConsensusState: &v7.ConsensusState{ + PublicKey: clientState.ConsensusState.PublicKey, + Diversifier: clientState.ConsensusState.Diversifier, + Timestamp: clientState.ConsensusState.Timestamp, + }, + AllowUpdateAfterProposal: true, + } + + // set client state + bz, err := suite.chainA.App.AppCodec().MarshalInterface(legacyClientState) + suite.Require().NoError(err) + clientStore.Set(host.ClientStateKey(), bz) + + bz, err = suite.chainA.App.AppCodec().MarshalInterface(legacyClientState.ConsensusState) + suite.Require().NoError(err) + + // set some consensus states + for i := uint64(0); i < numCreations; i++ { + height := types.NewHeight(1, i) + clientStore.Set(host.ConsensusStateKey(height), bz) + } + + } +} + +func (suite *MigrationsV7TestSuite) assertSolomachineClients(solomachines []*ibctesting.Solomachine) { + // verify client state has been migrated + for _, sm := range solomachines { + clientState, ok := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), sm.ClientID) + suite.Require().True(ok) + suite.Require().Equal(sm.ClientState(), clientState) + + for i := uint64(0); i < numCreations; i++ { + height := types.NewHeight(1, i) + + consState, ok := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientConsensusState(suite.chainA.GetContext(), sm.ClientID, height) + suite.Require().False(ok) + suite.Require().Empty(consState) + } + } +} + +// createLocalhostClients clients creates multiple localhost clients and multiple consensus states for each +func (suite *MigrationsV7TestSuite) createLocalhostClients() { + for numClients := uint64(0); numClients < numCreations; numClients++ { + clientID := v7.Localhost + "-" + strconv.FormatUint(numClients, 10) + clientStore := suite.chainA.GetSimApp().IBCKeeper.ClientKeeper.ClientStore(suite.chainA.GetContext(), clientID) + + clientStore.Set(host.ClientStateKey(), []byte("clientState")) + + for i := 0; i < numCreations; i++ { + clientStore.Set(host.ConsensusStateKey(types.NewHeight(1, uint64(i))), []byte("consensusState")) + } + } +} + +// assertLocalhostClients asserts that all localhost information has been deleted +func (suite *MigrationsV7TestSuite) assertLocalhostClients() { + for numClients := uint64(0); numClients < numCreations; numClients++ { + clientID := v7.Localhost + "-" + strconv.FormatUint(numClients, 10) + clientStore := suite.chainA.GetSimApp().IBCKeeper.ClientKeeper.ClientStore(suite.chainA.GetContext(), clientID) + + suite.Require().False(clientStore.Has(host.ClientStateKey())) + + for i := uint64(0); i < numCreations; i++ { + suite.Require().False(clientStore.Has(host.ConsensusStateKey(types.NewHeight(1, i)))) + } + } +} diff --git a/modules/core/24-host/parse.go b/modules/core/24-host/parse.go index 8c3459500d9..37ae8e1460d 100644 --- a/modules/core/24-host/parse.go +++ b/modules/core/24-host/parse.go @@ -32,6 +32,29 @@ func ParseIdentifier(identifier, prefix string) (uint64, error) { return sequence, nil } +// ParseClientStatePath returns the client ID from a client state path. It returns +// an error if the provided path is invalid. +func ParseClientStatePath(path string) (string, error) { + split := strings.Split(path, "/") + if len(split) != 3 { + return "", sdkerrors.Wrapf(ErrInvalidPath, "cannot parse client state path %s", path) + } + + if split[0] != string(KeyClientStorePrefix) { + return "", sdkerrors.Wrapf(ErrInvalidPath, "path does not begin with client store prefix: expected %s, got %s", KeyClientStorePrefix, split[0]) + } + + if split[2] != KeyClientState { + return "", sdkerrors.Wrapf(ErrInvalidPath, "path does not end with client state key: expected %s, got %s", KeyClientState, split[2]) + } + + if strings.TrimSpace(split[1]) == "" { + return "", sdkerrors.Wrap(ErrInvalidPath, "clientID is empty") + } + + return split[1], nil +} + // ParseConnectionPath returns the connection ID from a full path. It returns // an error if the provided path is invalid. func ParseConnectionPath(path string) (string, error) { diff --git a/modules/core/keeper/migrations.go b/modules/core/keeper/migrations.go index 2984ad9c016..2182b1ade64 100644 --- a/modules/core/keeper/migrations.go +++ b/modules/core/keeper/migrations.go @@ -30,3 +30,13 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error { return nil } + +// Migrate2to3 migrates from version 2 to 3. 02-client migrations are performed. +func (m Migrator) Migrate2to3(ctx sdk.Context) error { + clientMigrator := clientkeeper.NewMigrator(m.keeper.ClientKeeper) + if err := clientMigrator.Migrate2to3(ctx); err != nil { + return err + } + + return nil +} diff --git a/modules/core/module.go b/modules/core/module.go index dc46d4718b1..02cc5e2b3fc 100644 --- a/modules/core/module.go +++ b/modules/core/module.go @@ -144,6 +144,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err != nil { panic(err) } + err = cfg.RegisterMigration(host.ModuleName, 2, m.Migrate2to3) + if err != nil { + panic(err) + } } // InitGenesis performs genesis initialization for the ibc module. It returns @@ -165,7 +169,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 2 } +func (AppModule) ConsensusVersion() uint64 { return 3 } // BeginBlock returns the begin blocker for the ibc module. func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { diff --git a/proto/ibc/lightclients/solomachine/v2/solomachine.proto b/proto/ibc/lightclients/solomachine/v2/solomachine.proto index faf71334711..6964404dd14 100644 --- a/proto/ibc/lightclients/solomachine/v2/solomachine.proto +++ b/proto/ibc/lightclients/solomachine/v2/solomachine.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package ibc.lightclients.solomachine.v2; -option go_package = "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v6"; +option go_package = "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v7"; import "ibc/core/connection/v1/connection.proto"; import "ibc/core/channel/v1/channel.proto"; From 9d7c04871a306098b33c6a274575b7525f710b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:38:45 +0100 Subject: [PATCH 12/20] review: apply self nits --- modules/core/02-client/keeper/migrations.go | 1 - modules/core/02-client/migrations/v7/store.go | 6 +++--- modules/core/keeper/migrations.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/core/02-client/keeper/migrations.go b/modules/core/02-client/keeper/migrations.go index 31e294ea5da..7da99213ec0 100644 --- a/modules/core/02-client/keeper/migrations.go +++ b/modules/core/02-client/keeper/migrations.go @@ -33,7 +33,6 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error { // - prunes solo machine consensus states // - removes the localhost client // - asserts that existing tendermint clients are properly registered on the chain codec -// - adds iteration and processed height keys for unexpired tendermint consensus states func (m Migrator) Migrate2to3(ctx sdk.Context) error { return v7.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) } diff --git a/modules/core/02-client/migrations/v7/store.go b/modules/core/02-client/migrations/v7/store.go index d478c190e81..628b5cf9900 100644 --- a/modules/core/02-client/migrations/v7/store.go +++ b/modules/core/02-client/migrations/v7/store.go @@ -48,7 +48,7 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar } // handleSolomachineMigration iterates over the solo machine clients and migrates client state from -// protobuf definition v2 to v3. All associated consensus states stored separately are pruned. +// protobuf definition v2 to v3. All consensus states stored outside of the client state are pruned. func handleSolomachineMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec) error { clients, err := collectClients(ctx, store, exported.Solomachine) if err != nil { @@ -149,7 +149,7 @@ func handleLocalhostMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bina // and return a list of clientIDs associated with the client type. This is necessary to // avoid state corruption as modifying state during iteration is unsafe. A special case // for tendermint clients is included as only one tendermint clientID is required for -// this migration.. +// v7 migrations. func collectClients(ctx sdk.Context, store sdk.KVStore, clientType string) (clients []string, err error) { clientPrefix := []byte(fmt.Sprintf("%s/%s", host.KeyClientStorePrefix, clientType)) iterator := sdk.KVStorePrefixIterator(store, clientPrefix) @@ -179,7 +179,7 @@ func collectClients(ctx sdk.Context, store sdk.KVStore, clientType string) (clie } // pruneClientConsensusStates removes all client consensus states from the associated -// client store which is keyed by the clientID. +// client store. func pruneClientConsensusStates(clientStore sdk.KVStore) { iterator := sdk.KVStorePrefixIterator(clientStore, []byte(host.KeyConsensusStatePrefix)) var heights []exported.Height diff --git a/modules/core/keeper/migrations.go b/modules/core/keeper/migrations.go index 2182b1ade64..0885dbb7ad9 100644 --- a/modules/core/keeper/migrations.go +++ b/modules/core/keeper/migrations.go @@ -31,7 +31,7 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error { return nil } -// Migrate2to3 migrates from version 2 to 3. 02-client migrations are performed. +// Migrate2to3 migrates from version 2 to 3. See 02-client keeper function Migrate2to3. func (m Migrator) Migrate2to3(ctx sdk.Context) error { clientMigrator := clientkeeper.NewMigrator(m.keeper.ClientKeeper) if err := clientMigrator.Migrate2to3(ctx); err != nil { From fa08b6379be20fe2d2411c2117d0a30b89c94b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:40:21 +0100 Subject: [PATCH 13/20] chore: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42057e1a1b0..4c0164722ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -115,6 +115,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* (core/02-client) [\#2819](https://github.com/cosmos/ibc-go/pull/2819) Add automatic in-place store migrations to remove the localhost client and migrate existing solo machine definitions. * (apps/27-interchain-accounts) [\#2147](https://github.com/cosmos/ibc-go/pull/2147) Adding a `SubmitTx` gRPC endpoint for the ICS27 Controller module which allows owners of interchain accounts to submit transactions. This replaces the previously existing need for authentication modules to implement this standard functionality. * (testing/simapp) [\#2190](https://github.com/cosmos/ibc-go/pull/2190) Adding the new `x/group` cosmos-sdk module to simapp. From ae2b1c22a712362a282278cdcf305a1d505d0a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 23 Nov 2022 16:29:57 +0100 Subject: [PATCH 14/20] test: add an additional test for improperly registered codecs --- .../02-client/migrations/v7/store_test.go | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/core/02-client/migrations/v7/store_test.go b/modules/core/02-client/migrations/v7/store_test.go index e7b7308aa5b..c1ced29fcfb 100644 --- a/modules/core/02-client/migrations/v7/store_test.go +++ b/modules/core/02-client/migrations/v7/store_test.go @@ -4,11 +4,15 @@ import ( "strconv" "testing" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/stretchr/testify/suite" "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v7" "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + solomachine "github.com/cosmos/ibc-go/v6/modules/light-clients/06-solomachine" + ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v6/testing" ) @@ -36,6 +40,23 @@ func TestIBCTestSuite(t *testing.T) { suite.Run(t, new(MigrationsV7TestSuite)) } +// test that MigrateStore returns an error if the codec used doesn't register tendermint types +func (suite *MigrationsV7TestSuite) TestMigrateStoreTendermint() { + path := ibctesting.NewPath(suite.chainA, suite.chainB) + suite.coordinator.SetupClients(path) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + solomachine.RegisterInterfaces(registry) + err := v7.MigrateStore(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetKey(host.StoreKey), cdc) + suite.Require().Error(err) + + ibctm.RegisterInterfaces(registry) + err = v7.MigrateStore(suite.chainA.GetContext(), suite.chainA.GetSimApp().GetKey(host.StoreKey), cdc) + suite.Require().NoError(err) +} + // create multiple solo machine clients, tendermint and localhost clients // ensure that solo machine clients are migrated and their cosnensus states are removed // ensure the localhost is deleted entirely. From 20e4d8d5813799d1d454d63c6ded98739677dd38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 23 Nov 2022 16:43:17 +0100 Subject: [PATCH 15/20] chore: update migration doc header --- docs/migrations/v6-to-v7.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migrations/v6-to-v7.md b/docs/migrations/v6-to-v7.md index 88c6e3d3dcc..e5b2ed04759 100644 --- a/docs/migrations/v6-to-v7.md +++ b/docs/migrations/v6-to-v7.md @@ -1,4 +1,4 @@ -# Migrating from ibc-go v5 to v6 +# Migrating from ibc-go v6 to v7 This document is intended to highlight significant changes which may require more information than presented in the CHANGELOG. Any changes that must be done by a user of ibc-go should be documented here. From d828218d52e8652f1cbbe81ce8d706390d6a2e89 Mon Sep 17 00:00:00 2001 From: Charly Date: Tue, 29 Nov 2022 14:50:56 +0100 Subject: [PATCH 16/20] create upgrade handler and call handler in app.go of simapp --- testing/simapp/app.go | 12 ++++++++ testing/simapp/upgrades/v7/upgrades.go | 38 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 testing/simapp/upgrades/v7/upgrades.go diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 702531b4996..4be7e1f8afd 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -113,6 +113,7 @@ import ( simappparams "github.com/cosmos/ibc-go/v6/testing/simapp/params" simappupgrades "github.com/cosmos/ibc-go/v6/testing/simapp/upgrades" v6 "github.com/cosmos/ibc-go/v6/testing/simapp/upgrades/v6" + v7 "github.com/cosmos/ibc-go/v6/testing/simapp/upgrades/v7" ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types" ) @@ -887,4 +888,15 @@ func (app *SimApp) setupUpgradeHandlers() { ibcmock.ModuleName+icacontrollertypes.SubModuleName, ), ) + + app.UpgradeKeeper.SetUpgradeHandler( + v7.UpgradeName, + v7.CreateUpgradeHandler( + app.mm, + app.configurator, + app.appCodec, + app.keys[ibchost.StoreKey], + ibcmock.ModuleName+icahosttypes.SubModuleName, + ), + ) } diff --git a/testing/simapp/upgrades/v7/upgrades.go b/testing/simapp/upgrades/v7/upgrades.go new file mode 100644 index 00000000000..8611ebc3995 --- /dev/null +++ b/testing/simapp/upgrades/v7/upgrades.go @@ -0,0 +1,38 @@ +package v7 + +import ( + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" + v7 "github.com/cosmos/ibc-go/v7/modules/core/02-client/migrations/v7" +) + +const ( + // UpgradeName defines the on-chain upgrade name for the SimApp v7 upgrade. + UpgradeName = "v7" +) + +// CreateUpgradeHandler creates an upgrade handler for the v7 SimApp upgrade. +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + cdc codec.BinaryCodec, + hostStoreKey *storetypes.KVStoreKey, + moduleName string, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + // Perform in-place store migrations for the v7 upgrade + if err := v7.MigrateStore(ctx, hostStoreKey, cdc); err != nil { + return nil, err + } + + // OPTIONAL: prune expired tendermint consensus states to save storage space + ibctm.PruneTendermintConsensusStates(ctx, cdc, host.StoreKey) + return mm.RunMigrations(ctx, configurator, vm) + } +} From fddd991c62b4583db8bc45d70adccdce262d3f48 Mon Sep 17 00:00:00 2001 From: Charly Date: Wed, 30 Nov 2022 11:06:15 +0100 Subject: [PATCH 17/20] update to main --- testing/simapp/upgrades/v7/upgrades.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/testing/simapp/upgrades/v7/upgrades.go b/testing/simapp/upgrades/v7/upgrades.go index 8611ebc3995..fdb5e1f150b 100644 --- a/testing/simapp/upgrades/v7/upgrades.go +++ b/testing/simapp/upgrades/v7/upgrades.go @@ -7,9 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + v7 "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v7" ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" - v7 "github.com/cosmos/ibc-go/v7/modules/core/02-client/migrations/v7" ) const ( @@ -32,7 +31,7 @@ func CreateUpgradeHandler( } // OPTIONAL: prune expired tendermint consensus states to save storage space - ibctm.PruneTendermintConsensusStates(ctx, cdc, host.StoreKey) + ibctm.PruneTendermintConsensusStates(ctx, cdc, hostStoreKey) return mm.RunMigrations(ctx, configurator, vm) } } From d85e8c7fd9d65f2460c0add7b7d09d0b6499d0c7 Mon Sep 17 00:00:00 2001 From: Charly Date: Wed, 30 Nov 2022 11:08:17 +0100 Subject: [PATCH 18/20] err check for tendermint consensus state pruning --- testing/simapp/upgrades/v7/upgrades.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/simapp/upgrades/v7/upgrades.go b/testing/simapp/upgrades/v7/upgrades.go index fdb5e1f150b..1a8b15554f8 100644 --- a/testing/simapp/upgrades/v7/upgrades.go +++ b/testing/simapp/upgrades/v7/upgrades.go @@ -31,7 +31,9 @@ func CreateUpgradeHandler( } // OPTIONAL: prune expired tendermint consensus states to save storage space - ibctm.PruneTendermintConsensusStates(ctx, cdc, hostStoreKey) + if err := ibctm.PruneTendermintConsensusStates(ctx, cdc, hostStoreKey); err != nil { + return nil, err + } return mm.RunMigrations(ctx, configurator, vm) } } From 9d732f816d1a0975dfeb4695e3b9f60b77c5389d Mon Sep 17 00:00:00 2001 From: Charly Date: Wed, 30 Nov 2022 11:18:12 +0100 Subject: [PATCH 19/20] add comments, rm unnecessary moduleName --- testing/simapp/app.go | 1 - testing/simapp/upgrades/v7/upgrades.go | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index b4724b591e7..633199155e7 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -900,7 +900,6 @@ func (app *SimApp) setupUpgradeHandlers() { app.configurator, app.appCodec, app.keys[ibchost.StoreKey], - ibcmock.ModuleName+icahosttypes.SubModuleName, ), ) } diff --git a/testing/simapp/upgrades/v7/upgrades.go b/testing/simapp/upgrades/v7/upgrades.go index 1a8b15554f8..6dda8cab4bb 100644 --- a/testing/simapp/upgrades/v7/upgrades.go +++ b/testing/simapp/upgrades/v7/upgrades.go @@ -22,10 +22,15 @@ func CreateUpgradeHandler( configurator module.Configurator, cdc codec.BinaryCodec, hostStoreKey *storetypes.KVStoreKey, - moduleName string, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { // Perform in-place store migrations for the v7 upgrade + // The migration includes: + // + // - Migrating solo machine client states from v2 to v3 protobuf definition + // - Pruning all solo machine consensus states + // - Removing the localhost client + // - Asserting existing tendermint clients are properly registered on the chain codec if err := v7.MigrateStore(ctx, hostStoreKey, cdc); err != nil { return nil, err } From 2b5b10de2cad069d276296b904e2e5fad4486db6 Mon Sep 17 00:00:00 2001 From: Charly Date: Wed, 30 Nov 2022 17:45:36 +0100 Subject: [PATCH 20/20] fix re: pr comments --- CHANGELOG.md | 1 + testing/simapp/upgrades/v7/upgrades.go | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71629f83a02..6e7fc445774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,6 +122,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (core/24-host) [\#2820](https://github.com/cosmos/ibc-go/pull/2820) Add `MustParseClientStatePath` which parses the clientID from a client state key path. * (apps/27-interchain-accounts) [\#2147](https://github.com/cosmos/ibc-go/pull/2147) Adding a `SubmitTx` gRPC endpoint for the ICS27 Controller module which allows owners of interchain accounts to submit transactions. This replaces the previously existing need for authentication modules to implement this standard functionality. * (testing/simapp) [\#2190](https://github.com/cosmos/ibc-go/pull/2190) Adding the new `x/group` cosmos-sdk module to simapp. +* (testing/simapp) [\#2842](https://github.com/cosmos/ibc-go/pull/2842) Adding the new upgrade handler for v6 -> v7 to simapp which prunes expired Tendermint consensus states. ### Bug Fixes diff --git a/testing/simapp/upgrades/v7/upgrades.go b/testing/simapp/upgrades/v7/upgrades.go index 6dda8cab4bb..a9072ed63a2 100644 --- a/testing/simapp/upgrades/v7/upgrades.go +++ b/testing/simapp/upgrades/v7/upgrades.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - v7 "github.com/cosmos/ibc-go/v6/modules/core/02-client/migrations/v7" ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" ) @@ -24,17 +23,6 @@ func CreateUpgradeHandler( hostStoreKey *storetypes.KVStoreKey, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - // Perform in-place store migrations for the v7 upgrade - // The migration includes: - // - // - Migrating solo machine client states from v2 to v3 protobuf definition - // - Pruning all solo machine consensus states - // - Removing the localhost client - // - Asserting existing tendermint clients are properly registered on the chain codec - if err := v7.MigrateStore(ctx, hostStoreKey, cdc); err != nil { - return nil, err - } - // OPTIONAL: prune expired tendermint consensus states to save storage space if err := ibctm.PruneTendermintConsensusStates(ctx, cdc, hostStoreKey); err != nil { return nil, err