From 6ebc4764749a09a020cd4d6224948594b0291a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Fri, 7 Aug 2020 14:42:12 +0200 Subject: [PATCH] don't create localhost (#6974) --- x/ibc/02-client/abci_test.go | 4 ++-- x/ibc/02-client/genesis.go | 3 ++- x/ibc/02-client/keeper/client_test.go | 4 ++-- x/ibc/02-client/keeper/keeper.go | 6 +++--- x/ibc/02-client/keeper/keeper_test.go | 14 ++++++++------ x/ibc/02-client/types/genesis.go | 2 +- x/ibc/09-localhost/types/codec.go | 5 +++++ x/ibc/types/codec.go | 1 + 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/x/ibc/02-client/abci_test.go b/x/ibc/02-client/abci_test.go index e61cc2f36..b949ad7b9 100644 --- a/x/ibc/02-client/abci_test.go +++ b/x/ibc/02-client/abci_test.go @@ -9,8 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - client "github.com/cosmos/cosmos-sdk/x/ibc/02-client" - "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" ) type ClientTestSuite struct { @@ -34,6 +32,7 @@ func TestClientTestSuite(t *testing.T) { suite.Run(t, new(ClientTestSuite)) } +/* TODO: uncomment once simapp is switched to proto func (suite *ClientTestSuite) TestBeginBlocker() { prevHeight := suite.ctx.BlockHeight() @@ -55,3 +54,4 @@ func (suite *ClientTestSuite) TestBeginBlocker() { prevHeight = int64(localHostClient.GetLatestHeight()) } } +*/ diff --git a/x/ibc/02-client/genesis.go b/x/ibc/02-client/genesis.go index 1dcdb6f27..579a4cf20 100644 --- a/x/ibc/02-client/genesis.go +++ b/x/ibc/02-client/genesis.go @@ -16,6 +16,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { if !ok { panic("invalid client state") } + k.SetClientState(ctx, client.ClientID, cs) k.SetClientType(ctx, client.ClientID, cs.ClientType()) } @@ -55,6 +56,6 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { return types.GenesisState{ Clients: k.GetAllGenesisClients(ctx), ClientsConsensus: k.GetAllConsensusStates(ctx), - CreateLocalhost: true, + CreateLocalhost: false, } } diff --git a/x/ibc/02-client/keeper/client_test.go b/x/ibc/02-client/keeper/client_test.go index b3a5754a6..c4c810b2d 100644 --- a/x/ibc/02-client/keeper/client_test.go +++ b/x/ibc/02-client/keeper/client_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) @@ -232,6 +231,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() { } } +/* func (suite *KeeperTestSuite) TestUpdateClientLocalhost() { var localhostClient exported.ClientState = localhosttypes.NewClientState(suite.header.ChainID, suite.ctx.BlockHeight()) @@ -240,7 +240,7 @@ func (suite *KeeperTestSuite) TestUpdateClientLocalhost() { updatedClientState, err := suite.keeper.UpdateClient(suite.ctx, exported.ClientTypeLocalHost, nil) suite.Require().NoError(err, err) suite.Require().Equal(localhostClient.GetLatestHeight()+1, updatedClientState.GetLatestHeight()) -} +}*/ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() { altPrivVal := tmtypes.NewMockPV() diff --git a/x/ibc/02-client/keeper/keeper.go b/x/ibc/02-client/keeper/keeper.go index 4e070c4e6..c565a35e4 100644 --- a/x/ibc/02-client/keeper/keeper.go +++ b/x/ibc/02-client/keeper/keeper.go @@ -131,17 +131,17 @@ func (k Keeper) GetAllConsensusStates(ctx sdk.Context) types.ClientsConsensusSta mapClientIDToConsStateIdx := make(map[string]int) k.IterateConsensusStates(ctx, func(clientID string, cs exported.ConsensusState) bool { - anyClientState := types.MustPackConsensusState(cs) + anyConsensusState := types.MustPackConsensusState(cs) idx, ok := mapClientIDToConsStateIdx[clientID] if ok { - clientConsStates[idx].ConsensusStates = append(clientConsStates[idx].ConsensusStates, anyClientState) + clientConsStates[idx].ConsensusStates = append(clientConsStates[idx].ConsensusStates, anyConsensusState) return false } clientConsState := types.ClientConsensusStates{ ClientID: clientID, - ConsensusStates: []*codectypes.Any{anyClientState}, + ConsensusStates: []*codectypes.Any{anyConsensusState}, } clientConsStates = append(clientConsStates, clientConsState) diff --git a/x/ibc/02-client/keeper/keeper_test.go b/x/ibc/02-client/keeper/keeper_test.go index 5b500d615..01371b441 100644 --- a/x/ibc/02-client/keeper/keeper_test.go +++ b/x/ibc/02-client/keeper/keeper_test.go @@ -133,9 +133,10 @@ func (suite KeeperTestSuite) TestGetAllClients() { } // add localhost client - localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost) - suite.Require().True(found) - expClients = append(expClients, localHostClient) + // TODO: uncomment after simapp is migrated to proto + // localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost) + // suite.Require().True(found) + // expClients = append(expClients, localHostClient) clients := suite.keeper.GetAllClients(suite.ctx) suite.Require().Len(clients, len(expClients)) @@ -160,9 +161,10 @@ func (suite KeeperTestSuite) TestGetAllGenesisClients() { } // add localhost client - localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost) - suite.Require().True(found) - expGenClients = append(expGenClients, types.NewGenesisClientState(exported.ClientTypeLocalHost, localHostClient)) + // TODO: uncomment after simapp is migrated to proto + // localHostClient, found := suite.keeper.GetClientState(suite.ctx, exported.ClientTypeLocalHost) + // suite.Require().True(found) + // expGenClients = append(expGenClients, types.NewGenesisClientState(exported.ClientTypeLocalHost, localHostClient)) genClients := suite.keeper.GetAllGenesisClients(suite.ctx) diff --git a/x/ibc/02-client/types/genesis.go b/x/ibc/02-client/types/genesis.go index efbcc7531..049630f1c 100644 --- a/x/ibc/02-client/types/genesis.go +++ b/x/ibc/02-client/types/genesis.go @@ -118,7 +118,7 @@ func DefaultGenesisState() GenesisState { return GenesisState{ Clients: []GenesisClientState{}, ClientsConsensus: ClientsConsensusStates{}, - CreateLocalhost: true, + CreateLocalhost: false, } } diff --git a/x/ibc/09-localhost/types/codec.go b/x/ibc/09-localhost/types/codec.go index 7cac129d5..3db64cf7c 100644 --- a/x/ibc/09-localhost/types/codec.go +++ b/x/ibc/09-localhost/types/codec.go @@ -7,6 +7,11 @@ import ( clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" ) +// REMOVE: once simapp uses proto +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterConcrete(ClientState{}, "ibc/client/localhost/ClientState", nil) +} + // RegisterInterfaces register the ibc interfaces submodule implementations to protobuf // Any. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { diff --git a/x/ibc/types/codec.go b/x/ibc/types/codec.go index a401f09b0..661e7b18b 100644 --- a/x/ibc/types/codec.go +++ b/x/ibc/types/codec.go @@ -16,6 +16,7 @@ import ( func RegisterCodec(cdc *codec.Codec) { clienttypes.RegisterCodec(cdc) ibctmtypes.RegisterCodec(cdc) + localhosttypes.RegisterCodec(cdc) commitmenttypes.RegisterCodec(cdc) }