From 48aebed2ea3828fdee87d8b0539d9845e1f5abd7 Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Wed, 13 May 2020 19:23:33 -0400 Subject: [PATCH] x/ibc: /types cleanup (#6169) * x/ibc: move /types to /common * x/ibc/types: remove errors * remove mocked proofs * remove invalidProof{} * create new ibc/types dir * format * move keys to host * move order to channel * move channel state * move connection state * lint --- types/errors/errors.go | 6 + x/ibc/02-client/client/utils/utils.go | 6 +- x/ibc/02-client/keeper/keeper.go | 22 +- x/ibc/02-client/types/events.go | 4 +- x/ibc/02-client/types/querier.go | 6 +- x/ibc/03-connection/alias.go | 5 + x/ibc/03-connection/client/utils/utils.go | 6 +- x/ibc/03-connection/exported/exported.go | 3 +- x/ibc/03-connection/keeper/handshake.go | 29 +-- x/ibc/03-connection/keeper/handshake_test.go | 61 ++--- x/ibc/03-connection/keeper/keeper.go | 13 +- x/ibc/03-connection/keeper/keeper_test.go | 23 +- x/ibc/03-connection/keeper/verify_test.go | 34 +-- x/ibc/03-connection/types/connection.go | 11 +- x/ibc/03-connection/types/connection_test.go | 13 +- x/ibc/03-connection/types/events.go | 4 +- x/ibc/03-connection/types/genesis_test.go | 16 +- x/ibc/03-connection/types/msgs.go | 25 +- x/ibc/03-connection/types/querier.go | 6 +- x/ibc/03-connection/types/types.pb.go | 153 +++++++---- x/ibc/03-connection/types/types.proto | 18 +- x/ibc/04-channel/alias.go | 10 + x/ibc/04-channel/client/cli/tx.go | 7 +- x/ibc/04-channel/client/rest/rest.go | 19 +- x/ibc/04-channel/client/utils/utils.go | 6 +- x/ibc/04-channel/exported/exported.go | 8 +- x/ibc/04-channel/keeper/handshake.go | 71 +++-- x/ibc/04-channel/keeper/handshake_test.go | 245 +++++++++--------- x/ibc/04-channel/keeper/keeper.go | 43 +-- x/ibc/04-channel/keeper/keeper_test.go | 87 ++----- x/ibc/04-channel/keeper/packet.go | 36 +-- x/ibc/04-channel/keeper/packet_test.go | 172 ++++++------ x/ibc/04-channel/keeper/timeout.go | 20 +- x/ibc/04-channel/keeper/timeout_test.go | 86 +++--- x/ibc/04-channel/types/channel.go | 29 +-- x/ibc/04-channel/types/events.go | 4 +- x/ibc/04-channel/types/genesis_test.go | 10 +- x/ibc/04-channel/types/msgs.go | 41 ++- x/ibc/04-channel/types/msgs_test.go | 65 +++-- x/ibc/04-channel/types/querier.go | 8 +- x/ibc/04-channel/types/types.pb.go | 236 +++++++++++------ x/ibc/04-channel/types/types.proto | 35 ++- x/ibc/05-port/keeper/keeper.go | 14 +- x/ibc/05-port/types/module.go | 5 +- x/ibc/{ => 05-port}/types/utils.go | 2 +- x/ibc/07-tendermint/misbehaviour.go | 3 +- x/ibc/07-tendermint/types/client_state.go | 22 +- .../07-tendermint/types/client_state_test.go | 10 +- x/ibc/07-tendermint/types/msgs.go | 7 +- x/ibc/09-localhost/types/client_state.go | 16 +- x/ibc/09-localhost/types/client_state_test.go | 5 +- x/ibc/09-localhost/types/msgs.go | 4 +- x/ibc/20-transfer/client/utils/utils.go | 4 +- x/ibc/20-transfer/handler_test.go | 13 +- x/ibc/20-transfer/keeper/keeper.go | 12 +- x/ibc/20-transfer/keeper/keeper_test.go | 9 +- x/ibc/20-transfer/keeper/relay.go | 4 +- x/ibc/20-transfer/keeper/relay_test.go | 29 ++- x/ibc/20-transfer/module.go | 10 +- x/ibc/20-transfer/types/events.go | 4 +- x/ibc/20-transfer/types/keys.go | 4 +- x/ibc/{types => 24-host}/keys.go | 2 +- x/ibc/alias.go | 19 +- x/ibc/ante/ante_test.go | 27 +- x/ibc/client/cli/cli.go | 6 +- x/ibc/genesis.go | 30 --- x/ibc/genesis_test.go | 15 +- x/ibc/ibc_test.go | 4 +- x/ibc/module.go | 19 +- x/ibc/types/codec.go | 29 +++ x/ibc/types/errors.go | 11 - x/ibc/types/genesis.go | 37 +++ x/ibc/types/mock.go | 74 ------ x/ibc/types/types.pb.go | 129 --------- x/ibc/types/types.proto | 36 --- 75 files changed, 1105 insertions(+), 1212 deletions(-) rename x/ibc/{ => 05-port}/types/utils.go (82%) rename x/ibc/{types => 24-host}/keys.go (99%) create mode 100644 x/ibc/types/codec.go delete mode 100644 x/ibc/types/errors.go create mode 100644 x/ibc/types/genesis.go delete mode 100644 x/ibc/types/mock.go delete mode 100644 x/ibc/types/types.pb.go delete mode 100644 x/ibc/types/types.proto diff --git a/types/errors/errors.go b/types/errors/errors.go index 54d29ddfb0..684186b861 100644 --- a/types/errors/errors.go +++ b/types/errors/errors.go @@ -94,6 +94,12 @@ var ( // ErrorInvalidGasAdjustment defines an error for an invalid gas adjustment ErrorInvalidGasAdjustment = Register(RootCodespace, 25, "invalid gas adjustment") + // ErrInvalidHeight defines an error for an invalid height + ErrInvalidHeight = Register(RootCodespace, 26, "invalid height") + + // ErrInvalidVersion defines a general error for an invalid version + ErrInvalidVersion = Register(RootCodespace, 27, "invalid version") + // ErrPanic is only set when we recover from a panic, so we know to // redact potentially sensitive system info ErrPanic = Register(UndefinedCodespace, 111222, "panic") diff --git a/x/ibc/02-client/client/utils/utils.go b/x/ibc/02-client/client/utils/utils.go index 8dae0bc0de..ca26db298e 100644 --- a/x/ibc/02-client/client/utils/utils.go +++ b/x/ibc/02-client/client/utils/utils.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // QueryAllClientStates returns all the light client states. It _does not_ return @@ -44,7 +44,7 @@ func QueryClientState( ) (types.StateResponse, error) { req := abci.RequestQuery{ Path: "store/ibc/key", - Data: prefixClientKey(clientID, ibctypes.KeyClientState()), + Data: prefixClientKey(clientID, host.KeyClientState()), Prove: prove, } @@ -72,7 +72,7 @@ func QueryConsensusState( req := abci.RequestQuery{ Path: "store/ibc/key", - Data: prefixClientKey(clientID, ibctypes.KeyConsensusState(height)), + Data: prefixClientKey(clientID, host.KeyConsensusState(height)), Prove: prove, } diff --git a/x/ibc/02-client/keeper/keeper.go b/x/ibc/02-client/keeper/keeper.go index 3149e721b3..af023cba2b 100644 --- a/x/ibc/02-client/keeper/keeper.go +++ b/x/ibc/02-client/keeper/keeper.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -37,13 +37,13 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.StakingKeeper) Keepe // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", ibctypes.ModuleName, types.SubModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", host.ModuleName, types.SubModuleName)) } // GetClientState gets a particular client from the store func (k Keeper) GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) { store := k.ClientStore(ctx, clientID) - bz := store.Get(ibctypes.KeyClientState()) + bz := store.Get(host.KeyClientState()) if bz == nil { return nil, false } @@ -57,13 +57,13 @@ func (k Keeper) GetClientState(ctx sdk.Context, clientID string) (exported.Clien func (k Keeper) SetClientState(ctx sdk.Context, clientState exported.ClientState) { store := k.ClientStore(ctx, clientState.GetID()) bz := k.cdc.MustMarshalBinaryBare(clientState) - store.Set(ibctypes.KeyClientState(), bz) + store.Set(host.KeyClientState(), bz) } // GetClientType gets the consensus type for a specific client func (k Keeper) GetClientType(ctx sdk.Context, clientID string) (exported.ClientType, bool) { store := k.ClientStore(ctx, clientID) - bz := store.Get(ibctypes.KeyClientType()) + bz := store.Get(host.KeyClientType()) if bz == nil { return 0, false } @@ -74,13 +74,13 @@ func (k Keeper) GetClientType(ctx sdk.Context, clientID string) (exported.Client // SetClientType sets the specific client consensus type to the provable store func (k Keeper) SetClientType(ctx sdk.Context, clientID string, clientType exported.ClientType) { store := k.ClientStore(ctx, clientID) - store.Set(ibctypes.KeyClientType(), []byte{byte(clientType)}) + store.Set(host.KeyClientType(), []byte{byte(clientType)}) } // GetClientConsensusState gets the stored consensus state from a client at a given height. func (k Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height uint64) (exported.ConsensusState, bool) { store := k.ClientStore(ctx, clientID) - bz := store.Get(ibctypes.KeyConsensusState(height)) + bz := store.Get(host.KeyConsensusState(height)) if bz == nil { return nil, false } @@ -95,7 +95,7 @@ func (k Keeper) GetClientConsensusState(ctx sdk.Context, clientID string, height func (k Keeper) SetClientConsensusState(ctx sdk.Context, clientID string, height uint64, consensusState exported.ConsensusState) { store := k.ClientStore(ctx, clientID) bz := k.cdc.MustMarshalBinaryBare(consensusState) - store.Set(ibctypes.KeyConsensusState(height), bz) + store.Set(host.KeyConsensusState(height), bz) } // IterateConsensusStates provides an iterator over all stored consensus states. @@ -103,7 +103,7 @@ func (k Keeper) SetClientConsensusState(ctx sdk.Context, clientID string, height // the iterator will close and stop. func (k Keeper) IterateConsensusStates(ctx sdk.Context, cb func(clientID string, cs exported.ConsensusState) bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, ibctypes.KeyClientStorePrefix) + iterator := sdk.KVStorePrefixIterator(store, host.KeyClientStorePrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -163,7 +163,7 @@ func (k Keeper) GetAllConsensusStates(ctx sdk.Context) (clientConsStates []types // client at the given height func (k Keeper) HasClientConsensusState(ctx sdk.Context, clientID string, height uint64) bool { store := k.ClientStore(ctx, clientID) - return store.Has(ibctypes.KeyConsensusState(height)) + return store.Has(host.KeyConsensusState(height)) } // GetLatestClientConsensusState gets the latest ConsensusState stored for a given client @@ -211,7 +211,7 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported. // the iterator will close and stop. func (k Keeper) IterateClients(ctx sdk.Context, cb func(exported.ClientState) bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, ibctypes.KeyClientStorePrefix) + iterator := sdk.KVStorePrefixIterator(store, host.KeyClientStorePrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/ibc/02-client/types/events.go b/x/ibc/02-client/types/events.go index 9692cd3892..c2d75b71ff 100644 --- a/x/ibc/02-client/types/events.go +++ b/x/ibc/02-client/types/events.go @@ -3,7 +3,7 @@ package types import ( "fmt" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // IBC client events @@ -18,5 +18,5 @@ var ( EventTypeUpdateClient = "update_client" EventTypeSubmitMisbehaviour = "client_misbehaviour" - AttributeValueCategory = fmt.Sprintf("%s_%s", ibctypes.ModuleName, SubModuleName) + AttributeValueCategory = fmt.Sprintf("%s_%s", host.ModuleName, SubModuleName) ) diff --git a/x/ibc/02-client/types/querier.go b/x/ibc/02-client/types/querier.go index 3a34926f8b..029335673c 100644 --- a/x/ibc/02-client/types/querier.go +++ b/x/ibc/02-client/types/querier.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // query routes supported by the IBC client Querier @@ -48,7 +48,7 @@ func NewClientStateResponse( return StateResponse{ ClientState: clientState, Proof: commitmenttypes.MerkleProof{Proof: proof}, - ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(ibctypes.ClientStatePath(), "/")...)), + ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(host.ClientStatePath(), "/")...)), ProofHeight: uint64(height), } } @@ -69,7 +69,7 @@ func NewConsensusStateResponse( return ConsensusStateResponse{ ConsensusState: cs, Proof: commitmenttypes.MerkleProof{Proof: proof}, - ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(ibctypes.ClientStatePath(), "/")...)), + ProofPath: commitmenttypes.NewMerklePath(append([]string{clientID}, strings.Split(host.ClientStatePath(), "/")...)), ProofHeight: uint64(height), } } diff --git a/x/ibc/03-connection/alias.go b/x/ibc/03-connection/alias.go index d2ee564875..5853d77c04 100644 --- a/x/ibc/03-connection/alias.go +++ b/x/ibc/03-connection/alias.go @@ -20,6 +20,10 @@ const ( QueryAllConnections = types.QueryAllConnections QueryAllClientConnections = types.QueryAllClientConnections QueryClientConnections = types.QueryClientConnections + UNINITIALIZED = types.UNINITIALIZED + INIT = types.INIT + TRYOPEN = types.TRYOPEN + OPEN = types.OPEN ) var ( @@ -64,6 +68,7 @@ var ( type ( Keeper = keeper.Keeper End = types.ConnectionEnd + State = types.State Counterparty = types.Counterparty ClientKeeper = types.ClientKeeper MsgConnectionOpenInit = types.MsgConnectionOpenInit diff --git a/x/ibc/03-connection/client/utils/utils.go b/x/ibc/03-connection/client/utils/utils.go index d7916d3ecf..28872046a7 100644 --- a/x/ibc/03-connection/client/utils/utils.go +++ b/x/ibc/03-connection/client/utils/utils.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // QueryAllConnections returns all the connections. It _does not_ return @@ -45,7 +45,7 @@ func QueryConnection( ) (types.ConnectionResponse, error) { req := abci.RequestQuery{ Path: "store/ibc/key", - Data: ibctypes.KeyConnection(connectionID), + Data: host.KeyConnection(connectionID), Prove: prove, } @@ -94,7 +94,7 @@ func QueryClientConnections( ) (types.ClientConnectionsResponse, error) { req := abci.RequestQuery{ Path: "store/ibc/key", - Data: ibctypes.KeyClientConnections(clientID), + Data: host.KeyClientConnections(clientID), Prove: prove, } diff --git a/x/ibc/03-connection/exported/exported.go b/x/ibc/03-connection/exported/exported.go index b4aaca1587..c4746239a2 100644 --- a/x/ibc/03-connection/exported/exported.go +++ b/x/ibc/03-connection/exported/exported.go @@ -2,14 +2,13 @@ package exported import ( commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // ConnectionI describes the required methods for a connection. type ConnectionI interface { - GetState() ibctypes.State GetID() string GetClientID() string + GetState() int32 GetCounterparty() CounterpartyI GetVersions() []string ValidateBasic() error diff --git a/x/ibc/03-connection/keeper/handshake.go b/x/ibc/03-connection/keeper/handshake.go index a1814476cb..1bdcf3164d 100644 --- a/x/ibc/03-connection/keeper/handshake.go +++ b/x/ibc/03-connection/keeper/handshake.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // ConnOpenInit initialises a connection attempt on chain A. @@ -28,7 +27,7 @@ func (k Keeper) ConnOpenInit( } // connection defines chain A's ConnectionEnd - connection := types.NewConnectionEnd(ibctypes.INIT, connectionID, clientID, counterparty, types.GetCompatibleVersions()) + connection := types.NewConnectionEnd(types.INIT, connectionID, clientID, counterparty, types.GetCompatibleVersions()) k.SetConnection(ctx, connectionID, connection) if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil { @@ -57,7 +56,7 @@ func (k Keeper) ConnOpenTry( consensusHeight uint64, // latest height of chain B which chain A has stored in its chain B client ) error { if consensusHeight > uint64(ctx.BlockHeight()) { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "invalid consensus height") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "invalid consensus height") } expectedConsensusState, found := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) @@ -69,14 +68,14 @@ func (k Keeper) ConnOpenTry( // NOTE: chain A's counterparty is chain B (i.e where this code is executed) prefix := k.GetCommitmentPrefix() expectedCounterparty := types.NewCounterparty(clientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes())) - expectedConnection := types.NewConnectionEnd(ibctypes.INIT, counterparty.ConnectionID, counterparty.ClientID, expectedCounterparty, counterpartyVersions) + expectedConnection := types.NewConnectionEnd(types.INIT, counterparty.ConnectionID, counterparty.ClientID, expectedCounterparty, counterpartyVersions) // chain B picks a version from Chain A's available versions that is compatible // with the supported IBC versions version := types.PickVersion(counterpartyVersions, types.GetCompatibleVersions()) // connection defines chain B's ConnectionEnd - connection := types.NewConnectionEnd(ibctypes.UNINITIALIZED, connectionID, clientID, counterparty, []string{version}) + connection := types.NewConnectionEnd(types.UNINITIALIZED, connectionID, clientID, counterparty, []string{version}) // Check that ChainA committed expectedConnectionEnd to its state if err := k.VerifyConnectionState( @@ -97,7 +96,7 @@ func (k Keeper) ConnOpenTry( // is chainA and connection is on INIT stage // Check that existing connection version is on desired version of current handshake previousConnection, found := k.GetConnection(ctx, connectionID) - if found && !(previousConnection.State == ibctypes.INIT && + if found && !(previousConnection.State == types.INIT && previousConnection.Counterparty.ConnectionID == counterparty.ConnectionID && bytes.Equal(previousConnection.Counterparty.Prefix.Bytes(), counterparty.Prefix.Bytes()) && previousConnection.ClientID == clientID && @@ -107,7 +106,7 @@ func (k Keeper) ConnOpenTry( } // Set connection state to TRYOPEN and store in chainB state - connection.State = ibctypes.TRYOPEN + connection.State = types.TRYOPEN if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil { return sdkerrors.Wrap(err, "cannot relay connection attempt") } @@ -132,7 +131,7 @@ func (k Keeper) ConnOpenAck( ) error { // Check that chainB client hasn't stored invalid height if consensusHeight > uint64(ctx.BlockHeight()) { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "invalid consensus height") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "invalid consensus height") } // Retrieve connection @@ -142,7 +141,7 @@ func (k Keeper) ConnOpenAck( } // Check connection on ChainA is on correct state: INIT or TRYOPEN - if connection.State != ibctypes.INIT && connection.State != ibctypes.TRYOPEN { + if connection.State != types.INIT && connection.State != types.TRYOPEN { return sdkerrors.Wrapf( types.ErrInvalidConnectionState, "connection state is not INIT (got %s)", connection.State.String(), @@ -152,7 +151,7 @@ func (k Keeper) ConnOpenAck( // Check that ChainB's proposed version is one of chainA's accepted versions if types.LatestVersion(connection.Versions) != version { return sdkerrors.Wrapf( - ibctypes.ErrInvalidVersion, + sdkerrors.ErrInvalidVersion, "connection version does't match provided one (%s ≠ %s)", types.LatestVersion(connection.Versions), version, ) } @@ -165,7 +164,7 @@ func (k Keeper) ConnOpenAck( prefix := k.GetCommitmentPrefix() expectedCounterparty := types.NewCounterparty(connection.ClientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes())) - expectedConnection := types.NewConnectionEnd(ibctypes.TRYOPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, []string{version}) + expectedConnection := types.NewConnectionEnd(types.TRYOPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, []string{version}) // Ensure that ChainB stored expected connectionEnd in its state during ConnOpenTry if err := k.VerifyConnectionState( @@ -183,7 +182,7 @@ func (k Keeper) ConnOpenAck( } // Update connection state to Open - connection.State = ibctypes.OPEN + connection.State = types.OPEN connection.Versions = []string{version} k.SetConnection(ctx, connectionID, connection) k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: INIT -> OPEN ", connectionID)) @@ -207,7 +206,7 @@ func (k Keeper) ConnOpenConfirm( } // Check that connection state on ChainB is on state: TRYOPEN - if connection.State != ibctypes.TRYOPEN { + if connection.State != types.TRYOPEN { return sdkerrors.Wrapf( types.ErrInvalidConnectionState, "connection state is not TRYOPEN (got %s)", connection.State.String(), @@ -216,7 +215,7 @@ func (k Keeper) ConnOpenConfirm( prefix := k.GetCommitmentPrefix() expectedCounterparty := types.NewCounterparty(connection.ClientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes())) - expectedConnection := types.NewConnectionEnd(ibctypes.OPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, connection.Versions) + expectedConnection := types.NewConnectionEnd(types.OPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, connection.Versions) // Check that connection on ChainA is open if err := k.VerifyConnectionState( @@ -227,7 +226,7 @@ func (k Keeper) ConnOpenConfirm( } // Update ChainB's connection to Open - connection.State = ibctypes.OPEN + connection.State = types.OPEN k.SetConnection(ctx, connectionID, connection) k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: TRYOPEN -> OPEN ", connectionID)) return nil diff --git a/x/ibc/03-connection/keeper/handshake_test.go b/x/ibc/03-connection/keeper/handshake_test.go index 4522f1ea72..eabb978b00 100644 --- a/x/ibc/03-connection/keeper/handshake_test.go +++ b/x/ibc/03-connection/keeper/handshake_test.go @@ -4,8 +4,9 @@ import ( "fmt" connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" + "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // TestConnOpenInit - Chain A (ID #1) initializes (INIT state) a connection with @@ -20,7 +21,7 @@ func (suite *KeeperTestSuite) TestConnOpenInit() { suite.chainA.CreateClient(suite.chainB) }, true}, {"connection already exists", func() { - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, types.INIT) }, false}, {"couldn't add connection to client", func() {}, false}, } @@ -61,7 +62,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { {"success", func() uint64 { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.INIT) suite.chainB.updateClient(suite.chainA) suite.chainA.updateClient(suite.chainB) suite.chainB.updateClient(suite.chainA) @@ -78,14 +79,14 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { {"connection state verification invalid", func() uint64 { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.UNINITIALIZED) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.UNINITIALIZED) suite.chainB.updateClient(suite.chainA) return 0 }, false}, {"consensus state verification invalid", func() uint64 { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.INIT) suite.chainB.updateClient(suite.chainA) suite.chainA.updateClient(suite.chainB) return suite.chainB.Header.GetHeight() @@ -93,14 +94,14 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { {"invalid previous connection", func() uint64 { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, types.UNINITIALIZED) suite.chainB.updateClient(suite.chainA) suite.chainA.updateClient(suite.chainB) return 0 }, false}, {"couldn't add connection to client", func() uint64 { suite.chainB.CreateClient(suite.chainA) - suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.UNINITIALIZED) + suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, types.UNINITIALIZED) suite.chainB.updateClient(suite.chainA) suite.chainA.updateClient(suite.chainB) return 0 @@ -115,10 +116,10 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { consensusHeight := tc.malleate() - connectionKey := ibctypes.KeyConnection(testConnectionIDA) + connectionKey := host.KeyConnection(testConnectionIDA) proofInit, proofHeight := queryProof(suite.chainA, connectionKey) - consensusKey := prefixedClientKey(testClientIDB, ibctypes.KeyConsensusState(consensusHeight)) + consensusKey := prefixedClientKey(testClientIDB, host.KeyConsensusState(consensusHeight)) proofConsensus, _ := queryProof(suite.chainA, consensusKey) err := suite.chainB.App.IBCKeeper.ConnectionKeeper.ConnOpenTry( @@ -150,8 +151,8 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { {"success", version, func() uint64 { suite.chainA.CreateClient(suite.chainB) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.TRYOPEN) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, types.TRYOPEN) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.INIT) suite.chainB.updateClient(suite.chainA) suite.chainA.updateClient(suite.chainB) return suite.chainB.Header.GetHeight() @@ -159,8 +160,8 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { {"success from tryopen", version, func() uint64 { suite.chainA.CreateClient(suite.chainB) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.TRYOPEN) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.TRYOPEN) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, types.TRYOPEN) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.TRYOPEN) suite.chainB.updateClient(suite.chainA) suite.chainA.updateClient(suite.chainB) return suite.chainB.Header.GetHeight() @@ -172,36 +173,36 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { return 2 }, false}, {"connection state is not INIT", version, func() uint64 { - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, types.UNINITIALIZED) suite.chainB.updateClient(suite.chainA) return suite.chainB.Header.GetHeight() }, false}, {"incompatible IBC versions", "2.0", func() uint64 { - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, types.INIT) suite.chainB.updateClient(suite.chainA) return suite.chainB.Header.GetHeight() }, false}, {"self consensus state not found", version, func() uint64 { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT) - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.TRYOPEN) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.INIT) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, types.TRYOPEN) suite.chainB.updateClient(suite.chainA) return suite.chainB.Header.GetHeight() }, false}, {"connection state verification failed", version, func() uint64 { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT) - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.INIT) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, types.UNINITIALIZED) suite.chainB.updateClient(suite.chainA) return suite.chainB.Header.GetHeight() }, false}, {"consensus state verification failed", version, func() uint64 { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT) - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.INIT) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, types.UNINITIALIZED) suite.chainB.updateClient(suite.chainA) return suite.chainB.Header.GetHeight() }, false}, @@ -215,10 +216,10 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { consensusHeight := tc.malleate() - connectionKey := ibctypes.KeyConnection(testConnectionIDB) + connectionKey := host.KeyConnection(testConnectionIDB) proofTry, proofHeight := queryProof(suite.chainB, connectionKey) - consensusKey := prefixedClientKey(testClientIDA, ibctypes.KeyConsensusState(consensusHeight)) + consensusKey := prefixedClientKey(testClientIDA, host.KeyConsensusState(consensusHeight)) proofConsensus, _ := queryProof(suite.chainB, consensusKey) err := suite.chainA.App.IBCKeeper.ConnectionKeeper.ConnOpenAck( @@ -242,22 +243,22 @@ func (suite *KeeperTestSuite) TestConnOpenConfirm() { {"success", func() { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.TRYOPEN) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.OPEN) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, types.TRYOPEN) suite.chainB.updateClient(suite.chainA) }, true}, {"connection not found", func() {}, false}, {"chain B's connection state is not TRYOPEN", func() { - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED) - suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, types.UNINITIALIZED) + suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, types.OPEN) suite.chainA.updateClient(suite.chainB) }, false}, {"connection state verification failed", func() { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) suite.chainB.updateClient(suite.chainA) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT) - suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.TRYOPEN) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, types.INIT) + suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, types.TRYOPEN) suite.chainA.updateClient(suite.chainA) }, false}, } @@ -270,7 +271,7 @@ func (suite *KeeperTestSuite) TestConnOpenConfirm() { tc.malleate() - connectionKey := ibctypes.KeyConnection(testConnectionIDA) + connectionKey := host.KeyConnection(testConnectionIDA) proofAck, proofHeight := queryProof(suite.chainA, connectionKey) if tc.expPass { diff --git a/x/ibc/03-connection/keeper/keeper.go b/x/ibc/03-connection/keeper/keeper.go index 5dfa17ec3d..4af160720b 100644 --- a/x/ibc/03-connection/keeper/keeper.go +++ b/x/ibc/03-connection/keeper/keeper.go @@ -14,7 +14,6 @@ import ( commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // Keeper defines the IBC connection keeper @@ -37,7 +36,7 @@ func NewKeeper(aminoCdc *codec.Codec, cdc codec.Marshaler, key sdk.StoreKey, ck // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", ibctypes.ModuleName, types.SubModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", host.ModuleName, types.SubModuleName)) } // GetCommitmentPrefix returns the IBC connection store prefix as a commitment @@ -49,7 +48,7 @@ func (k Keeper) GetCommitmentPrefix() commitmentexported.Prefix { // GetConnection returns a connection with a particular identifier func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (types.ConnectionEnd, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(ibctypes.KeyConnection(connectionID)) + bz := store.Get(host.KeyConnection(connectionID)) if bz == nil { return types.ConnectionEnd{}, false } @@ -64,7 +63,7 @@ func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (types.Conne func (k Keeper) SetConnection(ctx sdk.Context, connectionID string, connection types.ConnectionEnd) { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshalBinaryBare(&connection) - store.Set(ibctypes.KeyConnection(connectionID), bz) + store.Set(host.KeyConnection(connectionID), bz) } // GetTimestampAtHeight returns the timestamp in nanoseconds of the consensus state at the @@ -88,7 +87,7 @@ func (k Keeper) GetTimestampAtHeight(ctx sdk.Context, connection types.Connectio // particular client func (k Keeper) GetClientConnectionPaths(ctx sdk.Context, clientID string) ([]string, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(ibctypes.KeyClientConnections(clientID)) + bz := store.Get(host.KeyClientConnections(clientID)) if bz == nil { return nil, false } @@ -103,7 +102,7 @@ func (k Keeper) SetClientConnectionPaths(ctx sdk.Context, clientID string, paths store := ctx.KVStore(k.storeKey) clientPaths := types.ClientPaths{Paths: paths} bz := k.cdc.MustMarshalBinaryBare(&clientPaths) - store.Set(ibctypes.KeyClientConnections(clientID), bz) + store.Set(host.KeyClientConnections(clientID), bz) } // GetAllClientConnectionPaths returns all stored clients connection id paths. It @@ -130,7 +129,7 @@ func (k Keeper) GetAllClientConnectionPaths(ctx sdk.Context) []types.ConnectionP // iterator will close and stop. func (k Keeper) IterateConnections(ctx sdk.Context, cb func(types.ConnectionEnd) bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, ibctypes.KeyConnectionPrefix) + iterator := sdk.KVStorePrefixIterator(store, host.KeyConnectionPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/ibc/03-connection/keeper/keeper_test.go b/x/ibc/03-connection/keeper/keeper_test.go index 6bfc88382d..18284b929d 100644 --- a/x/ibc/03-connection/keeper/keeper_test.go +++ b/x/ibc/03-connection/keeper/keeper_test.go @@ -19,12 +19,13 @@ import ( channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" + "github.com/cosmos/cosmos-sdk/x/staking" ) const ( - storeKey = ibctypes.StoreKey + storeKey = host.StoreKey testClientIDA = "testclientida" // chainid for chainA also chainB's clientID for A's liteclient testConnectionIDA = "connectionidatob" @@ -89,7 +90,7 @@ func (suite *KeeperTestSuite) TestSetAndGetConnection() { suite.Require().False(existed) counterparty := types.NewCounterparty(testClientIDA, testConnectionIDA, commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())) - expConn := types.NewConnectionEnd(ibctypes.INIT, testConnectionIDB, testClientIDB, counterparty, types.GetCompatibleVersions()) + expConn := types.NewConnectionEnd(types.INIT, testConnectionIDB, testClientIDB, counterparty, types.GetCompatibleVersions()) suite.chainA.App.IBCKeeper.ConnectionKeeper.SetConnection(suite.chainA.GetContext(), testConnectionIDA, expConn) conn, existed := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetConnection(suite.chainA.GetContext(), testConnectionIDA) suite.Require().True(existed) @@ -112,9 +113,9 @@ func (suite KeeperTestSuite) TestGetAllConnections() { counterparty2 := types.NewCounterparty(testClientIDB, testConnectionIDB, commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())) counterparty3 := types.NewCounterparty(testClientID3, testConnectionID3, commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())) - conn1 := types.NewConnectionEnd(ibctypes.INIT, testConnectionIDA, testClientIDA, counterparty3, types.GetCompatibleVersions()) - conn2 := types.NewConnectionEnd(ibctypes.INIT, testConnectionIDB, testClientIDB, counterparty1, types.GetCompatibleVersions()) - conn3 := types.NewConnectionEnd(ibctypes.UNINITIALIZED, testConnectionID3, testClientID3, counterparty2, types.GetCompatibleVersions()) + conn1 := types.NewConnectionEnd(types.INIT, testConnectionIDA, testClientIDA, counterparty3, types.GetCompatibleVersions()) + conn2 := types.NewConnectionEnd(types.INIT, testConnectionIDB, testClientIDB, counterparty1, types.GetCompatibleVersions()) + conn3 := types.NewConnectionEnd(types.UNINITIALIZED, testConnectionID3, testClientID3, counterparty2, types.GetCompatibleVersions()) expConnections := []types.ConnectionEnd{conn1, conn2, conn3} @@ -139,8 +140,8 @@ func (suite KeeperTestSuite) TestGetAllClientConnectionPaths() { } expPaths := []types.ConnectionPaths{ - types.NewConnectionPaths(testClientIDA, []string{ibctypes.ConnectionPath(testConnectionIDA)}), - types.NewConnectionPaths(testClientIDB, []string{ibctypes.ConnectionPath(testConnectionIDB), ibctypes.ConnectionPath(testConnectionID3)}), + types.NewConnectionPaths(testClientIDA, []string{host.ConnectionPath(testConnectionIDA)}), + types.NewConnectionPaths(testClientIDB, []string{host.ConnectionPath(testConnectionIDB), host.ConnectionPath(testConnectionID3)}), } for i := range expPaths { @@ -172,7 +173,7 @@ func (suite *KeeperTestSuite) TestGetTimestampAtHeight() { tc.malleate() // create and store a connection to chainB on chainA - connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.OPEN) + connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.OPEN) actualTimestamp, err := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetTimestampAtHeight( suite.chainA.GetContext(), connection, uint64(suite.chainB.Header.Height), @@ -355,7 +356,7 @@ func (chain *TestChain) updateClient(client *TestChain) { func (chain *TestChain) createConnection( connID, counterpartyConnID, clientID, counterpartyClientID string, - state ibctypes.State, + state types.State, ) types.ConnectionEnd { counterparty := types.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())) connection := types.ConnectionEnd{ @@ -372,7 +373,7 @@ func (chain *TestChain) createConnection( func (chain *TestChain) createChannel( portID, channelID, counterpartyPortID, counterpartyChannelID string, - state ibctypes.State, order ibctypes.Order, connectionID string, + state channeltypes.State, order channeltypes.Order, connectionID string, ) channeltypes.Channel { counterparty := channeltypes.NewCounterparty(counterpartyPortID, counterpartyChannelID) channel := channeltypes.NewChannel(state, order, counterparty, []string{connectionID}, "1.0") diff --git a/x/ibc/03-connection/keeper/verify_test.go b/x/ibc/03-connection/keeper/verify_test.go index 0790667464..8cc06d1dee 100644 --- a/x/ibc/03-connection/keeper/verify_test.go +++ b/x/ibc/03-connection/keeper/verify_test.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) const ( @@ -25,7 +25,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() { commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()), ) connection1 := types.NewConnectionEnd( - ibctypes.UNINITIALIZED, testConnectionIDB, testClientIDB, counterparty, + types.UNINITIALIZED, testConnectionIDB, testClientIDB, counterparty, types.GetCompatibleVersions(), ) @@ -66,7 +66,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() { // TODO: is this the right consensus height consensusHeight := suite.chainA.Header.GetHeight() - consensusKey := prefixedClientKey(testClientIDA, ibctypes.KeyConsensusState(consensusHeight)) + consensusKey := prefixedClientKey(testClientIDA, host.KeyConsensusState(consensusHeight)) // get proof that chainB stored chainA' consensus state proof, proofHeight := queryProof(suite.chainB, consensusKey) @@ -85,7 +85,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() { } func (suite *KeeperTestSuite) TestVerifyConnectionState() { - connectionKey := ibctypes.KeyConnection(testConnectionIDA) + connectionKey := host.KeyConnection(testConnectionIDA) var invalidProofHeight uint64 cases := []struct { msg string @@ -117,7 +117,7 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() { tc.malleate() // create and store connection on chain A - expectedConnection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.OPEN) + expectedConnection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, types.OPEN) // // create expected connection // TODO: why is this commented @@ -134,7 +134,7 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() { // Create B's connection to A counterparty := types.NewCounterparty(testClientIDB, testConnectionIDB, commitmenttypes.NewMerklePrefix([]byte("ibc"))) - connection := types.NewConnectionEnd(ibctypes.UNINITIALIZED, testConnectionIDA, testClientIDA, counterparty, []string{"1.0.0"}) + connection := types.NewConnectionEnd(types.UNINITIALIZED, testConnectionIDA, testClientIDA, counterparty, []string{"1.0.0"}) // Ensure chain B can verify connection exists in chain A err := suite.chainB.App.IBCKeeper.ConnectionKeeper.VerifyConnectionState( suite.chainB.GetContext(), connection, proofHeight+1, proof, testConnectionIDA, expectedConnection, @@ -150,7 +150,7 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() { } func (suite *KeeperTestSuite) TestVerifyChannelState() { - channelKey := ibctypes.KeyChannel(testPort1, testChannel1) + channelKey := host.KeyChannel(testPort1, testChannel1) // create connection of chainB to pass into verify function counterparty := types.NewCounterparty( @@ -159,7 +159,7 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() { ) connection := types.NewConnectionEnd( - ibctypes.UNINITIALIZED, testConnectionIDA, testClientIDA, counterparty, + types.UNINITIALIZED, testConnectionIDA, testClientIDA, counterparty, types.GetCompatibleVersions(), ) @@ -193,7 +193,7 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() { // Create and store channel on chain A channel := suite.chainA.createChannel( testPort1, testChannel1, testPort2, testChannel2, - ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA, + channeltypes.OPEN, channeltypes.ORDERED, testConnectionIDA, ) // Update chainA client on chainB @@ -221,7 +221,7 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() { } func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { - commitmentKey := ibctypes.KeyPacketCommitment(testPort1, testChannel1, 1) + commitmentKey := host.KeyPacketCommitment(testPort1, testChannel1, 1) commitmentBz := []byte("commitment") cases := []struct { @@ -250,7 +250,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { tc.malleate() // Set PacketCommitment on chainA - connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) + connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, types.OPEN) suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), testPort1, testChannel1, 1, commitmentBz) // Update ChainA client on chainB @@ -278,7 +278,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { } func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { - packetAckKey := ibctypes.KeyPacketAcknowledgement(testPort1, testChannel1, 1) + packetAckKey := host.KeyPacketAcknowledgement(testPort1, testChannel1, 1) ack := []byte("acknowledgement") cases := []struct { @@ -303,7 +303,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { suite.SetupTest() // reset tc.malleate() - connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) + connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, types.OPEN) suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketAcknowledgement(suite.chainA.GetContext(), testPort1, testChannel1, 1, channeltypes.CommitAcknowledgement(ack)) suite.chainB.updateClient(suite.chainA) @@ -329,7 +329,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { } func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgementAbsence() { - packetAckKey := ibctypes.KeyPacketAcknowledgement(testPort1, testChannel1, 1) + packetAckKey := host.KeyPacketAcknowledgement(testPort1, testChannel1, 1) cases := []struct { msg string @@ -353,7 +353,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgementAbsence() { suite.SetupTest() // reset tc.malleate() - connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) + connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, types.OPEN) suite.chainB.updateClient(suite.chainA) proof, proofHeight := queryProof(suite.chainA, packetAckKey) @@ -377,7 +377,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgementAbsence() { } func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { - nextSeqRcvKey := ibctypes.KeyNextSequenceRecv(testPort1, testChannel1) + nextSeqRcvKey := host.KeyNextSequenceRecv(testPort1, testChannel1) cases := []struct { msg string @@ -401,7 +401,7 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { suite.SetupTest() // reset tc.malleate() - connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) + connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, types.OPEN) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort1, testChannel1, 1) suite.chainB.updateClient(suite.chainA) diff --git a/x/ibc/03-connection/types/connection.go b/x/ibc/03-connection/types/connection.go index e439d14342..3d88538681 100644 --- a/x/ibc/03-connection/types/connection.go +++ b/x/ibc/03-connection/types/connection.go @@ -8,13 +8,12 @@ import ( commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) var _ exported.ConnectionI = (*ConnectionEnd)(nil) // NewConnectionEnd creates a new ConnectionEnd instance. -func NewConnectionEnd(state ibctypes.State, connectionID, clientID string, counterparty Counterparty, versions []string) ConnectionEnd { +func NewConnectionEnd(state State, connectionID, clientID string, counterparty Counterparty, versions []string) ConnectionEnd { return ConnectionEnd{ ID: connectionID, ClientID: clientID, @@ -25,8 +24,8 @@ func NewConnectionEnd(state ibctypes.State, connectionID, clientID string, count } // GetState implements the Connection interface -func (c ConnectionEnd) GetState() ibctypes.State { - return c.State +func (c ConnectionEnd) GetState() int32 { + return int32(c.State) } // GetID implements the Connection interface @@ -60,11 +59,11 @@ func (c ConnectionEnd) ValidateBasic() error { return sdkerrors.Wrapf(err, "invalid client ID: %s", c.ClientID) } if len(c.Versions) == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "missing connection versions") + return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "missing connection versions") } for _, version := range c.Versions { if strings.TrimSpace(version) == "" { - return sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "version can't be blank") + return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "version can't be blank") } } return c.Counterparty.ValidateBasic() diff --git a/x/ibc/03-connection/types/connection_test.go b/x/ibc/03-connection/types/connection_test.go index faabbaf7ab..e43e938b4d 100644 --- a/x/ibc/03-connection/types/connection_test.go +++ b/x/ibc/03-connection/types/connection_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/require" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) var ( @@ -24,32 +23,32 @@ func TestConnectionValidateBasic(t *testing.T) { }{ { "valid connection", - ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, true, }, { "invalid connection id", - ConnectionEnd{"connectionIDONE", clientID, []string{"1.0.0"}, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + ConnectionEnd{"connectionIDONE", clientID, []string{"1.0.0"}, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "invalid client id", - ConnectionEnd{connectionID, "clientID1", []string{"1.0.0"}, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + ConnectionEnd{connectionID, "clientID1", []string{"1.0.0"}, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "empty versions", - ConnectionEnd{connectionID, clientID, nil, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + ConnectionEnd{connectionID, clientID, nil, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "invalid version", - ConnectionEnd{connectionID, clientID, []string{""}, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, + ConnectionEnd{connectionID, clientID, []string{""}, INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}}, false, }, { "invalid counterparty", - ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, ibctypes.INIT, Counterparty{clientID2, connectionID2, emptyPrefix}}, + ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, INIT, Counterparty{clientID2, connectionID2, emptyPrefix}}, false, }, } diff --git a/x/ibc/03-connection/types/events.go b/x/ibc/03-connection/types/events.go index 92a73afbeb..2bd95243b7 100644 --- a/x/ibc/03-connection/types/events.go +++ b/x/ibc/03-connection/types/events.go @@ -3,7 +3,7 @@ package types import ( "fmt" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // IBC connection events @@ -20,5 +20,5 @@ var ( EventTypeConnectionOpenAck = MsgConnectionOpenAck{}.Type() EventTypeConnectionOpenConfirm = MsgConnectionOpenConfirm{}.Type() - AttributeValueCategory = fmt.Sprintf("%s_%s", ibctypes.ModuleName, SubModuleName) + AttributeValueCategory = fmt.Sprintf("%s_%s", host.ModuleName, SubModuleName) ) diff --git a/x/ibc/03-connection/types/genesis_test.go b/x/ibc/03-connection/types/genesis_test.go index 19a4aa9775..a3f602329d 100644 --- a/x/ibc/03-connection/types/genesis_test.go +++ b/x/ibc/03-connection/types/genesis_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) func TestValidateGenesis(t *testing.T) { @@ -25,10 +25,10 @@ func TestValidateGenesis(t *testing.T) { name: "valid genesis", genState: NewGenesisState( []ConnectionEnd{ - NewConnectionEnd(ibctypes.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), + NewConnectionEnd(INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), }, []ConnectionPaths{ - {clientID, []string{ibctypes.ConnectionPath(connectionID)}}, + {clientID, []string{host.ConnectionPath(connectionID)}}, }, ), expPass: true, @@ -37,10 +37,10 @@ func TestValidateGenesis(t *testing.T) { name: "invalid connection", genState: NewGenesisState( []ConnectionEnd{ - NewConnectionEnd(ibctypes.INIT, connectionID, "CLIENTIDONE", Counterparty{clientID, connectionID, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), + NewConnectionEnd(INIT, connectionID, "CLIENTIDONE", Counterparty{clientID, connectionID, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), }, []ConnectionPaths{ - {clientID, []string{ibctypes.ConnectionPath(connectionID)}}, + {clientID, []string{host.ConnectionPath(connectionID)}}, }, ), expPass: false, @@ -49,10 +49,10 @@ func TestValidateGenesis(t *testing.T) { name: "invalid client id", genState: NewGenesisState( []ConnectionEnd{ - NewConnectionEnd(ibctypes.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), + NewConnectionEnd(INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), }, []ConnectionPaths{ - {"CLIENTIDONE", []string{ibctypes.ConnectionPath(connectionID)}}, + {"CLIENTIDONE", []string{host.ConnectionPath(connectionID)}}, }, ), expPass: false, @@ -61,7 +61,7 @@ func TestValidateGenesis(t *testing.T) { name: "invalid path", genState: NewGenesisState( []ConnectionEnd{ - NewConnectionEnd(ibctypes.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), + NewConnectionEnd(INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}), }, []ConnectionPaths{ {clientID, []string{connectionID}}, diff --git a/x/ibc/03-connection/types/msgs.go b/x/ibc/03-connection/types/msgs.go index 425c32d4e0..305496207d 100644 --- a/x/ibc/03-connection/types/msgs.go +++ b/x/ibc/03-connection/types/msgs.go @@ -7,7 +7,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) var _ sdk.Msg = MsgConnectionOpenInit{} @@ -29,7 +28,7 @@ func NewMsgConnectionOpenInit( // Route implements sdk.Msg func (msg MsgConnectionOpenInit) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -86,7 +85,7 @@ func NewMsgConnectionOpenTry( // Route implements sdk.Msg func (msg MsgConnectionOpenTry) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -103,11 +102,11 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error { return sdkerrors.Wrapf(err, "invalid client ID: %s", msg.ClientID) } if len(msg.CounterpartyVersions) == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "missing counterparty versions") + return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "missing counterparty versions") } for _, version := range msg.CounterpartyVersions { if strings.TrimSpace(version) == "" { - return sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "version can't be blank") + return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "version can't be blank") } } if msg.ProofInit.IsEmpty() || msg.ProofConsensus.IsEmpty() { @@ -120,10 +119,10 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error { return sdkerrors.Wrap(err, "proof consensus cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } if msg.ConsensusHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "consensus height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "consensus height must be > 0") } if msg.Signer.Empty() { return sdkerrors.ErrInvalidAddress @@ -162,7 +161,7 @@ func NewMsgConnectionOpenAck( // Route implements sdk.Msg func (msg MsgConnectionOpenAck) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -176,7 +175,7 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error { return sdkerrors.Wrap(err, "invalid connection ID") } if strings.TrimSpace(msg.Version) == "" { - return sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "version can't be blank") + return sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "version can't be blank") } if msg.ProofTry.IsEmpty() || msg.ProofConsensus.IsEmpty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof") @@ -188,10 +187,10 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error { return sdkerrors.Wrap(err, "proof consensus cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } if msg.ConsensusHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "consensus height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "consensus height must be > 0") } if msg.Signer.Empty() { return sdkerrors.ErrInvalidAddress @@ -226,7 +225,7 @@ func NewMsgConnectionOpenConfirm( // Route implements sdk.Msg func (msg MsgConnectionOpenConfirm) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -246,7 +245,7 @@ func (msg MsgConnectionOpenConfirm) ValidateBasic() error { return sdkerrors.Wrap(err, "proof ack cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } if msg.Signer.Empty() { return sdkerrors.ErrInvalidAddress diff --git a/x/ibc/03-connection/types/querier.go b/x/ibc/03-connection/types/querier.go index 52afc9f500..7b52eef12e 100644 --- a/x/ibc/03-connection/types/querier.go +++ b/x/ibc/03-connection/types/querier.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // query routes supported by the IBC connection Querier @@ -32,7 +32,7 @@ func NewConnectionResponse( return ConnectionResponse{ Connection: connection, Proof: commitmenttypes.MerkleProof{Proof: proof}, - ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.ConnectionPath(connectionID), "/")), + ProofPath: commitmenttypes.NewMerklePath(strings.Split(host.ConnectionPath(connectionID), "/")), ProofHeight: uint64(height), } } @@ -69,7 +69,7 @@ func NewClientConnectionsResponse( return ClientConnectionsResponse{ ConnectionPaths: connectionPaths, Proof: commitmenttypes.MerkleProof{Proof: proof}, - ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.ClientConnectionsPath(clientID), "/")), + ProofPath: commitmenttypes.NewMerklePath(strings.Split(host.ClientConnectionsPath(clientID), "/")), ProofHeight: uint64(height), } } diff --git a/x/ibc/03-connection/types/types.pb.go b/x/ibc/03-connection/types/types.pb.go index 78acde8a07..6c7e8f3334 100644 --- a/x/ibc/03-connection/types/types.pb.go +++ b/x/ibc/03-connection/types/types.pb.go @@ -7,7 +7,6 @@ import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - types1 "github.com/cosmos/cosmos-sdk/x/ibc/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -26,6 +25,43 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// State defines if a connection is in one of the following states: +// INIT, TRYOPEN, OPEN or UNINITIALIZED. +type State int32 + +const ( + // Default State + UNINITIALIZED State = 0 + // A connection end has just started the opening handshake. + INIT State = 1 + // A connection end has acknowledged the handshake step on the counterparty chain. + TRYOPEN State = 2 + // A connection end has completed the handshake. + OPEN State = 3 +) + +var State_name = map[int32]string{ + 0: "STATE_UNINITIALIZED_UNSPECIFIED", + 1: "STATE_INIT", + 2: "STATE_TRYOPEN", + 3: "STATE_OPEN", +} + +var State_value = map[string]int32{ + "STATE_UNINITIALIZED_UNSPECIFIED": 0, + "STATE_INIT": 1, + "STATE_TRYOPEN": 2, + "STATE_OPEN": 3, +} + +func (x State) String() string { + return proto.EnumName(State_name, int32(x)) +} + +func (State) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_30ee50c03d1fbe43, []int{0} +} + // MsgConnectionOpenInit defines the msg sent by an account on Chain A to // initialize a connection with Chain B. type MsgConnectionOpenInit struct { @@ -388,7 +424,7 @@ type ConnectionEnd struct { // channels or packets utilising this connection Versions []string `protobuf:"bytes,3,rep,name=versions,proto3" json:"versions,omitempty"` // current state of the connection end. - State types1.State `protobuf:"varint,4,opt,name=state,proto3,enum=cosmos_sdk.x.ibc.v1.State" json:"state,omitempty"` + State State `protobuf:"varint,4,opt,name=state,proto3,enum=cosmos_sdk.x.ibc.connection.v1.State" json:"state,omitempty"` // counterparty chain associated with this connection. Counterparty Counterparty `protobuf:"bytes,5,opt,name=counterparty,proto3" json:"counterparty"` } @@ -515,6 +551,7 @@ func (m *ClientPaths) GetPaths() []string { } func init() { + proto.RegisterEnum("cosmos_sdk.x.ibc.connection.v1.State", State_name, State_value) proto.RegisterType((*MsgConnectionOpenInit)(nil), "cosmos_sdk.x.ibc.connection.v1.MsgConnectionOpenInit") proto.RegisterType((*MsgConnectionOpenTry)(nil), "cosmos_sdk.x.ibc.connection.v1.MsgConnectionOpenTry") proto.RegisterType((*MsgConnectionOpenAck)(nil), "cosmos_sdk.x.ibc.connection.v1.MsgConnectionOpenAck") @@ -529,58 +566,64 @@ func init() { } var fileDescriptor_30ee50c03d1fbe43 = []byte{ - // 812 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x96, 0x4d, 0x6f, 0xda, 0x48, - 0x18, 0xc7, 0xb1, 0x79, 0x09, 0x4c, 0xc8, 0xcb, 0x3a, 0x64, 0xe3, 0x65, 0x57, 0x36, 0xeb, 0x68, - 0x57, 0x48, 0xbb, 0x31, 0x79, 0x91, 0x7a, 0x88, 0xd4, 0x43, 0xa0, 0xad, 0x4a, 0xa5, 0xa8, 0x91, - 0xdb, 0xe6, 0xd0, 0x0b, 0x02, 0x7b, 0x02, 0x23, 0xc2, 0x0c, 0xf2, 0x4c, 0xa2, 0xf0, 0x0d, 0x7a, - 0xec, 0x37, 0x68, 0x8f, 0xfd, 0x28, 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, 0x00, 0xff, 0xff, 0x86, 0x13, 0x13, 0x09, 0xf7, 0x0a, 0x00, 0x00, + // 911 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x96, 0x31, 0x6f, 0xdb, 0x46, + 0x14, 0x80, 0x45, 0x8a, 0x92, 0xa5, 0xb3, 0x9c, 0x28, 0x8c, 0xd3, 0xb0, 0x6a, 0x41, 0xb2, 0x0c, + 0x52, 0x08, 0x6d, 0x2d, 0x35, 0x0e, 0x90, 0xc1, 0x45, 0x07, 0x49, 0x56, 0x50, 0x16, 0xb5, 0x23, + 0xd0, 0x72, 0x80, 0x66, 0x11, 0x24, 0xf2, 0x2c, 0x1d, 0x64, 0x91, 0x02, 0xef, 0x1c, 0x58, 0xff, + 0x20, 0xf0, 0xd4, 0xb5, 0x83, 0x81, 0x02, 0x5d, 0x8a, 0xfe, 0x12, 0x8f, 0x19, 0x3a, 0x74, 0x22, + 0x0a, 0x19, 0xe8, 0xd8, 0x41, 0x63, 0xa7, 0xe2, 0xee, 0x28, 0x92, 0x8e, 0x5c, 0x1b, 0x86, 0x05, + 0xb4, 0x40, 0x16, 0xe9, 0xde, 0xbb, 0xf7, 0xde, 0xbd, 0x7b, 0xef, 0x23, 0x1f, 0xc1, 0xe3, 0xe3, + 0x2a, 0xea, 0xd9, 0xd5, 0x2f, 0x9f, 0x6e, 0xd8, 0x9e, 0xeb, 0x42, 0x9b, 0x20, 0xcf, 0xad, 0x92, + 0xc9, 0x18, 0x62, 0xfe, 0x5b, 0x19, 0xfb, 0x1e, 0xf1, 0x64, 0xd5, 0xf6, 0xf0, 0xc8, 0xc3, 0x1d, + 0xec, 0x0c, 0x2b, 0xc7, 0x15, 0xd4, 0xb3, 0x2b, 0xb1, 0x79, 0xe5, 0xf5, 0x93, 0xd2, 0xa7, 0x64, + 0x80, 0x7c, 0xa7, 0x33, 0xee, 0xfa, 0x64, 0x52, 0x65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, 0x09, 0x00, 0x00, 0xff, 0xff, 0x43, 0x20, 0xb6, 0x5a, 0x85, 0x0b, 0x00, 0x00, } func (m *MsgConnectionOpenInit) Marshal() (dAtA []byte, err error) { @@ -2259,7 +2302,7 @@ func (m *ConnectionEnd) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.State |= types1.State(b&0x7F) << shift + m.State |= State(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/ibc/03-connection/types/types.proto b/x/ibc/03-connection/types/types.proto index bf196ea335..4e729e2935 100644 --- a/x/ibc/03-connection/types/types.proto +++ b/x/ibc/03-connection/types/types.proto @@ -5,7 +5,6 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"; import "third_party/proto/gogoproto/gogo.proto"; import "x/ibc/23-commitment/types/types.proto"; -import "x/ibc/types/types.proto"; // MsgConnectionOpenInit defines the msg sent by an account on Chain A to // initialize a connection with Chain B. @@ -78,11 +77,26 @@ message ConnectionEnd { // channels or packets utilising this connection repeated string versions = 3; // current state of the connection end. - cosmos_sdk.x.ibc.v1.State state = 4; + State state = 4; // counterparty chain associated with this connection. Counterparty counterparty = 5 [(gogoproto.nullable) = false]; } +// State defines if a connection is in one of the following states: +// INIT, TRYOPEN, OPEN or UNINITIALIZED. +enum State { + option (gogoproto.goproto_enum_prefix) = false; + + // Default State + STATE_UNINITIALIZED_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNINITIALIZED"]; + // A connection end has just started the opening handshake. + STATE_INIT = 1 [(gogoproto.enumvalue_customname) = "INIT"]; + // A connection end has acknowledged the handshake step on the counterparty chain. + STATE_TRYOPEN = 2 [(gogoproto.enumvalue_customname) = "TRYOPEN"]; + // A connection end has completed the handshake. + STATE_OPEN = 3 [(gogoproto.enumvalue_customname) = "OPEN"]; +} + // Counterparty defines the counterparty chain associated with a connection end. message Counterparty { option (gogoproto.goproto_getters) = false; diff --git a/x/ibc/04-channel/alias.go b/x/ibc/04-channel/alias.go index 0e3356bec4..4a8efff613 100644 --- a/x/ibc/04-channel/alias.go +++ b/x/ibc/04-channel/alias.go @@ -18,6 +18,14 @@ const ( QueryAllChannels = types.QueryAllChannels QueryConnectionChannels = types.QueryConnectionChannels QueryChannel = types.QueryChannel + UNINITIALIZED = types.UNINITIALIZED + INIT = types.INIT + TRYOPEN = types.TRYOPEN + OPEN = types.OPEN + CLOSED = types.CLOSED + NONE = types.NONE + UNORDERED = types.UNORDERED + ORDERED = types.ORDERED ) var ( @@ -73,6 +81,8 @@ type ( Keeper = keeper.Keeper Channel = types.Channel Counterparty = types.Counterparty + State = types.State + Order = types.Order IdentifiedChannel = types.IdentifiedChannel ClientKeeper = types.ClientKeeper ConnectionKeeper = types.ConnectionKeeper diff --git a/x/ibc/04-channel/client/cli/tx.go b/x/ibc/04-channel/client/cli/tx.go index db4565fc34..b255c2e296 100644 --- a/x/ibc/04-channel/client/cli/tx.go +++ b/x/ibc/04-channel/client/cli/tx.go @@ -15,7 +15,6 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" connectionutils "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // IBC Channel flags @@ -243,9 +242,9 @@ func GetMsgChannelCloseConfirmCmd(storeKey string, cdc *codec.Codec) *cobra.Comm } } -func channelOrder() ibctypes.Order { +func channelOrder() types.Order { if viper.GetBool(FlagOrdered) { - return ibctypes.ORDERED + return types.ORDERED } - return ibctypes.UNORDERED + return types.UNORDERED } diff --git a/x/ibc/04-channel/client/rest/rest.go b/x/ibc/04-channel/client/rest/rest.go index 4bb45ad243..d91eae7023 100644 --- a/x/ibc/04-channel/client/rest/rest.go +++ b/x/ibc/04-channel/client/rest/rest.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) const ( @@ -23,14 +22,14 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string) // ChannelOpenInitReq defines the properties of a channel open init request's body. type ChannelOpenInitReq struct { - BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` - PortID string `json:"port_id" yaml:"port_id"` - ChannelID string `json:"channel_id" yaml:"channel_id"` - Version string `json:"version" yaml:"version"` - ChannelOrder ibctypes.Order `json:"channel_order" yaml:"channel_order"` - ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"` - CounterpartyPortID string `json:"counterparty_port_id" yaml:"counterparty_port_id"` - CounterpartyChannelID string `json:"counterparty_channel_id" yaml:"counterparty_channel_id"` + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + PortID string `json:"port_id" yaml:"port_id"` + ChannelID string `json:"channel_id" yaml:"channel_id"` + Version string `json:"version" yaml:"version"` + ChannelOrder types.Order `json:"channel_order" yaml:"channel_order"` + ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"` + CounterpartyPortID string `json:"counterparty_port_id" yaml:"counterparty_port_id"` + CounterpartyChannelID string `json:"counterparty_channel_id" yaml:"counterparty_channel_id"` } // ChannelOpenTryReq defines the properties of a channel open try request's body. @@ -39,7 +38,7 @@ type ChannelOpenTryReq struct { PortID string `json:"port_id" yaml:"port_id"` ChannelID string `json:"channel_id" yaml:"channel_id"` Version string `json:"version" yaml:"version"` - ChannelOrder ibctypes.Order `json:"channel_order" yaml:"channel_order"` + ChannelOrder types.Order `json:"channel_order" yaml:"channel_order"` ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"` CounterpartyPortID string `json:"counterparty_port_id" yaml:"counterparty_port_id"` CounterpartyChannelID string `json:"counterparty_channel_id" yaml:"counterparty_channel_id"` diff --git a/x/ibc/04-channel/client/utils/utils.go b/x/ibc/04-channel/client/utils/utils.go index 9886a79c03..9f5302e76b 100644 --- a/x/ibc/04-channel/client/utils/utils.go +++ b/x/ibc/04-channel/client/utils/utils.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // QueryPacket returns a packet from the store @@ -15,7 +15,7 @@ func QueryPacket( ) (types.PacketResponse, error) { req := abci.RequestQuery{ Path: "store/ibc/key", - Data: ibctypes.KeyPacketCommitment(portID, channelID, sequence), + Data: host.KeyPacketCommitment(portID, channelID, sequence), Prove: prove, } @@ -53,7 +53,7 @@ func QueryChannel( ) (types.ChannelResponse, error) { req := abci.RequestQuery{ Path: "store/ibc/key", - Data: ibctypes.KeyChannel(portID, channelID), + Data: host.KeyChannel(portID, channelID), Prove: prove, } diff --git a/x/ibc/04-channel/exported/exported.go b/x/ibc/04-channel/exported/exported.go index ed1dbc531d..bbbd84f2dc 100644 --- a/x/ibc/04-channel/exported/exported.go +++ b/x/ibc/04-channel/exported/exported.go @@ -1,13 +1,9 @@ package exported -import ( - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" -) - // ChannelI defines the standard interface for a channel end. type ChannelI interface { - GetState() ibctypes.State - GetOrdering() ibctypes.Order + GetState() int32 + GetOrdering() int32 GetCounterparty() CounterpartyI GetConnectionHops() []string GetVersion() string diff --git a/x/ibc/04-channel/keeper/handshake.go b/x/ibc/04-channel/keeper/handshake.go index 6eec946b7d..2196a956ad 100644 --- a/x/ibc/04-channel/keeper/handshake.go +++ b/x/ibc/04-channel/keeper/handshake.go @@ -7,11 +7,10 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/capability" connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" - "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types" commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // CounterpartyHops returns the connection hops of the counterparty channel. @@ -35,7 +34,7 @@ func (k Keeper) CounterpartyHops(ctx sdk.Context, ch types.Channel) ([]string, b // a module on another chain. func (k Keeper) ChanOpenInit( ctx sdk.Context, - order ibctypes.Order, + order types.Order, connectionHops []string, portID, channelID string, @@ -54,7 +53,7 @@ func (k Keeper) ChanOpenInit( return nil, sdkerrors.Wrap(connection.ErrConnectionNotFound, connectionHops[0]) } - if connectionEnd.GetState() == ibctypes.UNINITIALIZED { + if connectionEnd.GetState() == int32(connection.UNINITIALIZED) { return nil, sdkerrors.Wrap( connection.ErrInvalidConnectionState, "connection state cannot be UNINITIALIZED", @@ -65,10 +64,10 @@ func (k Keeper) ChanOpenInit( return nil, sdkerrors.Wrap(porttypes.ErrInvalidPort, "caller does not own port capability") } - channel := types.NewChannel(ibctypes.INIT, order, counterparty, connectionHops, version) + channel := types.NewChannel(types.INIT, order, counterparty, connectionHops, version) k.SetChannel(ctx, portID, channelID, channel) - capKey, err := k.scopedKeeper.NewCapability(ctx, ibctypes.ChannelCapabilityPath(portID, channelID)) + capKey, err := k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { return nil, sdkerrors.Wrap(types.ErrInvalidChannelCapability, err.Error()) } @@ -84,7 +83,7 @@ func (k Keeper) ChanOpenInit( // handshake initiated by a module on another chain. func (k Keeper) ChanOpenTry( ctx sdk.Context, - order ibctypes.Order, + order types.Order, connectionHops []string, portID, channelID string, @@ -97,7 +96,7 @@ func (k Keeper) ChanOpenTry( ) (*capability.Capability, error) { // channel identifier and connection hop length checked on msg.ValidateBasic() previousChannel, found := k.GetChannel(ctx, portID, channelID) - if found && !(previousChannel.State == ibctypes.INIT && + if found && !(previousChannel.State == types.INIT && previousChannel.Ordering == order && previousChannel.Counterparty.PortID == counterparty.PortID && previousChannel.Counterparty.ChannelID == counterparty.ChannelID && @@ -115,16 +114,16 @@ func (k Keeper) ChanOpenTry( return nil, sdkerrors.Wrap(connection.ErrConnectionNotFound, connectionHops[0]) } - if connectionEnd.GetState() != ibctypes.OPEN { + if connectionEnd.GetState() != int32(connection.OPEN) { return nil, sdkerrors.Wrapf( connection.ErrInvalidConnectionState, - "connection state is not OPEN (got %s)", connectionEnd.GetState().String(), + "connection state is not OPEN (got %s)", connection.State(connectionEnd.GetState()).String(), ) } // NOTE: this step has been switched with the one below to reverse the connection // hops - channel := types.NewChannel(ibctypes.TRYOPEN, order, counterparty, connectionHops, version) + channel := types.NewChannel(types.TRYOPEN, order, counterparty, connectionHops, version) counterpartyHops, found := k.CounterpartyHops(ctx, channel) if !found { @@ -136,7 +135,7 @@ func (k Keeper) ChanOpenTry( // (i.e self) expectedCounterparty := types.NewCounterparty(portID, channelID) expectedChannel := types.NewChannel( - ibctypes.INIT, channel.Ordering, expectedCounterparty, + types.INIT, channel.Ordering, expectedCounterparty, counterpartyHops, counterpartyVersion, ) @@ -149,7 +148,7 @@ func (k Keeper) ChanOpenTry( k.SetChannel(ctx, portID, channelID, channel) - capKey, err := k.scopedKeeper.NewCapability(ctx, ibctypes.ChannelCapabilityPath(portID, channelID)) + capKey, err := k.scopedKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { return nil, sdkerrors.Wrap(types.ErrInvalidChannelCapability, err.Error()) } @@ -177,14 +176,14 @@ func (k Keeper) ChanOpenAck( return sdkerrors.Wrap(types.ErrChannelNotFound, channelID) } - if !(channel.State == ibctypes.INIT || channel.State == ibctypes.TRYOPEN) { + if !(channel.State == types.INIT || channel.State == types.TRYOPEN) { return sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel state should be INIT or TRYOPEN (got %s)", channel.State.String(), ) } - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, ibctypes.ChannelCapabilityPath(portID, channelID)) { + if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel") } @@ -193,10 +192,10 @@ func (k Keeper) ChanOpenAck( return sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0]) } - if connectionEnd.GetState() != ibctypes.OPEN { + if connectionEnd.GetState() != int32(connection.OPEN) { return sdkerrors.Wrapf( connection.ErrInvalidConnectionState, - "connection state is not OPEN (got %s)", connectionEnd.GetState().String(), + "connection state is not OPEN (got %s)", connection.State(connectionEnd.GetState()).String(), ) } @@ -209,7 +208,7 @@ func (k Keeper) ChanOpenAck( // counterparty of the counterparty channel end (i.e self) expectedCounterparty := types.NewCounterparty(portID, channelID) expectedChannel := types.NewChannel( - ibctypes.TRYOPEN, channel.Ordering, expectedCounterparty, + types.TRYOPEN, channel.Ordering, expectedCounterparty, counterpartyHops, counterpartyVersion, ) @@ -221,7 +220,7 @@ func (k Keeper) ChanOpenAck( return err } - channel.State = ibctypes.OPEN + channel.State = types.OPEN channel.Version = counterpartyVersion k.SetChannel(ctx, portID, channelID, channel) @@ -244,14 +243,14 @@ func (k Keeper) ChanOpenConfirm( return sdkerrors.Wrap(types.ErrChannelNotFound, channelID) } - if channel.State != ibctypes.TRYOPEN { + if channel.State != types.TRYOPEN { return sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel state is not TRYOPEN (got %s)", channel.State.String(), ) } - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, ibctypes.ChannelCapabilityPath(portID, channelID)) { + if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel") } @@ -260,10 +259,10 @@ func (k Keeper) ChanOpenConfirm( return sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0]) } - if connectionEnd.GetState() != ibctypes.OPEN { + if connectionEnd.GetState() != int32(connection.OPEN) { return sdkerrors.Wrapf( connection.ErrInvalidConnectionState, - "connection state is not OPEN (got %s)", connectionEnd.GetState().String(), + "connection state is not OPEN (got %s)", connection.State(connectionEnd.GetState()).String(), ) } @@ -275,7 +274,7 @@ func (k Keeper) ChanOpenConfirm( counterparty := types.NewCounterparty(portID, channelID) expectedChannel := types.NewChannel( - ibctypes.OPEN, channel.Ordering, counterparty, + types.OPEN, channel.Ordering, counterparty, counterpartyHops, channel.Version, ) @@ -287,7 +286,7 @@ func (k Keeper) ChanOpenConfirm( return err } - channel.State = ibctypes.OPEN + channel.State = types.OPEN k.SetChannel(ctx, portID, channelID, channel) k.Logger(ctx).Info(fmt.Sprintf("channel (port-id: %s, channel-id: %s) state updated: TRYOPEN -> OPEN", portID, channelID)) @@ -307,7 +306,7 @@ func (k Keeper) ChanCloseInit( channelID string, chanCap *capability.Capability, ) error { - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, ibctypes.ChannelCapabilityPath(portID, channelID)) { + if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel") } @@ -316,7 +315,7 @@ func (k Keeper) ChanCloseInit( return sdkerrors.Wrap(types.ErrChannelNotFound, channelID) } - if channel.State == ibctypes.CLOSED { + if channel.State == types.CLOSED { return sdkerrors.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") } @@ -325,16 +324,16 @@ func (k Keeper) ChanCloseInit( return sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0]) } - if connectionEnd.GetState() != ibctypes.OPEN { + if connectionEnd.GetState() != int32(connection.OPEN) { return sdkerrors.Wrapf( connection.ErrInvalidConnectionState, - "connection state is not OPEN (got %s)", connectionEnd.GetState().String(), + "connection state is not OPEN (got %s)", connection.State(connectionEnd.GetState()).String(), ) } k.Logger(ctx).Info(fmt.Sprintf("channel (port-id: %s, channel-id: %s) state updated: %s -> CLOSED", portID, channelID, channel.State)) - channel.State = ibctypes.CLOSED + channel.State = types.CLOSED k.SetChannel(ctx, portID, channelID, channel) return nil @@ -350,7 +349,7 @@ func (k Keeper) ChanCloseConfirm( proofInit commitmentexported.Proof, proofHeight uint64, ) error { - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, ibctypes.ChannelCapabilityPath(portID, channelID)) { + if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel") } @@ -359,7 +358,7 @@ func (k Keeper) ChanCloseConfirm( return sdkerrors.Wrap(types.ErrChannelNotFound, channelID) } - if channel.State == ibctypes.CLOSED { + if channel.State == types.CLOSED { return sdkerrors.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") } @@ -368,10 +367,10 @@ func (k Keeper) ChanCloseConfirm( return sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0]) } - if connectionEnd.GetState() != ibctypes.OPEN { + if connectionEnd.GetState() != int32(connection.OPEN) { return sdkerrors.Wrapf( connection.ErrInvalidConnectionState, - "connection state is not OPEN (got %s)", connectionEnd.GetState().String(), + "connection state is not OPEN (got %s)", connection.State(connectionEnd.GetState()).String(), ) } @@ -383,7 +382,7 @@ func (k Keeper) ChanCloseConfirm( counterparty := types.NewCounterparty(portID, channelID) expectedChannel := types.NewChannel( - ibctypes.CLOSED, channel.Ordering, counterparty, + types.CLOSED, channel.Ordering, counterparty, counterpartyHops, channel.Version, ) @@ -397,7 +396,7 @@ func (k Keeper) ChanCloseConfirm( k.Logger(ctx).Info(fmt.Sprintf("channel (port-id: %s, channel-id: %s) state updated: %s -> CLOSED", portID, channelID, channel.State)) - channel.State = ibctypes.CLOSED + channel.State = types.CLOSED k.SetChannel(ctx, portID, channelID, channel) return nil diff --git a/x/ibc/04-channel/keeper/handshake_test.go b/x/ibc/04-channel/keeper/handshake_test.go index afe9230789..d2c5ac6f03 100644 --- a/x/ibc/04-channel/keeper/handshake_test.go +++ b/x/ibc/04-channel/keeper/handshake_test.go @@ -4,8 +4,9 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/x/capability" + connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) func (suite *KeeperTestSuite) TestChanOpenInit() { @@ -16,26 +17,26 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { {"success", func() { suite.chainA.createConnection( testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, - ibctypes.INIT, + connection.INIT, ) }, true}, {"channel already exists", func() { suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.INIT, + types.ORDERED, testConnectionIDA, ) }, false}, {"connection doesn't exist", func() {}, false}, {"connection is UNINITIALIZED", func() { suite.chainA.createConnection( testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, - ibctypes.UNINITIALIZED, + connection.UNINITIALIZED, ) }, false}, {"capability is incorrect", func() { suite.chainA.createConnection( testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, - ibctypes.INIT, + connection.INIT, ) portCap = capability.NewCapability(3) }, false}, @@ -49,13 +50,13 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { var err error portCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability( - suite.chainA.GetContext(), ibctypes.PortPath(testPort1), + suite.chainA.GetContext(), host.PortPath(testPort1), ) suite.Require().NoError(err, "could not create capability") tc.malleate() cap, err := suite.chainA.App.IBCKeeper.ChannelKeeper.ChanOpenInit( - suite.chainA.GetContext(), ibctypes.ORDERED, []string{testConnectionIDA}, + suite.chainA.GetContext(), types.ORDERED, []string{testConnectionIDA}, testPort1, testChannel1, portCap, counterparty, testChannelVersion, ) @@ -64,7 +65,7 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { suite.Require().NotNil(cap) chanCap, ok := suite.chainA.App.ScopedIBCKeeper.GetCapability( suite.chainA.GetContext(), - ibctypes.ChannelCapabilityPath(testPort1, testChannel1), + host.ChannelCapabilityPath(testPort1, testChannel1), ) suite.Require().True(ok, "could not retrieve channel capapbility after successful ChanOpenInit") suite.Require().Equal(chanCap.String(), cap.String(), "channel capability is not correct") @@ -77,7 +78,7 @@ func (suite *KeeperTestSuite) TestChanOpenInit() { func (suite *KeeperTestSuite) TestChanOpenTry() { counterparty := types.NewCounterparty(testPort1, testChannel1) - channelKey := ibctypes.KeyChannel(testPort1, testChannel1) + channelKey := host.KeyChannel(testPort1, testChannel1) var portCap *capability.Capability testCases := []testCase{ @@ -86,36 +87,36 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) suite.chainB.createConnection( - testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT, ibctypes.ORDERED, testConnectionIDA) + testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.INIT, types.ORDERED, testConnectionIDA) }, true}, {"previous channel with invalid state", func() { _ = suite.chainA.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.UNINITIALIZED, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.UNINITIALIZED, + types.ORDERED, testConnectionIDB, ) }, false}, {"connection doesn't exist", func() {}, false}, {"connection is not OPEN", func() { _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.INIT, + connection.INIT, ) }, false}, {"consensus state not found", func() { _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) }, false}, {"channel verification failed", func() { suite.chainA.CreateClient(suite.chainB) _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) }, false}, {"port capability not found", func() { @@ -123,11 +124,11 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) suite.chainB.createConnection( - testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT, ibctypes.ORDERED, testConnectionIDA) + testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.INIT, types.ORDERED, testConnectionIDA) portCap = capability.NewCapability(3) }, false}, } @@ -139,7 +140,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { suite.SetupTest() // reset var err error - portCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), ibctypes.PortPath(testPort2)) + portCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), host.PortPath(testPort2)) suite.Require().NoError(err, "could not create capability") tc.malleate() @@ -150,7 +151,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { if tc.expPass { cap, err := suite.chainA.App.IBCKeeper.ChannelKeeper.ChanOpenTry( - suite.chainA.GetContext(), ibctypes.ORDERED, []string{testConnectionIDB}, + suite.chainA.GetContext(), types.ORDERED, []string{testConnectionIDB}, testPort2, testChannel2, portCap, counterparty, testChannelVersion, testChannelVersion, proof, proofHeight+1, ) @@ -158,15 +159,15 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { suite.Require().NotNil(cap) chanCap, ok := suite.chainA.App.ScopedIBCKeeper.GetCapability( suite.chainA.GetContext(), - ibctypes.ChannelCapabilityPath(testPort2, testChannel2), + host.ChannelCapabilityPath(testPort2, testChannel2), ) suite.Require().True(ok, "could not retrieve channel capapbility after successful ChanOpenInit") suite.Require().Equal(chanCap.String(), cap.String(), "channel capability is not correct") } else { _, err := suite.chainA.App.IBCKeeper.ChannelKeeper.ChanOpenTry( - suite.chainA.GetContext(), ibctypes.ORDERED, []string{testConnectionIDB}, + suite.chainA.GetContext(), types.ORDERED, []string{testConnectionIDB}, testPort2, testChannel2, portCap, counterparty, testChannelVersion, testChannelVersion, - invalidProof{}, proofHeight, + proof, proofHeight, ) suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg) } @@ -175,7 +176,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() { } func (suite *KeeperTestSuite) TestChanOpenAck() { - channelKey := ibctypes.KeyChannel(testPort2, testChannel2) + channelKey := host.KeyChannel(testPort2, testChannel2) var channelCap *capability.Capability testCases := []testCase{ @@ -184,63 +185,63 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { suite.chainB.CreateClient(suite.chainA) suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainB.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT, - ibctypes.ORDERED, testConnectionIDB, + testPort1, testChannel1, testPort2, testChannel2, types.INIT, + types.ORDERED, testConnectionIDB, ) suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort2, testChannel2, testPort1, testChannel1, types.TRYOPEN, + types.ORDERED, testConnectionIDA, ) }, true}, {"channel doesn't exist", func() {}, false}, {"channel state is not INIT or TRYOPEN", func() { _ = suite.chainB.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.UNINITIALIZED, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.UNINITIALIZED, + types.ORDERED, testConnectionIDA, ) }, false}, {"connection not found", func() { _ = suite.chainB.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.TRYOPEN, + types.ORDERED, testConnectionIDA, ) }, false}, {"connection is not OPEN", func() { _ = suite.chainB.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.TRYOPEN, + connection.TRYOPEN, ) _ = suite.chainB.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.TRYOPEN, + types.ORDERED, testConnectionIDA, ) }, false}, {"consensus state not found", func() { _ = suite.chainB.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainB.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.TRYOPEN, + types.ORDERED, testConnectionIDA, ) }, false}, {"channel verification failed", func() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainB.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainB.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.TRYOPEN, + types.ORDERED, testConnectionIDA, ) }, false}, {"channel capability not found", func() { @@ -248,19 +249,19 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { suite.chainB.CreateClient(suite.chainA) suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainB.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT, - ibctypes.ORDERED, testConnectionIDB, + testPort1, testChannel1, testPort2, testChannel2, types.INIT, + types.ORDERED, testConnectionIDB, ) suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort2, testChannel2, testPort1, testChannel1, types.TRYOPEN, + types.ORDERED, testConnectionIDA, ) channelCap = capability.NewCapability(3) }, false}, @@ -273,7 +274,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { suite.SetupTest() // reset var err error - channelCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), ibctypes.ChannelCapabilityPath(testPort1, testChannel1)) + channelCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(testPort1, testChannel1)) suite.Require().NoError(err, "could not create capability") tc.malleate() @@ -291,7 +292,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { } else { err := suite.chainA.App.IBCKeeper.ChannelKeeper.ChanOpenAck( suite.chainA.GetContext(), testPort1, testChannel1, channelCap, testChannelVersion, - invalidProof{}, proofHeight+1, + proof, proofHeight+1, ) suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg) } @@ -300,7 +301,7 @@ func (suite *KeeperTestSuite) TestChanOpenAck() { } func (suite *KeeperTestSuite) TestChanOpenConfirm() { - channelKey := ibctypes.KeyChannel(testPort2, testChannel2) + channelKey := host.KeyChannel(testPort2, testChannel2) var channelCap *capability.Capability testCases := []testCase{ @@ -309,61 +310,61 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.TRYOPEN, + connection.TRYOPEN, ) _ = suite.chainB.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainA.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.OPEN, + types.ORDERED, testConnectionIDB, ) _ = suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, - ibctypes.TRYOPEN, ibctypes.ORDERED, testConnectionIDA) + types.TRYOPEN, types.ORDERED, testConnectionIDA) }, true}, {"channel doesn't exist", func() {}, false}, {"channel state is not TRYOPEN", func() { _ = suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.UNINITIALIZED, - ibctypes.ORDERED, testConnectionIDB, + testPort1, testChannel1, testPort2, testChannel2, types.UNINITIALIZED, + types.ORDERED, testConnectionIDB, ) }, false}, {"connection not found", func() { _ = suite.chainA.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.TRYOPEN, + types.ORDERED, testConnectionIDB, ) }, false}, {"connection is not OPEN", func() { _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.TRYOPEN, + connection.TRYOPEN, ) _ = suite.chainA.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.TRYOPEN, + types.ORDERED, testConnectionIDB, ) }, false}, {"consensus state not found", func() { _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainA.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.TRYOPEN, + types.ORDERED, testConnectionIDB, ) }, false}, {"channel verification failed", func() { suite.chainA.CreateClient(suite.chainB) _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainA.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.TRYOPEN, + types.ORDERED, testConnectionIDB, ) }, false}, {"channel capability not found", func() { @@ -371,18 +372,18 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainA.createConnection( testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, - ibctypes.TRYOPEN, + connection.TRYOPEN, ) suite.chainB.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainA.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.OPEN, + types.ORDERED, testConnectionIDB, ) suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, - ibctypes.TRYOPEN, ibctypes.ORDERED, testConnectionIDA) + types.TRYOPEN, types.ORDERED, testConnectionIDA) channelCap = capability.NewCapability(3) }, false}, } @@ -394,7 +395,7 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { suite.SetupTest() // reset var err error - channelCap, err = suite.chainB.App.ScopedIBCKeeper.NewCapability(suite.chainB.GetContext(), ibctypes.ChannelCapabilityPath(testPort1, testChannel1)) + channelCap, err = suite.chainB.App.ScopedIBCKeeper.NewCapability(suite.chainB.GetContext(), host.ChannelCapabilityPath(testPort1, testChannel1)) suite.Require().NoError(err, "could not create capability") tc.malleate() @@ -412,7 +413,7 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() { } else { err := suite.chainB.App.IBCKeeper.ChannelKeeper.ChanOpenConfirm( suite.chainB.GetContext(), testPort1, testChannel1, channelCap, - invalidProof{}, proofHeight+1, + proof, proofHeight+1, ) suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg) } @@ -427,45 +428,45 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainA.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.OPEN, + types.ORDERED, testConnectionIDA, ) }, true}, {"channel doesn't exist", func() {}, false}, {"channel state is CLOSED", func() { _ = suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, - ibctypes.ORDERED, testConnectionIDB, + testPort1, testChannel1, testPort2, testChannel2, types.CLOSED, + types.ORDERED, testConnectionIDB, ) }, false}, {"connection not found", func() { _ = suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.OPEN, + types.ORDERED, testConnectionIDA, ) }, false}, {"connection is not OPEN", func() { _ = suite.chainA.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.TRYOPEN, + connection.TRYOPEN, ) _ = suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.UNINITIALIZED, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.UNINITIALIZED, + types.ORDERED, testConnectionIDA, ) }, false}, {"channel capability not found", func() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainA.createConnection( testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.OPEN, + types.ORDERED, testConnectionIDA, ) channelCap = capability.NewCapability(3) }, false}, @@ -478,7 +479,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { suite.SetupTest() // reset var err error - channelCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), ibctypes.ChannelCapabilityPath(testPort1, testChannel1)) + channelCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(testPort1, testChannel1)) suite.Require().NoError(err, "could not create capability") tc.malleate() @@ -496,7 +497,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() { } func (suite *KeeperTestSuite) TestChanCloseConfirm() { - channelKey := ibctypes.KeyChannel(testPort1, testChannel1) + channelKey := host.KeyChannel(testPort1, testChannel1) var channelCap *capability.Capability testCases := []testCase{ @@ -505,63 +506,63 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainB.createConnection( testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) suite.chainA.createConnection( testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.OPEN, + types.ORDERED, testConnectionIDB, ) suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.CLOSED, + types.ORDERED, testConnectionIDA, ) }, true}, {"channel doesn't exist", func() {}, false}, {"channel state is CLOSED", func() { _ = suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.CLOSED, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.CLOSED, + types.ORDERED, testConnectionIDB, ) }, false}, {"connection not found", func() { _ = suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDA, + testPort2, testChannel2, testPort1, testChannel1, types.OPEN, + types.ORDERED, testConnectionIDA, ) }, false}, {"connection is not OPEN", func() { _ = suite.chainB.createConnection( testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, - ibctypes.TRYOPEN, + connection.TRYOPEN, ) _ = suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.OPEN, + types.ORDERED, testConnectionIDB, ) }, false}, {"consensus state not found", func() { _ = suite.chainB.createConnection( testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.OPEN, + types.ORDERED, testConnectionIDB, ) }, false}, {"channel verification failed", func() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainB.createConnection( testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.OPEN, + types.ORDERED, testConnectionIDB, ) }, false}, {"channel capability not found", func() { @@ -569,19 +570,19 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { suite.chainB.CreateClient(suite.chainA) _ = suite.chainB.createConnection( testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, - ibctypes.OPEN, + connection.OPEN, ) suite.chainA.createConnection( testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, - ibctypes.OPEN, + connection.OPEN, ) _ = suite.chainB.createChannel( - testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, - ibctypes.ORDERED, testConnectionIDB, + testPort2, testChannel2, testPort1, testChannel1, types.OPEN, + types.ORDERED, testConnectionIDB, ) suite.chainA.createChannel( - testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, - ibctypes.ORDERED, testConnectionIDA, + testPort1, testChannel1, testPort2, testChannel2, types.CLOSED, + types.ORDERED, testConnectionIDA, ) }, false}, } @@ -593,7 +594,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { suite.SetupTest() // reset var err error - channelCap, err = suite.chainB.App.ScopedIBCKeeper.NewCapability(suite.chainB.GetContext(), ibctypes.ChannelCapabilityPath(testPort2, testChannel2)) + channelCap, err = suite.chainB.App.ScopedIBCKeeper.NewCapability(suite.chainB.GetContext(), host.ChannelCapabilityPath(testPort2, testChannel2)) suite.Require().NoError(err, "could not create capability") tc.malleate() @@ -611,7 +612,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { } else { err := suite.chainB.App.IBCKeeper.ChannelKeeper.ChanCloseConfirm( suite.chainB.GetContext(), testPort2, testChannel2, channelCap, - invalidProof{}, proofHeight, + proof, proofHeight, ) suite.Require().Error(err, "invalid test case %d passed: %s", i, tc.msg) } diff --git a/x/ibc/04-channel/keeper/keeper.go b/x/ibc/04-channel/keeper/keeper.go index d44d7ee5ad..b08cc0d09e 100644 --- a/x/ibc/04-channel/keeper/keeper.go +++ b/x/ibc/04-channel/keeper/keeper.go @@ -13,7 +13,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // Keeper defines the IBC channel keeper @@ -44,13 +45,13 @@ func NewKeeper( // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", ibctypes.ModuleName, types.SubModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", host.ModuleName, types.SubModuleName)) } // GetChannel returns a channel with a particular identifier binded to a specific port func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (types.Channel, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(ibctypes.KeyChannel(portID, channelID)) + bz := store.Get(host.KeyChannel(portID, channelID)) if bz == nil { return types.Channel{}, false } @@ -64,13 +65,13 @@ func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (types.Cha func (k Keeper) SetChannel(ctx sdk.Context, portID, channelID string, channel types.Channel) { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshalBinaryBare(&channel) - store.Set(ibctypes.KeyChannel(portID, channelID), bz) + store.Set(host.KeyChannel(portID, channelID), bz) } // GetNextSequenceSend gets a channel's next send sequence from the store func (k Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(ibctypes.KeyNextSequenceSend(portID, channelID)) + bz := store.Get(host.KeyNextSequenceSend(portID, channelID)) if bz == nil { return 0, false } @@ -82,13 +83,13 @@ func (k Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) ( func (k Keeper) SetNextSequenceSend(ctx sdk.Context, portID, channelID string, sequence uint64) { store := ctx.KVStore(k.storeKey) bz := sdk.Uint64ToBigEndian(sequence) - store.Set(ibctypes.KeyNextSequenceSend(portID, channelID), bz) + store.Set(host.KeyNextSequenceSend(portID, channelID), bz) } // GetNextSequenceRecv gets a channel's next receive sequence from the store func (k Keeper) GetNextSequenceRecv(ctx sdk.Context, portID, channelID string) (uint64, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(ibctypes.KeyNextSequenceRecv(portID, channelID)) + bz := store.Get(host.KeyNextSequenceRecv(portID, channelID)) if bz == nil { return 0, false } @@ -100,37 +101,37 @@ func (k Keeper) GetNextSequenceRecv(ctx sdk.Context, portID, channelID string) ( func (k Keeper) SetNextSequenceRecv(ctx sdk.Context, portID, channelID string, sequence uint64) { store := ctx.KVStore(k.storeKey) bz := sdk.Uint64ToBigEndian(sequence) - store.Set(ibctypes.KeyNextSequenceRecv(portID, channelID), bz) + store.Set(host.KeyNextSequenceRecv(portID, channelID), bz) } // GetPacketCommitment gets the packet commitment hash from the store func (k Keeper) GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte { store := ctx.KVStore(k.storeKey) - bz := store.Get(ibctypes.KeyPacketCommitment(portID, channelID, sequence)) + bz := store.Get(host.KeyPacketCommitment(portID, channelID, sequence)) return bz } // SetPacketCommitment sets the packet commitment hash to the store func (k Keeper) SetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64, commitmentHash []byte) { store := ctx.KVStore(k.storeKey) - store.Set(ibctypes.KeyPacketCommitment(portID, channelID, sequence), commitmentHash) + store.Set(host.KeyPacketCommitment(portID, channelID, sequence), commitmentHash) } func (k Keeper) deletePacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) { store := ctx.KVStore(k.storeKey) - store.Delete(ibctypes.KeyPacketCommitment(portID, channelID, sequence)) + store.Delete(host.KeyPacketCommitment(portID, channelID, sequence)) } // SetPacketAcknowledgement sets the packet ack hash to the store func (k Keeper) SetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64, ackHash []byte) { store := ctx.KVStore(k.storeKey) - store.Set(ibctypes.KeyPacketAcknowledgement(portID, channelID, sequence), ackHash) + store.Set(host.KeyPacketAcknowledgement(portID, channelID, sequence), ackHash) } // GetPacketAcknowledgement gets the packet ack hash from the store func (k Keeper) GetPacketAcknowledgement(ctx sdk.Context, portID, channelID string, sequence uint64) ([]byte, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(ibctypes.KeyPacketAcknowledgement(portID, channelID, sequence)) + bz := store.Get(host.KeyPacketAcknowledgement(portID, channelID, sequence)) if bz == nil { return nil, false } @@ -144,9 +145,9 @@ func (k Keeper) IteratePacketSequence(ctx sdk.Context, send bool, cb func(portID store := ctx.KVStore(k.storeKey) var iterator db.Iterator if send { - iterator = sdk.KVStorePrefixIterator(store, []byte(ibctypes.KeyNextSeqSendPrefix)) + iterator = sdk.KVStorePrefixIterator(store, []byte(host.KeyNextSeqSendPrefix)) } else { - iterator = sdk.KVStorePrefixIterator(store, []byte(ibctypes.KeyNextSeqRecvPrefix)) + iterator = sdk.KVStorePrefixIterator(store, []byte(host.KeyNextSeqRecvPrefix)) } defer iterator.Close() @@ -188,7 +189,7 @@ func (k Keeper) GetAllPacketRecvSeqs(ctx sdk.Context) (seqs []types.PacketSequen // and stop. func (k Keeper) IteratePacketCommitment(ctx sdk.Context, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte(ibctypes.KeyPacketCommitmentPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte(host.KeyPacketCommitmentPrefix)) k.iterateHashes(ctx, iterator, cb) } @@ -207,7 +208,7 @@ func (k Keeper) GetAllPacketCommitments(ctx sdk.Context) (commitments []types.Pa // and stop. func (k Keeper) IteratePacketAcknowledgement(ctx sdk.Context, cb func(portID, channelID string, sequence uint64, hash []byte) bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte(ibctypes.KeyPacketAckPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte(host.KeyPacketAckPrefix)) k.iterateHashes(ctx, iterator, cb) } @@ -226,14 +227,14 @@ func (k Keeper) GetAllPacketAcks(ctx sdk.Context) (acks []types.PacketAckCommitm // and stop. func (k Keeper) IterateChannels(ctx sdk.Context, cb func(types.IdentifiedChannel) bool) { store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, []byte(ibctypes.KeyChannelPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte(host.KeyChannelPrefix)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var channel types.Channel k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &channel) - portID, channelID := ibctypes.MustParseChannelPath(string(iterator.Key())) + portID, channelID := host.MustParseChannelPath(string(iterator.Key())) identifiedChannel := types.NewIdentifiedChannel(portID, channelID, channel) if cb(identifiedChannel) { break @@ -252,12 +253,12 @@ func (k Keeper) GetAllChannels(ctx sdk.Context) (channels []types.IdentifiedChan // LookupModuleByChannel will return the IBCModule along with the capability associated with a given channel defined by its portID and channelID func (k Keeper) LookupModuleByChannel(ctx sdk.Context, portID, channelID string) (string, *capability.Capability, error) { - modules, cap, err := k.scopedKeeper.LookupModules(ctx, ibctypes.ChannelCapabilityPath(portID, channelID)) + modules, cap, err := k.scopedKeeper.LookupModules(ctx, host.ChannelCapabilityPath(portID, channelID)) if err != nil { return "", nil, err } - return ibctypes.GetModuleOwner(modules), cap, nil + return porttypes.GetModuleOwner(modules), cap, nil } // common functionality for IteratePacketCommitment and IteratePacketAcknowledgemen diff --git a/x/ibc/04-channel/keeper/keeper_test.go b/x/ibc/04-channel/keeper/keeper_test.go index fd9a5ce5c5..6c13b67c90 100644 --- a/x/ibc/04-channel/keeper/keeper_test.go +++ b/x/ibc/04-channel/keeper/keeper_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - "bytes" - "errors" "fmt" "testing" "time" @@ -18,9 +16,9 @@ import ( connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" + "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -40,7 +38,7 @@ const ( testChannel2 = "secondchannel" testChannel3 = "thirdchannel" - testChannelOrder = ibctypes.ORDERED + testChannelOrder = types.ORDERED testChannelVersion = "1.0" trustingPeriod time.Duration = time.Hour * 24 * 7 * 2 @@ -76,7 +74,7 @@ func (suite *KeeperTestSuite) TestSetChannel() { counterparty2 := types.NewCounterparty(testPort2, testChannel2) channel := types.NewChannel( - ibctypes.INIT, testChannelOrder, + types.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, ) suite.chainB.App.IBCKeeper.ChannelKeeper.SetChannel(ctx, testPort1, testChannel1, channel) @@ -93,15 +91,15 @@ func (suite KeeperTestSuite) TestGetAllChannels() { counterparty3 := types.NewCounterparty(testPort3, testChannel3) channel1 := types.NewChannel( - ibctypes.INIT, testChannelOrder, + types.INIT, testChannelOrder, counterparty3, []string{testConnectionIDA}, testChannelVersion, ) channel2 := types.NewChannel( - ibctypes.INIT, testChannelOrder, + types.INIT, testChannelOrder, counterparty1, []string{testConnectionIDA}, testChannelVersion, ) channel3 := types.NewChannel( - ibctypes.CLOSED, testChannelOrder, + types.CLOSED, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, ) @@ -239,7 +237,7 @@ func commitBlockWithNewTimestamp(chain *TestChain, timestamp int64) { // nolint: unused func queryProof(chain *TestChain, key []byte) (commitmenttypes.MerkleProof, uint64) { res := chain.App.Query(abci.RequestQuery{ - Path: fmt.Sprintf("store/%s/key", ibctypes.StoreKey), + Path: fmt.Sprintf("store/%s/key", host.StoreKey), Height: chain.App.LastBlockHeight(), Data: key, Prove: true, @@ -403,7 +401,7 @@ func (chain *TestChain) updateClient(client *TestChain) { func (chain *TestChain) createConnection( connID, counterpartyConnID, clientID, counterpartyClientID string, - state ibctypes.State, + state connectiontypes.State, ) connectiontypes.ConnectionEnd { counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())) connection := connectiontypes.ConnectionEnd{ @@ -419,7 +417,7 @@ func (chain *TestChain) createConnection( func (chain *TestChain) createChannel( portID, channelID, counterpartyPortID, counterpartyChannelID string, - state ibctypes.State, order ibctypes.Order, connectionID string, + state types.State, order types.Order, connectionID string, ) types.Channel { counterparty := types.NewCounterparty(counterpartyPortID, counterpartyChannelID) channel := types.NewChannel(state, order, counterparty, @@ -436,66 +434,13 @@ func nextHeader(chain *TestChain) ibctmtypes.Header { } // Mocked types -// TODO: fix tests and replace for real proofs -var ( - _ commitmentexported.Proof = validProof{nil, nil, nil} - _ commitmentexported.Proof = invalidProof{} -) +type mockSuccessPacket struct{} -type ( - validProof struct { - root commitmentexported.Root - path commitmentexported.Path - value []byte - } - invalidProof struct{} -) +// GetBytes returns the serialised packet data +func (mp mockSuccessPacket) GetBytes() []byte { return []byte("THIS IS A SUCCESS PACKET") } -func (validProof) GetCommitmentType() commitmentexported.Type { - return commitmentexported.Merkle -} +type mockFailPacket struct{} -func (proof validProof) VerifyMembership( - root commitmentexported.Root, path commitmentexported.Path, value []byte, -) error { - if bytes.Equal(root.GetHash(), proof.root.GetHash()) && - path.String() == proof.path.String() && - bytes.Equal(value, proof.value) { - return nil - } - return errors.New("invalid proof") -} - -func (validProof) VerifyNonMembership(root commitmentexported.Root, path commitmentexported.Path) error { - return nil -} - -func (validProof) ValidateBasic() error { - return nil -} - -func (validProof) IsEmpty() bool { - return false -} - -func (invalidProof) GetCommitmentType() commitmentexported.Type { - return commitmentexported.Merkle -} - -func (invalidProof) VerifyMembership( - root commitmentexported.Root, path commitmentexported.Path, value []byte) error { - return errors.New("proof failed") -} - -func (invalidProof) VerifyNonMembership(root commitmentexported.Root, path commitmentexported.Path) error { - return errors.New("proof failed") -} - -func (invalidProof) ValidateBasic() error { - return errors.New("invalid proof") -} - -func (invalidProof) IsEmpty() bool { - return true -} +// GetBytes returns the serialised packet data (without timeout) +func (mp mockFailPacket) GetBytes() []byte { return []byte("THIS IS A FAILURE PACKET") } diff --git a/x/ibc/04-channel/keeper/packet.go b/x/ibc/04-channel/keeper/packet.go index 8e0e2eb323..fa514ffc36 100644 --- a/x/ibc/04-channel/keeper/packet.go +++ b/x/ibc/04-channel/keeper/packet.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // SendPacket is called by a module in order to send an IBC packet on a channel @@ -33,14 +33,14 @@ func (k Keeper) SendPacket( return sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetSourceChannel()) } - if channel.State == ibctypes.CLOSED { + if channel.State == types.CLOSED { return sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel is CLOSED (got %s)", channel.State.String(), ) } - if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, ibctypes.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())) { + if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())) { return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel") } @@ -64,10 +64,10 @@ func (k Keeper) SendPacket( } // NOTE: assume UNINITIALIZED is a closed connection - if connectionEnd.GetState() == ibctypes.UNINITIALIZED { + if connectionEnd.GetState() == int32(connection.UNINITIALIZED) { return sdkerrors.Wrap( connection.ErrInvalidConnectionState, - "connection is closed (i.e NONE)", + "connection is UNINITIALIZED", ) } @@ -146,7 +146,7 @@ func (k Keeper) RecvPacket( return nil, sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetDestChannel()) } - if channel.State != ibctypes.OPEN { + if channel.State != types.OPEN { return nil, sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), @@ -176,10 +176,10 @@ func (k Keeper) RecvPacket( return nil, sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0]) } - if connectionEnd.GetState() != ibctypes.OPEN { + if connectionEnd.GetState() != int32(connection.OPEN) { return nil, sdkerrors.Wrapf( connection.ErrInvalidConnectionState, - "connection state is not OPEN (got %s)", connectionEnd.GetState().String(), + "connection state is not OPEN (got %s)", connection.State(connectionEnd.GetState()).String(), ) } @@ -225,26 +225,26 @@ func (k Keeper) PacketExecuted( } // sanity check - if channel.State != ibctypes.OPEN { + if channel.State != types.OPEN { return sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), ) } - capName := ibctypes.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) + capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, capName) { return sdkerrors.Wrap(types.ErrInvalidChannelCapability, "channel capability failed authentication") } - if acknowledgement != nil || channel.Ordering == ibctypes.UNORDERED { + if acknowledgement != nil || channel.Ordering == types.UNORDERED { k.SetPacketAcknowledgement( ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), types.CommitAcknowledgement(acknowledgement), ) } - if channel.Ordering == ibctypes.ORDERED { + if channel.Ordering == types.ORDERED { nextSequenceRecv, found := k.GetNextSequenceRecv(ctx, packet.GetDestPort(), packet.GetDestChannel()) if !found { return types.ErrSequenceReceiveNotFound @@ -301,7 +301,7 @@ func (k Keeper) AcknowledgePacket( return nil, sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetSourceChannel()) } - if channel.State != ibctypes.OPEN { + if channel.State != types.OPEN { return nil, sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), @@ -331,10 +331,10 @@ func (k Keeper) AcknowledgePacket( return nil, sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0]) } - if connectionEnd.GetState() != ibctypes.OPEN { + if connectionEnd.GetState() != int32(connection.OPEN) { return nil, sdkerrors.Wrapf( connection.ErrInvalidConnectionState, - "connection state is not OPEN (got %s)", connectionEnd.GetState().String(), + "connection state is not OPEN (got %s)", connection.State(connectionEnd.GetState()).String(), ) } @@ -395,7 +395,7 @@ func (k Keeper) CleanupPacket( return nil, sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetSourceChannel()) } - if channel.State != ibctypes.OPEN { + if channel.State != types.OPEN { return nil, sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), @@ -446,13 +446,13 @@ func (k Keeper) CleanupPacket( var err error switch channel.Ordering { - case ibctypes.ORDERED: + case types.ORDERED: // check that the recv sequence is as claimed err = k.connectionKeeper.VerifyNextSequenceRecv( ctx, connectionEnd, proofHeight, proof, packet.GetDestPort(), packet.GetDestChannel(), nextSequenceRecv, ) - case ibctypes.UNORDERED: + case types.UNORDERED: err = k.connectionKeeper.VerifyPacketAcknowledgement( ctx, connectionEnd, proofHeight, proof, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), diff --git a/x/ibc/04-channel/keeper/packet_test.go b/x/ibc/04-channel/keeper/packet_test.go index 05c05ee88f..48f50c93c7 100644 --- a/x/ibc/04-channel/keeper/packet_test.go +++ b/x/ibc/04-channel/keeper/packet_test.go @@ -4,11 +4,11 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/x/capability" + connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - transfertypes "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) func (suite *KeeperTestSuite) TestSendPacket() { @@ -20,8 +20,8 @@ func (suite *KeeperTestSuite) TestSendPacket() { {"success", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainB.GetContext(), testPort1, testChannel1, 1) }, true}, {"packet basic validation failed", func() { @@ -32,62 +32,62 @@ func (suite *KeeperTestSuite) TestSendPacket() { }, false}, {"channel closed", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.CLOSED, types.ORDERED, testConnectionIDA) }, false}, {"packet dest port ≠ channel counterparty port", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, testPort3, counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet dest channel ID ≠ channel counterparty channel ID", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), testChannel3, timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection is UNINITIALIZED", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.UNINITIALIZED) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"client state not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"timeout height passed", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) commitNBlocks(suite.chainB, 10) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"timeout timestamp passed", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), disabledTimeoutHeight, timeoutTimestamp) commitBlockWithNewTimestamp(suite.chainB, timeoutTimestamp) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"next sequence send not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"next sequence wrong", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainB.GetContext(), testPort1, testChannel1, 5) }, false}, {"channel capability not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainB.GetContext(), testPort1, testChannel1, 1) channelCap = capability.NewCapability(3) }, false}, @@ -99,7 +99,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { suite.SetupTest() // reset var err error - channelCap, err = suite.chainB.App.ScopedIBCKeeper.NewCapability(suite.chainB.GetContext(), ibctypes.ChannelCapabilityPath(testPort1, testChannel1)) + channelCap, err = suite.chainB.App.ScopedIBCKeeper.NewCapability(suite.chainB.GetContext(), host.ChannelCapabilityPath(testPort1, testChannel1)) suite.Require().Nil(err, "could not create capability") tc.malleate() @@ -118,7 +118,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { func (suite *KeeperTestSuite) TestRecvPacket() { counterparty := types.NewCounterparty(testPort1, testChannel1) - packetKey := ibctypes.KeyPacketCommitment(testPort2, testChannel2, 1) + packetKey := host.KeyPacketCommitment(testPort2, testChannel2, 1) var packet exported.PacketI @@ -126,10 +126,10 @@ func (suite *KeeperTestSuite) TestRecvPacket() { {"success", func() { suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDB) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDB) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort2, testChannel2, 1) packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort2, testChannel2, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), testPort2, testChannel2, 1, types.CommitPacket(packet)) @@ -138,35 +138,35 @@ func (suite *KeeperTestSuite) TestRecvPacket() { {"channel not found", func() {}, false}, {"channel not open", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.INIT, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.INIT, types.ORDERED, testConnectionIDA) }, false}, {"packet source port ≠ channel counterparty port", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort2, testChannel2, testPort3, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort2, testChannel2, testPort3, testChannel1, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet source channel ID ≠ channel counterparty channel ID", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel3, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not OPEN", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT) - suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.INIT) + suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"timeout height passed", func() { commitNBlocks(suite.chainB, 10) packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"validation failed", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, } @@ -187,7 +187,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { _, err = suite.chainB.App.IBCKeeper.ChannelKeeper.RecvPacket(ctx, packet, proof, proofHeight+1) suite.Require().NoError(err) } else { - packet, err = suite.chainB.App.IBCKeeper.ChannelKeeper.RecvPacket(ctx, packet, ibctypes.InvalidProof{}, proofHeight) + packet, err = suite.chainB.App.IBCKeeper.ChannelKeeper.RecvPacket(ctx, packet, proof, proofHeight) suite.Require().Error(err) } }) @@ -203,31 +203,31 @@ func (suite *KeeperTestSuite) TestPacketExecuted() { testCases := []testCase{ {"success: UNORDERED", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.UNORDERED, testConnectionIDA) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1) }, true}, {"success: ORDERED", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1) }, true}, {"channel not found", func() {}, false}, {"channel not OPEN", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.CLOSED, types.ORDERED, testConnectionIDA) }, false}, {"next sequence receive not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet sequence ≠ next sequence receive", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 5) }, false}, {"capability not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.UNORDERED, testConnectionIDA) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1) channelCap = capability.NewCapability(3) }, false}, @@ -239,7 +239,7 @@ func (suite *KeeperTestSuite) TestPacketExecuted() { suite.SetupTest() // reset var err error - channelCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), ibctypes.ChannelCapabilityPath(testPort2, testChannel2)) + channelCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), host.ChannelCapabilityPath(testPort2, testChannel2)) suite.Require().NoError(err, "could not create capability") tc.malleate() @@ -258,7 +258,7 @@ func (suite *KeeperTestSuite) TestPacketExecuted() { func (suite *KeeperTestSuite) TestAcknowledgePacket() { counterparty := types.NewCounterparty(testPort2, testChannel2) var packet types.Packet - packetKey := ibctypes.KeyPacketAcknowledgement(testPort2, testChannel2, 1) + packetKey := host.KeyPacketAcknowledgement(testPort2, testChannel2, 1) ack := transfertypes.FungibleTokenPacketAcknowledgement{ Success: true, @@ -269,44 +269,44 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDB) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.ORDERED, testConnectionIDB) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet)) suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketAcknowledgement(suite.chainA.GetContext(), testPort2, testChannel2, 1, types.CommitAcknowledgement(ack)) }, true}, {"channel not found", func() {}, false}, {"channel not open", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.CLOSED, types.ORDERED, testConnectionIDA) }, false}, {"packet source port ≠ channel counterparty port", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet source channel ID ≠ channel counterparty channel ID", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not OPEN", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.INIT) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet hasn't been sent", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet ack verification failed", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet)) }, false}, } @@ -337,7 +337,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { func (suite *KeeperTestSuite) TestCleanupPacket() { counterparty := types.NewCounterparty(testPort2, testChannel2) - packetKey := ibctypes.KeyPacketAcknowledgement(testPort2, testChannel2, 1) + packetKey := host.KeyPacketAcknowledgement(testPort2, testChannel2, 1) var ( packet types.Packet nextSeqRecv uint64 @@ -351,58 +351,58 @@ func (suite *KeeperTestSuite) TestCleanupPacket() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainA.CreateClient(suite.chainB) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDB) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.UNORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.UNORDERED, testConnectionIDB) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet)) suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketAcknowledgement(suite.chainA.GetContext(), testPort2, testChannel2, 1, types.CommitAcknowledgement(ack)) }, true}, {"channel not found", func() {}, false}, {"channel not open", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.CLOSED, types.ORDERED, testConnectionIDA) }, false}, {"packet source port ≠ channel counterparty port", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet source channel ID ≠ channel counterparty channel ID", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not OPEN", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.INIT) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet already received ", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 10, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet hasn't been sent", func() { nextSeqRecv = 10 packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"next seq receive verification failed", func() { nextSeqRecv = 10 packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet)) }, false}, {"packet ack verification failed", func() { nextSeqRecv = 10 packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.UNORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet)) }, false}, } @@ -424,20 +424,10 @@ func (suite *KeeperTestSuite) TestCleanupPacket() { suite.Require().NoError(err) suite.Require().NotNil(packetOut) } else { - packetOut, err := suite.chainB.App.IBCKeeper.ChannelKeeper.CleanupPacket(ctx, packet, ibctypes.InvalidProof{}, proofHeight+1, nextSeqRecv, ack) + packetOut, err := suite.chainB.App.IBCKeeper.ChannelKeeper.CleanupPacket(ctx, packet, proof, proofHeight, nextSeqRecv, ack) suite.Require().Error(err) suite.Require().Nil(packetOut) } }) } } - -type mockSuccessPacket struct{} - -// GetBytes returns the serialised packet data -func (mp mockSuccessPacket) GetBytes() []byte { return []byte("THIS IS A SUCCESS PACKET") } - -type mockFailPacket struct{} - -// GetBytes returns the serialised packet data (without timeout) -func (mp mockFailPacket) GetBytes() []byte { return []byte("THIS IS A FAILURE PACKET") } diff --git a/x/ibc/04-channel/keeper/timeout.go b/x/ibc/04-channel/keeper/timeout.go index 2647bdefef..70d427347b 100644 --- a/x/ibc/04-channel/keeper/timeout.go +++ b/x/ibc/04-channel/keeper/timeout.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // TimeoutPacket is called by a module which originally attempted to send a @@ -34,7 +34,7 @@ func (k Keeper) TimeoutPacket( ) } - if channel.State != ibctypes.OPEN { + if channel.State != types.OPEN { return nil, sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel state is not OPEN (got %s)", channel.State.String(), @@ -85,7 +85,7 @@ func (k Keeper) TimeoutPacket( } switch channel.Ordering { - case ibctypes.ORDERED: + case types.ORDERED: // check that packet has not been received if nextSequenceRecv > packet.GetSequence() { return nil, sdkerrors.Wrap(types.ErrInvalidPacket, "packet already received") @@ -96,7 +96,7 @@ func (k Keeper) TimeoutPacket( ctx, connectionEnd, proofHeight, proof, packet.GetDestPort(), packet.GetDestChannel(), nextSequenceRecv, ) - case ibctypes.UNORDERED: + case types.UNORDERED: err = k.connectionKeeper.VerifyPacketAcknowledgementAbsence( ctx, connectionEnd, proofHeight, proof, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), @@ -136,14 +136,14 @@ func (k Keeper) TimeoutExecuted(ctx sdk.Context, chanCap *capability.Capability, return sdkerrors.Wrapf(types.ErrChannelNotFound, packet.GetSourcePort(), packet.GetSourceChannel()) } - if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, ibctypes.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())) { + if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())) { return sdkerrors.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel") } k.deletePacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - if channel.Ordering == ibctypes.ORDERED { - channel.State = ibctypes.CLOSED + if channel.Ordering == types.ORDERED { + channel.State = types.CLOSED k.SetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), channel) } @@ -212,7 +212,7 @@ func (k Keeper) TimeoutOnClose( counterparty := types.NewCounterparty(packet.GetSourcePort(), packet.GetSourceChannel()) expectedChannel := types.NewChannel( - ibctypes.CLOSED, channel.Ordering, counterparty, counterpartyHops, channel.Version, + types.CLOSED, channel.Ordering, counterparty, counterpartyHops, channel.Version, ) // check that the opposing channel end has closed @@ -226,13 +226,13 @@ func (k Keeper) TimeoutOnClose( var err error switch channel.Ordering { - case ibctypes.ORDERED: + case types.ORDERED: // check that the recv sequence is as claimed err = k.connectionKeeper.VerifyNextSequenceRecv( ctx, connectionEnd, proofHeight, proof, packet.GetDestPort(), packet.GetDestChannel(), nextSequenceRecv, ) - case ibctypes.UNORDERED: + case types.UNORDERED: err = k.connectionKeeper.VerifyPacketAcknowledgementAbsence( ctx, connectionEnd, proofHeight, proof, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), diff --git a/x/ibc/04-channel/keeper/timeout_test.go b/x/ibc/04-channel/keeper/timeout_test.go index fa8c4027ed..ebc7a1391a 100644 --- a/x/ibc/04-channel/keeper/timeout_test.go +++ b/x/ibc/04-channel/keeper/timeout_test.go @@ -4,13 +4,14 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/x/capability" + connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) func (suite *KeeperTestSuite) TestTimeoutPacket() { counterparty := types.NewCounterparty(testPort2, testChannel2) - packetKey := ibctypes.KeyPacketAcknowledgement(testPort2, testChannel2, 2) + packetKey := host.KeyPacketAcknowledgement(testPort2, testChannel2, 2) var ( packet types.Packet nextSeqRecv uint64 @@ -22,58 +23,58 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 1, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDB) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.UNORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.OPEN, types.UNORDERED, testConnectionIDB) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet)) }, true}, {"channel not found", func() {}, false}, {"channel not open", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.CLOSED, types.ORDERED, testConnectionIDA) }, false}, {"packet source port ≠ channel counterparty port", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet source channel ID ≠ channel counterparty channel ID", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"timeout", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 10, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet already received ", func() { nextSeqRecv = 2 packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet hasn't been sent", func() { nextSeqRecv = 1 packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"next seq receive verification failed", func() { nextSeqRecv = 1 packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet)) }, false}, {"packet ack verification failed", func() { nextSeqRecv = 1 packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.UNORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet)) }, false}, } @@ -95,7 +96,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { suite.Require().NoError(err) suite.Require().NotNil(packetOut) } else { - packetOut, err := suite.chainB.App.IBCKeeper.ChannelKeeper.TimeoutPacket(ctx, packet, ibctypes.InvalidProof{}, proofHeight+1, nextSeqRecv) + packetOut, err := suite.chainB.App.IBCKeeper.ChannelKeeper.TimeoutPacket(ctx, packet, proof, proofHeight, nextSeqRecv) suite.Require().Error(err) suite.Require().Nil(packetOut) } @@ -110,12 +111,12 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { testCases := []testCase{ {"success ORDERED", func() { packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, true}, {"channel not found", func() {}, false}, {"incorrect capability", func() { packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) chanCap = capability.NewCapability(100) }, false}, } @@ -127,7 +128,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { var err error chanCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability( - suite.chainA.GetContext(), ibctypes.ChannelCapabilityPath(testPort1, testChannel1), + suite.chainA.GetContext(), host.ChannelCapabilityPath(testPort1, testChannel1), ) suite.Require().NoError(err, "could not create capability") @@ -145,8 +146,8 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { } func (suite *KeeperTestSuite) TestTimeoutOnClose() { - channelKey := ibctypes.KeyChannel(testPort2, testChannel2) - packetKey := ibctypes.KeyPacketAcknowledgement(testPort1, testChannel1, 2) + channelKey := host.KeyChannel(testPort2, testChannel2) + packetKey := host.KeyPacketAcknowledgement(testPort1, testChannel1, 2) counterparty := types.NewCounterparty(testPort2, testChannel2) var ( packet types.Packet @@ -158,52 +159,52 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) suite.chainA.CreateClient(suite.chainB) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) - suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.CLOSED, ibctypes.UNORDERED, testConnectionIDB) // channel on chainA is closed + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.UNORDERED, testConnectionIDA) + suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, types.CLOSED, types.UNORDERED, testConnectionIDB) // channel on chainA is closed suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet)) suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv) }, true}, {"channel not found", func() {}, false}, {"packet dest port ≠ channel counterparty port", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet dest channel ID ≠ channel counterparty channel ID", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"connection not found", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"packet hasn't been sent", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) }, false}, {"channel verification failed", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.UNORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet)) suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv) }, false}, {"next seq receive verification failed", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.ORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet)) suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv) }, false}, {"packet ack verification failed", func() { packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateClient(suite.chainA) - suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN) - suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA) + suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connection.OPEN) + suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, types.OPEN, types.UNORDERED, testConnectionIDA) suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet)) suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv) }, false}, @@ -226,7 +227,8 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { suite.Require().NoError(err) suite.Require().NotNil(packetOut) } else { - packetOut, err := suite.chainB.App.IBCKeeper.ChannelKeeper.TimeoutOnClose(ctx, packet, invalidProof{}, invalidProof{}, proofHeight+1, nextSeqRecv) + // switch the proofs to invalidate them + packetOut, err := suite.chainB.App.IBCKeeper.ChannelKeeper.TimeoutOnClose(ctx, packet, proofClosed, proofAckAbsence, proofHeight+1, nextSeqRecv) suite.Require().Error(err) suite.Require().Nil(packetOut) } diff --git a/x/ibc/04-channel/types/channel.go b/x/ibc/04-channel/types/channel.go index 11c5c7cb6f..6f99a296ef 100644 --- a/x/ibc/04-channel/types/channel.go +++ b/x/ibc/04-channel/types/channel.go @@ -6,7 +6,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) var ( @@ -16,7 +15,7 @@ var ( // NewChannel creates a new Channel instance func NewChannel( - state ibctypes.State, ordering ibctypes.Order, counterparty Counterparty, + state State, ordering Order, counterparty Counterparty, hops []string, version string, ) Channel { return Channel{ @@ -29,13 +28,13 @@ func NewChannel( } // GetState implements Channel interface. -func (ch Channel) GetState() ibctypes.State { - return ch.State +func (ch Channel) GetState() int32 { + return int32(ch.State) } // GetOrdering implements Channel interface. -func (ch Channel) GetOrdering() ibctypes.Order { - return ch.Ordering +func (ch Channel) GetOrdering() int32 { + return int32(ch.Ordering) } // GetCounterparty implements Channel interface. @@ -58,7 +57,7 @@ func (ch Channel) ValidateBasic() error { if ch.State.String() == "" { return sdkerrors.Wrap(ErrInvalidChannel, ErrInvalidChannelState.Error()) } - if !(ch.Ordering == ibctypes.ORDERED || ch.Ordering == ibctypes.UNORDERED) { + if !(ch.Ordering == ORDERED || ch.Ordering == UNORDERED) { return sdkerrors.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String()) } if len(ch.ConnectionHops) != 1 { @@ -76,7 +75,7 @@ func (ch Channel) ValidateBasic() error { if strings.TrimSpace(ch.Version) == "" { return sdkerrors.Wrap( ErrInvalidChannel, - sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "channel version can't be blank").Error(), + sdkerrors.Wrap(sdkerrors.ErrInvalidVersion, "channel version can't be blank").Error(), ) } return ch.Counterparty.ValidateBasic() @@ -120,13 +119,13 @@ func (c Counterparty) ValidateBasic() error { // IdentifiedChannel defines a channel with additional port and channel identifier // fields. type IdentifiedChannel struct { - ID string `json:"id" yaml:"id"` - PortID string `json:"port_id" yaml:"port_id"` - State ibctypes.State `json:"state" yaml:"state"` - Ordering ibctypes.Order `json:"ordering" yaml:"ordering"` - Counterparty Counterparty `json:"counterparty" yaml:"counterparty"` - ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"` - Version string `json:"version" yaml:"version "` + ID string `json:"id" yaml:"id"` + PortID string `json:"port_id" yaml:"port_id"` + State State `json:"state" yaml:"state"` + Ordering Order `json:"ordering" yaml:"ordering"` + Counterparty Counterparty `json:"counterparty" yaml:"counterparty"` + ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"` + Version string `json:"version" yaml:"version "` } // NewIdentifiedChannel creates a new IdentifiedChannel instance diff --git a/x/ibc/04-channel/types/events.go b/x/ibc/04-channel/types/events.go index e39407d883..fced7d8694 100644 --- a/x/ibc/04-channel/types/events.go +++ b/x/ibc/04-channel/types/events.go @@ -3,7 +3,7 @@ package types import ( "fmt" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // IBC channel events @@ -40,5 +40,5 @@ var ( EventTypeChannelCloseInit = MsgChannelCloseInit{}.Type() EventTypeChannelCloseConfirm = MsgChannelCloseConfirm{}.Type() - AttributeValueCategory = fmt.Sprintf("%s_%s", ibctypes.ModuleName, SubModuleName) + AttributeValueCategory = fmt.Sprintf("%s_%s", host.ModuleName, SubModuleName) ) diff --git a/x/ibc/04-channel/types/genesis_test.go b/x/ibc/04-channel/types/genesis_test.go index c96025f74f..b5a0f7158b 100644 --- a/x/ibc/04-channel/types/genesis_test.go +++ b/x/ibc/04-channel/types/genesis_test.go @@ -4,8 +4,6 @@ import ( "testing" "github.com/stretchr/testify/require" - - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) const ( @@ -16,7 +14,7 @@ const ( testChannel1 = "firstchannel" testChannel2 = "secondchannel" - testChannelOrder = ibctypes.ORDERED + testChannelOrder = ORDERED testChannelVersion = "1.0" ) @@ -39,12 +37,12 @@ func TestValidateGenesis(t *testing.T) { []IdentifiedChannel{ NewIdentifiedChannel( testPort1, testChannel1, NewChannel( - ibctypes.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, + INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, ), ), NewIdentifiedChannel( testPort2, testChannel2, NewChannel( - ibctypes.INIT, testChannelOrder, counterparty1, []string{testConnectionIDA}, testChannelVersion, + INIT, testChannelOrder, counterparty1, []string{testConnectionIDA}, testChannelVersion, ), ), }, @@ -69,7 +67,7 @@ func TestValidateGenesis(t *testing.T) { Channels: []IdentifiedChannel{ NewIdentifiedChannel( testPort1, "testChannel1", NewChannel( - ibctypes.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, + INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion, ), ), }, diff --git a/x/ibc/04-channel/types/msgs.go b/x/ibc/04-channel/types/msgs.go index cb2e139bd3..93b5dd83a2 100644 --- a/x/ibc/04-channel/types/msgs.go +++ b/x/ibc/04-channel/types/msgs.go @@ -8,18 +8,17 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) var _ sdk.Msg = MsgChannelOpenInit{} // NewMsgChannelOpenInit creates a new MsgChannelCloseInit MsgChannelOpenInit func NewMsgChannelOpenInit( - portID, channelID string, version string, channelOrder ibctypes.Order, connectionHops []string, + portID, channelID string, version string, channelOrder Order, connectionHops []string, counterpartyPortID, counterpartyChannelID string, signer sdk.AccAddress, ) MsgChannelOpenInit { counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID) - channel := NewChannel(ibctypes.INIT, channelOrder, counterparty, connectionHops, version) + channel := NewChannel(INIT, channelOrder, counterparty, connectionHops, version) return MsgChannelOpenInit{ PortID: portID, ChannelID: channelID, @@ -30,7 +29,7 @@ func NewMsgChannelOpenInit( // Route implements sdk.Msg func (msg MsgChannelOpenInit) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -64,12 +63,12 @@ var _ sdk.Msg = MsgChannelOpenTry{} // NewMsgChannelOpenTry creates a new MsgChannelOpenTry instance func NewMsgChannelOpenTry( - portID, channelID, version string, channelOrder ibctypes.Order, connectionHops []string, + portID, channelID, version string, channelOrder Order, connectionHops []string, counterpartyPortID, counterpartyChannelID, counterpartyVersion string, proofInit commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress, ) MsgChannelOpenTry { counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID) - channel := NewChannel(ibctypes.INIT, channelOrder, counterparty, connectionHops, version) + channel := NewChannel(INIT, channelOrder, counterparty, connectionHops, version) return MsgChannelOpenTry{ PortID: portID, ChannelID: channelID, @@ -83,7 +82,7 @@ func NewMsgChannelOpenTry( // Route implements sdk.Msg func (msg MsgChannelOpenTry) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -109,7 +108,7 @@ func (msg MsgChannelOpenTry) ValidateBasic() error { return sdkerrors.Wrap(err, "proof init cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } // Signer can be empty return msg.Channel.ValidateBasic() @@ -144,7 +143,7 @@ func NewMsgChannelOpenAck( // Route implements sdk.Msg func (msg MsgChannelOpenAck) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -170,7 +169,7 @@ func (msg MsgChannelOpenAck) ValidateBasic() error { return sdkerrors.Wrap(err, "proof try cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } // Signer can be empty return nil @@ -204,7 +203,7 @@ func NewMsgChannelOpenConfirm( // Route implements sdk.Msg func (msg MsgChannelOpenConfirm) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -227,7 +226,7 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error { return sdkerrors.Wrap(err, "proof ack cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } // Signer can be empty return nil @@ -258,7 +257,7 @@ func NewMsgChannelCloseInit( // Route implements sdk.Msg func (msg MsgChannelCloseInit) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -306,7 +305,7 @@ func NewMsgChannelCloseConfirm( // Route implements sdk.Msg func (msg MsgChannelCloseConfirm) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -329,7 +328,7 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error { return sdkerrors.Wrap(err, "proof init cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } // Signer can be empty return nil @@ -362,7 +361,7 @@ func NewMsgPacket( // Route implements sdk.Msg func (msg MsgPacket) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // ValidateBasic implements sdk.Msg @@ -374,7 +373,7 @@ func (msg MsgPacket) ValidateBasic() error { return sdkerrors.Wrap(err, "proof ack cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } if msg.Signer.Empty() { return sdkerrors.ErrInvalidAddress @@ -423,7 +422,7 @@ func NewMsgTimeout( // Route implements sdk.Msg func (msg MsgTimeout) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // ValidateBasic implements sdk.Msg @@ -435,7 +434,7 @@ func (msg MsgTimeout) ValidateBasic() error { return sdkerrors.Wrap(err, "proof ack cannot be nil") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } if msg.Signer.Empty() { return sdkerrors.ErrInvalidAddress @@ -475,7 +474,7 @@ func NewMsgAcknowledgement( // Route implements sdk.Msg func (msg MsgAcknowledgement) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // ValidateBasic implements sdk.Msg @@ -490,7 +489,7 @@ func (msg MsgAcknowledgement) ValidateBasic() error { return sdkerrors.Wrap(ErrAcknowledgementTooLong, "acknowledgement cannot exceed 100 bytes") } if msg.ProofHeight == 0 { - return sdkerrors.Wrap(ibctypes.ErrInvalidHeight, "proof height must be > 0") + return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be > 0") } if msg.Signer.Empty() { return sdkerrors.ErrInvalidAddress diff --git a/x/ibc/04-channel/types/msgs_test.go b/x/ibc/04-channel/types/msgs_test.go index fd6dcce9c2..ab4673aa43 100644 --- a/x/ibc/04-channel/types/msgs_test.go +++ b/x/ibc/04-channel/types/msgs_test.go @@ -17,7 +17,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // define constants used for testing @@ -81,21 +80,21 @@ func TestMsgTestSuite(t *testing.T) { // TestMsgChannelOpenInit tests ValidateBasic for MsgChannelOpenInit func (suite *MsgTestSuite) TestMsgChannelOpenInit() { testMsgs := []MsgChannelOpenInit{ - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // valid msg - NewMsgChannelOpenInit(invalidShortPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short port id - NewMsgChannelOpenInit(invalidLongPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long port id - NewMsgChannelOpenInit(invalidPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // port id contains non-alpha - NewMsgChannelOpenInit("testportid", invalidShortChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short channel id - NewMsgChannelOpenInit("testportid", invalidLongChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long channel id - NewMsgChannelOpenInit("testportid", invalidChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // channel id contains non-alpha - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.Order(3), connHops, "testcpport", "testcpchannel", addr), // invalid channel order - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.ORDERED, invalidConnHops, "testcpport", "testcpchannel", addr), // connection hops more than 1 - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", addr), // too short connection id - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", addr), // too long connection id - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", addr), // connection id contains non-alpha - NewMsgChannelOpenInit("testportid", "testchannel", "", ibctypes.UNORDERED, connHops, "testcpport", "testcpchannel", addr), // empty channel version - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, connHops, invalidPort, "testcpchannel", addr), // invalid counterparty port id - NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, connHops, "testcpport", invalidChannel, addr), // invalid counterparty channel id + NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // valid msg + NewMsgChannelOpenInit(invalidShortPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short port id + NewMsgChannelOpenInit(invalidLongPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long port id + NewMsgChannelOpenInit(invalidPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // port id contains non-alpha + NewMsgChannelOpenInit("testportid", invalidShortChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short channel id + NewMsgChannelOpenInit("testportid", invalidLongChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long channel id + NewMsgChannelOpenInit("testportid", invalidChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", addr), // channel id contains non-alpha + NewMsgChannelOpenInit("testportid", "testchannel", "1.0", Order(3), connHops, "testcpport", "testcpchannel", addr), // invalid channel order + NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ORDERED, invalidConnHops, "testcpport", "testcpchannel", addr), // connection hops more than 1 + NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", addr), // too short connection id + NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", addr), // too long connection id + NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", addr), // connection id contains non-alpha + NewMsgChannelOpenInit("testportid", "testchannel", "", UNORDERED, connHops, "testcpport", "testcpchannel", addr), // empty channel version + NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, connHops, invalidPort, "testcpchannel", addr), // invalid counterparty port id + NewMsgChannelOpenInit("testportid", "testchannel", "1.0", UNORDERED, connHops, "testcpport", invalidChannel, addr), // invalid counterparty channel id } testCases := []struct { @@ -133,23 +132,23 @@ func (suite *MsgTestSuite) TestMsgChannelOpenInit() { // TestMsgChannelOpenTry tests ValidateBasic for MsgChannelOpenTry func (suite *MsgTestSuite) TestMsgChannelOpenTry() { testMsgs := []MsgChannelOpenTry{ - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // valid msg - NewMsgChannelOpenTry(invalidShortPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short port id - NewMsgChannelOpenTry(invalidLongPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long port id - NewMsgChannelOpenTry(invalidPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha - NewMsgChannelOpenTry("testportid", invalidShortChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short channel id - NewMsgChannelOpenTry("testportid", invalidLongChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long channel id - NewMsgChannelOpenTry("testportid", invalidChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // channel id contains non-alpha - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "", suite.proof, 1, addr), // empty counterparty version - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 0, addr), // suite.proof height is zero - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.Order(4), connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // invalid channel order - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection hops more than 1 - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short connection id - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long connection id - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection id contains non-alpha - NewMsgChannelOpenTry("testportid", "testchannel", "", ibctypes.UNORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // empty channel version - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, connHops, invalidPort, "testcpchannel", "1.0", suite.proof, 1, addr), // invalid counterparty port id - NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, connHops, "testcpport", invalidChannel, "1.0", suite.proof, 1, addr), // invalid counterparty channel id + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // valid msg + NewMsgChannelOpenTry(invalidShortPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short port id + NewMsgChannelOpenTry(invalidLongPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long port id + NewMsgChannelOpenTry(invalidPort, "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha + NewMsgChannelOpenTry("testportid", invalidShortChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short channel id + NewMsgChannelOpenTry("testportid", invalidLongChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long channel id + NewMsgChannelOpenTry("testportid", invalidChannel, "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // channel id contains non-alpha + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "", suite.proof, 1, addr), // empty counterparty version + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 0, addr), // suite.proof height is zero + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", Order(4), connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // invalid channel order + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, invalidConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection hops more than 1 + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short connection id + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long connection id + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection id contains non-alpha + NewMsgChannelOpenTry("testportid", "testchannel", "", UNORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // empty channel version + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, connHops, invalidPort, "testcpchannel", "1.0", suite.proof, 1, addr), // invalid counterparty port id + NewMsgChannelOpenTry("testportid", "testchannel", "1.0", UNORDERED, connHops, "testcpport", invalidChannel, "1.0", suite.proof, 1, addr), // invalid counterparty channel id } testCases := []struct { diff --git a/x/ibc/04-channel/types/querier.go b/x/ibc/04-channel/types/querier.go index 7f5313f278..77afc0c608 100644 --- a/x/ibc/04-channel/types/querier.go +++ b/x/ibc/04-channel/types/querier.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // query routes supported by the IBC channel Querier @@ -33,7 +33,7 @@ func NewChannelResponse( Channel: NewIdentifiedChannel(portID, channelID, channel), Proof: commitmenttypes.MerkleProof{Proof: proof}, - ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.ChannelPath(portID, channelID), "/")), + ProofPath: commitmenttypes.NewMerklePath(strings.Split(host.ChannelPath(portID, channelID), "/")), ProofHeight: uint64(height), } } @@ -86,7 +86,7 @@ func NewPacketResponse( return PacketResponse{ Packet: packet, Proof: commitmenttypes.MerkleProof{Proof: proof}, - ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.PacketCommitmentPath(portID, channelID, sequence), "/")), + ProofPath: commitmenttypes.NewMerklePath(strings.Split(host.PacketCommitmentPath(portID, channelID, sequence), "/")), ProofHeight: uint64(height), } } @@ -108,7 +108,7 @@ func NewRecvResponse( return RecvResponse{ NextSequenceRecv: sequenceRecv, Proof: commitmenttypes.MerkleProof{Proof: proof}, - ProofPath: commitmenttypes.NewMerklePath(strings.Split(ibctypes.NextSequenceRecvPath(portID, channelID), "/")), + ProofPath: commitmenttypes.NewMerklePath(strings.Split(host.NextSequenceRecvPath(portID, channelID), "/")), ProofHeight: uint64(height), } } diff --git a/x/ibc/04-channel/types/types.pb.go b/x/ibc/04-channel/types/types.pb.go index 9e00240207..249db6e582 100644 --- a/x/ibc/04-channel/types/types.pb.go +++ b/x/ibc/04-channel/types/types.pb.go @@ -7,7 +7,6 @@ import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - types1 "github.com/cosmos/cosmos-sdk/x/ibc/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -26,6 +25,80 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// State defines if a channel is in one of the following states: +// CLOSED, INIT, TRYOPEN, OPEN or UNINITIALIZED. +type State int32 + +const ( + // Default State + UNINITIALIZED State = 0 + // A channel has just started the opening handshake. + INIT State = 1 + // A channel has acknowledged the handshake step on the counterparty chain. + TRYOPEN State = 2 + // A channel has completed the handshake. Open channels are + // ready to send and receive packets. + OPEN State = 3 + // A channel has been closed and can no longer be used to send or receive packets. + CLOSED State = 4 +) + +var State_name = map[int32]string{ + 0: "STATE_UNINITIALIZED_UNSPECIFIED", + 1: "STATE_INIT", + 2: "STATE_TRYOPEN", + 3: "STATE_OPEN", + 4: "STATE_CLOSED", +} + +var State_value = map[string]int32{ + "STATE_UNINITIALIZED_UNSPECIFIED": 0, + "STATE_INIT": 1, + "STATE_TRYOPEN": 2, + "STATE_OPEN": 3, + "STATE_CLOSED": 4, +} + +func (x State) String() string { + return proto.EnumName(State_name, int32(x)) +} + +func (State) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_a69005b45bd92d03, []int{0} +} + +// Order defines if a channel is ORDERED or UNORDERED +type Order int32 + +const ( + // zero-value for channel ordering + NONE Order = 0 + // packets can be delivered in any order, which may differ from the order in which they were sent. + UNORDERED Order = 1 + // packets are delivered exactly in the order which they were sent + ORDERED Order = 2 +) + +var Order_name = map[int32]string{ + 0: "ORDER_NONE_UNSPECIFIED", + 1: "ORDER_UNORDERED", + 2: "ORDER_ORDERED", +} + +var Order_value = map[string]int32{ + "ORDER_NONE_UNSPECIFIED": 0, + "ORDER_UNORDERED": 1, + "ORDER_ORDERED": 2, +} + +func (x Order) String() string { + return proto.EnumName(Order_name, int32(x)) +} + +func (Order) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_a69005b45bd92d03, []int{1} +} + // MsgChannelOpenInit defines an sdk.Msg to initialize a channel handshake. It is // called by a relayer on Chain A. type MsgChannelOpenInit struct { @@ -722,9 +795,9 @@ func (m *MsgAcknowledgement) GetSigner() github_com_cosmos_cosmos_sdk_types.AccA // packets and one end capable of receiving packets. type Channel struct { // current state of the channel end - State types1.State `protobuf:"varint,1,opt,name=state,proto3,enum=cosmos_sdk.x.ibc.v1.State" json:"state,omitempty"` + State State `protobuf:"varint,1,opt,name=state,proto3,enum=cosmos_sdk.x.ibc.channel.v1.State" json:"state,omitempty"` // whether the channel is ordered or unordered - Ordering types1.Order `protobuf:"varint,2,opt,name=ordering,proto3,enum=cosmos_sdk.x.ibc.v1.Order" json:"ordering,omitempty"` + Ordering Order `protobuf:"varint,2,opt,name=ordering,proto3,enum=cosmos_sdk.x.ibc.channel.v1.Order" json:"ordering,omitempty"` // counterparty channel end Counterparty Counterparty `protobuf:"bytes,3,opt,name=counterparty,proto3" json:"counterparty"` // list of connection identifiers, in order, along which packets sent on this @@ -864,6 +937,8 @@ func (m *Packet) XXX_DiscardUnknown() { var xxx_messageInfo_Packet proto.InternalMessageInfo func init() { + proto.RegisterEnum("cosmos_sdk.x.ibc.channel.v1.State", State_name, State_value) + proto.RegisterEnum("cosmos_sdk.x.ibc.channel.v1.Order", Order_name, Order_value) proto.RegisterType((*MsgChannelOpenInit)(nil), "cosmos_sdk.x.ibc.channel.v1.MsgChannelOpenInit") proto.RegisterType((*MsgChannelOpenTry)(nil), "cosmos_sdk.x.ibc.channel.v1.MsgChannelOpenTry") proto.RegisterType((*MsgChannelOpenAck)(nil), "cosmos_sdk.x.ibc.channel.v1.MsgChannelOpenAck") @@ -883,76 +958,87 @@ func init() { } var fileDescriptor_a69005b45bd92d03 = []byte{ - // 1097 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x58, 0xcd, 0x6f, 0x23, 0x35, - 0x14, 0x6f, 0x3e, 0x9a, 0x34, 0x6e, 0xb7, 0x1f, 0x2e, 0xdb, 0xa6, 0xe9, 0x92, 0xa9, 0x86, 0x0f, - 0x05, 0xa1, 0x26, 0xdb, 0x96, 0x0f, 0xa9, 0x27, 0x32, 0x5d, 0xc1, 0x56, 0xa8, 0x6a, 0xe5, 0x56, - 0x1c, 0xb8, 0x8c, 0xa6, 0x1e, 0xef, 0x64, 0x94, 0x66, 0x3c, 0x8c, 0xdd, 0xd2, 0xdc, 0x38, 0x72, - 0x42, 0x5c, 0xb8, 0x02, 0xff, 0x00, 0xff, 0xc7, 0x1e, 0x38, 0x2c, 0x37, 0xc4, 0x61, 0x40, 0xed, - 0x95, 0xd3, 0x1c, 0x11, 0x07, 0x34, 0xb6, 0x27, 0x99, 0x24, 0xdd, 0x4a, 0xdb, 0x54, 0x44, 0x70, - 0x49, 0xec, 0xe7, 0xdf, 0x7b, 0x7e, 0xef, 0xf7, 0xde, 0xb3, 0x9d, 0x00, 0xfd, 0xb2, 0xe1, 0x9e, - 0xe2, 0xc6, 0xe3, 0xf7, 0x36, 0x71, 0xcb, 0xf2, 0x3c, 0x72, 0xd6, 0xe0, 0x5d, 0x9f, 0x30, 0xf9, - 0x59, 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x7f, 0x93, 0x01, 0x73, 0x69, 0x4f, - 0x26, 0x77, 0x19, 0x29, 0x87, 0x7e, 0xcf, 0x81, 0x82, 0x3a, 0xa1, 0x2b, 0x60, 0x26, 0x69, 0x47, - 0xe1, 0x4b, 0x1e, 0xf5, 0xe6, 0xf0, 0x43, 0x30, 0xcb, 0xe8, 0x79, 0x80, 0x89, 0x19, 0x3b, 0xa0, - 0x36, 0x5c, 0x89, 0x42, 0x0d, 0xca, 0x3d, 0x52, 0x8b, 0x3a, 0x02, 0x72, 0x16, 0x07, 0x01, 0x3f, - 0x02, 0xf3, 0x6a, 0x2d, 0xfd, 0x0b, 0xaa, 0x64, 0xac, 0x45, 0xa1, 0xf6, 0x70, 0x40, 0x57, 0xad, - 0xeb, 0xe8, 0x81, 0x14, 0x24, 0x65, 0xf5, 0x31, 0x58, 0xb4, 0x09, 0xe3, 0xae, 0x67, 0x09, 0xde, - 0xc5, 0xfe, 0xf2, 0x27, 0xd3, 0x7a, 0x14, 0x6a, 0xab, 0xd2, 0xc6, 0x30, 0x42, 0x47, 0x0b, 0x29, - 0x91, 0xf0, 0xe4, 0x10, 0x2c, 0xa7, 0x51, 0x89, 0x3b, 0x22, 0x4d, 0x46, 0x35, 0x0a, 0xb5, 0xca, - 0xa8, 0xa9, 0x9e, 0x4f, 0x30, 0x25, 0x4d, 0x1c, 0x83, 0x20, 0x6f, 0x5b, 0xdc, 0x92, 0xef, 0x60, - 0x24, 0xc6, 0x71, 0xb8, 0x5c, 0x1e, 0xe7, 0x49, 0x63, 0x16, 0x45, 0x63, 0xa6, 0xc2, 0x1d, 0x5c, - 0xd7, 0xd1, 0x03, 0x25, 0xe8, 0x35, 0xe7, 0x52, 0x82, 0x88, 0xbf, 0x19, 0xb7, 0x3a, 0x7e, 0x79, - 0x46, 0x18, 0x79, 0x14, 0x85, 0x5a, 0x79, 0xd0, 0x48, 0x0f, 0xa2, 0xa3, 0x45, 0x25, 0x3b, 0x49, - 0x44, 0x32, 0xc3, 0xc6, 0xc1, 0xf3, 0xab, 0x6a, 0xe6, 0xc5, 0x55, 0x35, 0xf3, 0xc7, 0x55, 0x35, - 0xf3, 0xed, 0x75, 0x75, 0xea, 0xc5, 0x75, 0x75, 0xea, 0xd7, 0xeb, 0xea, 0xd4, 0xe7, 0x3b, 0xb7, - 0xf6, 0xfc, 0xcd, 0x7f, 0xa7, 0x9c, 0x16, 0xc4, 0x9f, 0x18, 0x3b, 0xff, 0x04, 0x00, 0x00, 0xff, - 0xff, 0x90, 0xdf, 0x6a, 0x15, 0x6f, 0x11, 0x00, 0x00, + // 1265 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x58, 0xcd, 0x6f, 0x1b, 0x45, + 0x1b, 0xf7, 0xfa, 0x33, 0x7e, 0xf2, 0xe5, 0x4c, 0xde, 0xa6, 0xae, 0xdb, 0xd7, 0x6b, 0x2d, 0x05, + 0x85, 0xa2, 0x38, 0x34, 0xe5, 0x4b, 0x3d, 0x20, 0xec, 0xd8, 0xa5, 0x16, 0x8d, 0x1d, 0x4d, 0x5c, + 0x24, 0x7a, 0x59, 0x39, 0xbb, 0x53, 0x67, 0xe5, 0x78, 0xc7, 0xec, 0x4e, 0xd2, 0xe6, 0xc6, 0xb1, + 0xca, 0x01, 0x71, 0xe1, 0x18, 0x40, 0xe2, 0x8f, 0xe0, 0xc4, 0xbd, 0x07, 0x0e, 0xe5, 0x86, 0x38, + 0x2c, 0x28, 0xbd, 0x72, 0xf2, 0x11, 0x71, 0x40, 0x3b, 0x33, 0x6b, 0xaf, 0x9d, 0x12, 0xd4, 0xba, + 0xc2, 0x82, 0x8b, 0x77, 0x9e, 0xcf, 0xf9, 0xcd, 0xef, 0x79, 0x66, 0x76, 0xbc, 0xa0, 0x3d, 0x5c, + 0xb7, 0x76, 0x8d, 0xf5, 0x37, 0xdf, 0x5a, 0x33, 0xf6, 0x5a, 0xb6, 0x4d, 0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0x34, 0xaf, + 0x3c, 0x39, 0xcd, 0x2b, 0xbf, 0x9e, 0xe6, 0x95, 0x2f, 0x9e, 0xe6, 0x23, 0x4f, 0x9e, 0xe6, 0x23, + 0x3f, 0x3d, 0xcd, 0x47, 0xee, 0xdd, 0x38, 0xf7, 0xd8, 0x7c, 0xf6, 0x87, 0xa7, 0xdd, 0x24, 0xff, + 0x0e, 0x74, 0xe3, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfb, 0xa1, 0x58, 0xd4, 0x99, 0x12, 0x00, + 0x00, } func (m *MsgChannelOpenInit) Marshal() (dAtA []byte, err error) { @@ -3839,7 +3925,7 @@ func (m *Channel) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.State |= types1.State(b&0x7F) << shift + m.State |= State(b&0x7F) << shift if b < 0x80 { break } @@ -3858,7 +3944,7 @@ func (m *Channel) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Ordering |= types1.Order(b&0x7F) << shift + m.Ordering |= Order(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/ibc/04-channel/types/types.proto b/x/ibc/04-channel/types/types.proto index 0d447a3736..a059a6268b 100644 --- a/x/ibc/04-channel/types/types.proto +++ b/x/ibc/04-channel/types/types.proto @@ -5,7 +5,6 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"; import "third_party/proto/gogoproto/gogo.proto"; import "x/ibc/23-commitment/types/types.proto"; -import "x/ibc/types/types.proto"; // MsgChannelOpenInit defines an sdk.Msg to initialize a channel handshake. It is // called by a relayer on Chain A. @@ -104,9 +103,9 @@ message Channel { option (gogoproto.goproto_getters) = false; // current state of the channel end - cosmos_sdk.x.ibc.v1.State state = 1; + State state = 1; // whether the channel is ordered or unordered - cosmos_sdk.x.ibc.v1.Order ordering = 2; + Order ordering = 2; // counterparty channel end Counterparty counterparty = 3 [(gogoproto.nullable) = false]; // list of connection identifiers, in order, along which packets sent on this @@ -116,6 +115,36 @@ message Channel { string version = 5; } +// State defines if a channel is in one of the following states: +// CLOSED, INIT, TRYOPEN, OPEN or UNINITIALIZED. +enum State { + option (gogoproto.goproto_enum_prefix) = false; + + // Default State + STATE_UNINITIALIZED_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNINITIALIZED"]; + // A channel has just started the opening handshake. + STATE_INIT = 1 [(gogoproto.enumvalue_customname) = "INIT"]; + // A channel has acknowledged the handshake step on the counterparty chain. + STATE_TRYOPEN = 2 [(gogoproto.enumvalue_customname) = "TRYOPEN"]; + // A channel has completed the handshake. Open channels are + // ready to send and receive packets. + STATE_OPEN = 3 [(gogoproto.enumvalue_customname) = "OPEN"]; + // A channel has been closed and can no longer be used to send or receive packets. + STATE_CLOSED = 4 [(gogoproto.enumvalue_customname) = "CLOSED"]; +} + +// Order defines if a channel is ORDERED or UNORDERED +enum Order { + option (gogoproto.goproto_enum_prefix) = false; + + // zero-value for channel ordering + ORDER_NONE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "NONE"]; + // packets can be delivered in any order, which may differ from the order in which they were sent. + ORDER_UNORDERED = 1 [(gogoproto.enumvalue_customname) = "UNORDERED"]; + // packets are delivered exactly in the order which they were sent + ORDER_ORDERED = 2 [(gogoproto.enumvalue_customname) = "ORDERED"]; +} + // Counterparty defines a channel end counterparty message Counterparty { option (gogoproto.goproto_getters) = false; diff --git a/x/ibc/05-port/keeper/keeper.go b/x/ibc/05-port/keeper/keeper.go index e50422d343..aa64e6e1c1 100644 --- a/x/ibc/05-port/keeper/keeper.go +++ b/x/ibc/05-port/keeper/keeper.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // Keeper defines the IBC connection keeper @@ -26,12 +25,12 @@ func NewKeeper(sck capability.ScopedKeeper) Keeper { // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", ibctypes.ModuleName, types.SubModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", host.ModuleName, types.SubModuleName)) } // isBounded checks a given port ID is already bounded. func (k Keeper) isBound(ctx sdk.Context, portID string) bool { - _, ok := k.scopedKeeper.GetCapability(ctx, ibctypes.PortPath(portID)) + _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } @@ -48,7 +47,7 @@ func (k *Keeper) BindPort(ctx sdk.Context, portID string) *capability.Capability panic(fmt.Sprintf("port %s is already bound", portID)) } - key, err := k.scopedKeeper.NewCapability(ctx, ibctypes.PortPath(portID)) + key, err := k.scopedKeeper.NewCapability(ctx, host.PortPath(portID)) if err != nil { panic(err.Error()) } @@ -66,16 +65,15 @@ func (k Keeper) Authenticate(ctx sdk.Context, key *capability.Capability, portID panic(err.Error()) } - return k.scopedKeeper.AuthenticateCapability(ctx, key, ibctypes.PortPath(portID)) + return k.scopedKeeper.AuthenticateCapability(ctx, key, host.PortPath(portID)) } // LookupModuleByPort will return the IBCModule along with the capability associated with a given portID func (k Keeper) LookupModuleByPort(ctx sdk.Context, portID string) (string, *capability.Capability, error) { - modules, cap, err := k.scopedKeeper.LookupModules(ctx, ibctypes.PortPath(portID)) + modules, cap, err := k.scopedKeeper.LookupModules(ctx, host.PortPath(portID)) if err != nil { return "", nil, err } - return ibctypes.GetModuleOwner(modules), cap, nil - + return types.GetModuleOwner(modules), cap, nil } diff --git a/x/ibc/05-port/types/module.go b/x/ibc/05-port/types/module.go index 4499cbd817..5179301344 100644 --- a/x/ibc/05-port/types/module.go +++ b/x/ibc/05-port/types/module.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/capability" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // IBCModule defines an interface that implements all the callbacks @@ -13,7 +12,7 @@ import ( type IBCModule interface { OnChanOpenInit( ctx sdk.Context, - order ibctypes.Order, + order channeltypes.Order, connectionHops []string, portID string, channelID string, @@ -24,7 +23,7 @@ type IBCModule interface { OnChanOpenTry( ctx sdk.Context, - order ibctypes.Order, + order channeltypes.Order, connectionHops []string, portID, channelID string, diff --git a/x/ibc/types/utils.go b/x/ibc/05-port/types/utils.go similarity index 82% rename from x/ibc/types/utils.go rename to x/ibc/05-port/types/utils.go index 7af4bf0de5..0bc1089dfe 100644 --- a/x/ibc/types/utils.go +++ b/x/ibc/05-port/types/utils.go @@ -1,6 +1,6 @@ package types -// For now, we enforce that only IBC and the module bound to port can own the capability +// GetModuleOwner enforces that only IBC and the module bound to port can own the capability // while future implementations may allow multiple modules to bind to a port, currently we // only allow one module to be bound to a port at any given time func GetModuleOwner(modules []string) string { diff --git a/x/ibc/07-tendermint/misbehaviour.go b/x/ibc/07-tendermint/misbehaviour.go index d373e2e5af..c2c3892f3e 100644 --- a/x/ibc/07-tendermint/misbehaviour.go +++ b/x/ibc/07-tendermint/misbehaviour.go @@ -11,7 +11,6 @@ import ( clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // CheckMisbehaviourAndUpdateState determines whether or not two conflicting @@ -67,7 +66,7 @@ func checkMisbehaviour( // check if provided height matches the headers' height if height > uint64(evidence.GetHeight()) { return sdkerrors.Wrapf( - ibctypes.ErrInvalidHeight, + sdkerrors.ErrInvalidHeight, "height > evidence header height (%d > %d)", height, evidence.GetHeight(), ) } diff --git a/x/ibc/07-tendermint/types/client_state.go b/x/ibc/07-tendermint/types/client_state.go index 1a153c41ee..0807208930 100644 --- a/x/ibc/07-tendermint/types/client_state.go +++ b/x/ibc/07-tendermint/types/client_state.go @@ -5,6 +5,9 @@ import ( "fmt" "time" + tmmath "github.com/tendermint/tendermint/libs/math" + lite "github.com/tendermint/tendermint/lite2" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -17,9 +20,6 @@ import ( commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" - tmmath "github.com/tendermint/tendermint/libs/math" - lite "github.com/tendermint/tendermint/lite2" ) var _ clientexported.ClientState = ClientState{} @@ -158,7 +158,7 @@ func (cs ClientState) VerifyClientConsensusState( proof commitmentexported.Proof, consensusState clientexported.ConsensusState, ) error { - clientPrefixedPath := "clients/" + counterpartyClientIdentifier + "/" + ibctypes.ConsensusStatePath(consensusHeight) + clientPrefixedPath := "clients/" + counterpartyClientIdentifier + "/" + host.ConsensusStatePath(consensusHeight) path, err := commitmenttypes.ApplyPrefix(prefix, clientPrefixedPath) if err != nil { return err @@ -192,7 +192,7 @@ func (cs ClientState) VerifyConnectionState( connectionEnd connectionexported.ConnectionI, consensusState clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.ConnectionPath(connectionID)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.ConnectionPath(connectionID)) if err != nil { return err } @@ -231,7 +231,7 @@ func (cs ClientState) VerifyChannelState( channel channelexported.ChannelI, consensusState clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.ChannelPath(portID, channelID)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.ChannelPath(portID, channelID)) if err != nil { return err } @@ -270,7 +270,7 @@ func (cs ClientState) VerifyPacketCommitment( commitmentBytes []byte, consensusState clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketCommitmentPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.PacketCommitmentPath(portID, channelID, sequence)) if err != nil { return err } @@ -299,7 +299,7 @@ func (cs ClientState) VerifyPacketAcknowledgement( acknowledgement []byte, consensusState clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketAcknowledgementPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.PacketAcknowledgementPath(portID, channelID, sequence)) if err != nil { return err } @@ -328,7 +328,7 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence( sequence uint64, consensusState clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketAcknowledgementPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.PacketAcknowledgementPath(portID, channelID, sequence)) if err != nil { return err } @@ -356,7 +356,7 @@ func (cs ClientState) VerifyNextSequenceRecv( nextSequenceRecv uint64, consensusState clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.NextSequenceRecvPath(portID, channelID)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.NextSequenceRecvPath(portID, channelID)) if err != nil { return err } @@ -384,7 +384,7 @@ func validateVerificationArgs( ) error { if cs.GetLatestHeight() < height { return sdkerrors.Wrap( - ibctypes.ErrInvalidHeight, + sdkerrors.ErrInvalidHeight, fmt.Sprintf("client state (%s) height < proof height (%d < %d)", cs.ID, cs.GetLatestHeight(), height), ) } diff --git a/x/ibc/07-tendermint/types/client_state_test.go b/x/ibc/07-tendermint/types/client_state_test.go index a7fd795031..3b4012e2a1 100644 --- a/x/ibc/07-tendermint/types/client_state_test.go +++ b/x/ibc/07-tendermint/types/client_state_test.go @@ -1,14 +1,14 @@ package types_test import ( + tmmath "github.com/tendermint/tendermint/libs/math" + lite "github.com/tendermint/tendermint/lite2" + connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" - tmmath "github.com/tendermint/tendermint/libs/math" - lite "github.com/tendermint/tendermint/lite2" ) const ( @@ -148,7 +148,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() { func (suite *TendermintTestSuite) TestVerifyConnectionState() { counterparty := connection.NewCounterparty("clientB", testConnectionID, commitmenttypes.NewMerklePrefix([]byte("ibc"))) - conn := connection.NewConnectionEnd(ibctypes.OPEN, testConnectionID, "clientA", counterparty, []string{"1.0.0"}) + conn := connection.NewConnectionEnd(connection.OPEN, testConnectionID, "clientA", counterparty, []string{"1.0.0"}) testCases := []struct { name string @@ -231,7 +231,7 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() { func (suite *TendermintTestSuite) TestVerifyChannelState() { counterparty := channel.NewCounterparty(testPortID, testChannelID) - ch := channel.NewChannel(ibctypes.OPEN, ibctypes.ORDERED, counterparty, []string{testConnectionID}, "1.0.0") + ch := channel.NewChannel(channel.OPEN, channel.ORDERED, counterparty, []string{testConnectionID}, "1.0.0") testCases := []struct { name string diff --git a/x/ibc/07-tendermint/types/msgs.go b/x/ibc/07-tendermint/types/msgs.go index 6234c676df..b4f8005fd6 100644 --- a/x/ibc/07-tendermint/types/msgs.go +++ b/x/ibc/07-tendermint/types/msgs.go @@ -13,7 +13,6 @@ import ( clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // Message types for the IBC client @@ -59,7 +58,7 @@ func NewMsgCreateClient( // Route implements sdk.Msg func (msg MsgCreateClient) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -141,7 +140,7 @@ func NewMsgUpdateClient(id string, header Header, signer sdk.AccAddress) MsgUpda // Route implements sdk.Msg func (msg MsgUpdateClient) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg @@ -191,7 +190,7 @@ func NewMsgSubmitClientMisbehaviour(e evidenceexported.Evidence, s sdk.AccAddres } // Route returns the MsgSubmitClientMisbehaviour's route. -func (msg MsgSubmitClientMisbehaviour) Route() string { return ibctypes.RouterKey } +func (msg MsgSubmitClientMisbehaviour) Route() string { return host.RouterKey } // Type returns the MsgSubmitClientMisbehaviour's type. func (msg MsgSubmitClientMisbehaviour) Type() string { return TypeMsgSubmitClientMisbehaviour } diff --git a/x/ibc/09-localhost/types/client_state.go b/x/ibc/09-localhost/types/client_state.go index f8e8366cfd..665761a4a1 100644 --- a/x/ibc/09-localhost/types/client_state.go +++ b/x/ibc/09-localhost/types/client_state.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" @@ -20,7 +19,6 @@ import ( commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) var _ clientexported.ClientState = ClientState{} @@ -102,7 +100,7 @@ func (cs ClientState) VerifyClientConsensusState( return sdkerrors.Wrapf(clienttypes.ErrFailedClientConsensusStateVerification, "not found for path %s", path) } - var prevConsensusState exported.ConsensusState + var prevConsensusState clientexported.ConsensusState if err := cdc.UnmarshalBinaryBare(data, &prevConsensusState); err != nil { return err } @@ -129,7 +127,7 @@ func (cs ClientState) VerifyConnectionState( connectionEnd connectionexported.ConnectionI, _ clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.ConnectionPath(connectionID)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.ConnectionPath(connectionID)) if err != nil { return err } @@ -168,7 +166,7 @@ func (cs ClientState) VerifyChannelState( channel channelexported.ChannelI, _ clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.ChannelPath(portID, channelID)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.ChannelPath(portID, channelID)) if err != nil { return err } @@ -207,7 +205,7 @@ func (cs ClientState) VerifyPacketCommitment( commitmentBytes []byte, _ clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketCommitmentPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.PacketCommitmentPath(portID, channelID, sequence)) if err != nil { return err } @@ -240,7 +238,7 @@ func (cs ClientState) VerifyPacketAcknowledgement( acknowledgement []byte, _ clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketAcknowledgementPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.PacketAcknowledgementPath(portID, channelID, sequence)) if err != nil { return err } @@ -273,7 +271,7 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence( sequence uint64, _ clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.PacketAcknowledgementPath(portID, channelID, sequence)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.PacketAcknowledgementPath(portID, channelID, sequence)) if err != nil { return err } @@ -298,7 +296,7 @@ func (cs ClientState) VerifyNextSequenceRecv( nextSequenceRecv uint64, _ clientexported.ConsensusState, ) error { - path, err := commitmenttypes.ApplyPrefix(prefix, ibctypes.NextSequenceRecvPath(portID, channelID)) + path, err := commitmenttypes.ApplyPrefix(prefix, host.NextSequenceRecvPath(portID, channelID)) if err != nil { return err } diff --git a/x/ibc/09-localhost/types/client_state_test.go b/x/ibc/09-localhost/types/client_state_test.go index 7d55ef14ec..367d74c187 100644 --- a/x/ibc/09-localhost/types/client_state_test.go +++ b/x/ibc/09-localhost/types/client_state_test.go @@ -5,7 +5,6 @@ import ( channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) const ( @@ -88,7 +87,7 @@ func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() { func (suite *LocalhostTestSuite) TestVerifyConnectionState() { counterparty := connection.NewCounterparty("clientB", testConnectionID, commitmenttypes.NewMerklePrefix([]byte("ibc"))) - conn := connection.NewConnectionEnd(ibctypes.OPEN, testConnectionID, "clientA", counterparty, []string{"1.0.0"}) + conn := connection.NewConnectionEnd(connection.OPEN, testConnectionID, "clientA", counterparty, []string{"1.0.0"}) testCases := []struct { name string @@ -132,7 +131,7 @@ func (suite *LocalhostTestSuite) TestVerifyConnectionState() { func (suite *LocalhostTestSuite) TestVerifyChannelState() { counterparty := channel.NewCounterparty(testPortID, testChannelID) - ch := channel.NewChannel(ibctypes.OPEN, ibctypes.ORDERED, counterparty, []string{testConnectionID}, "1.0.0") + ch := channel.NewChannel(channel.OPEN, channel.ORDERED, counterparty, []string{testConnectionID}, "1.0.0") testCases := []struct { name string diff --git a/x/ibc/09-localhost/types/msgs.go b/x/ibc/09-localhost/types/msgs.go index 508751a93e..8b526f446a 100644 --- a/x/ibc/09-localhost/types/msgs.go +++ b/x/ibc/09-localhost/types/msgs.go @@ -4,7 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // Message types for the IBC client @@ -30,7 +30,7 @@ func NewMsgCreateClient(signer sdk.AccAddress) MsgCreateClient { // Route implements sdk.Msg func (msg MsgCreateClient) Route() string { - return ibctypes.RouterKey + return host.RouterKey } // Type implements sdk.Msg diff --git a/x/ibc/20-transfer/client/utils/utils.go b/x/ibc/20-transfer/client/utils/utils.go index b2fe98034b..71d5165309 100644 --- a/x/ibc/20-transfer/client/utils/utils.go +++ b/x/ibc/20-transfer/client/utils/utils.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // QueryNextSequenceRecv queries the store to get the next receive sequence and @@ -17,7 +17,7 @@ func QueryNextSequenceRecv( ) (channeltypes.RecvResponse, error) { req := abci.RequestQuery{ Path: "store/ibc/key", - Data: ibctypes.KeyNextSequenceRecv(portID, channelID), + Data: host.KeyNextSequenceRecv(portID, channelID), Prove: prove, } diff --git a/x/ibc/20-transfer/handler_test.go b/x/ibc/20-transfer/handler_test.go index 647cc9b4d9..da5c552dee 100644 --- a/x/ibc/20-transfer/handler_test.go +++ b/x/ibc/20-transfer/handler_test.go @@ -21,7 +21,8 @@ import ( transfer "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" + "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -71,7 +72,7 @@ func (suite *HandlerTestSuite) TestHandleMsgTransfer() { handler := transfer.NewHandler(suite.chainA.App.TransferKeeper) // create channel capability from ibc scoped keeper and claim with transfer scoped keeper - capName := ibctypes.ChannelCapabilityPath(testPort1, testChannel1) + capName := host.ChannelCapabilityPath(testPort1, testChannel1) cap, err := suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), capName) suite.Require().Nil(err, "could not create capability") err = suite.chainA.App.ScopedTransferKeeper.ClaimCapability(suite.chainA.GetContext(), cap, capName) @@ -85,8 +86,8 @@ func (suite *HandlerTestSuite) TestHandleMsgTransfer() { // Setup channel from A to B suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection) + suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectiontypes.OPEN) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channeltypes.OPEN, channeltypes.ORDERED, testConnection) res, err = handler(ctx, msg) suite.Require().Error(err) @@ -276,7 +277,7 @@ func (chain *TestChain) updateClient(client *TestChain) { func (chain *TestChain) createConnection( connID, counterpartyConnID, clientID, counterpartyClientID string, - state ibctypes.State, + state connectiontypes.State, ) connectiontypes.ConnectionEnd { counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())) connection := connectiontypes.ConnectionEnd{ @@ -293,7 +294,7 @@ func (chain *TestChain) createConnection( // nolint: unused func (chain *TestChain) createChannel( portID, channelID, counterpartyPortID, counterpartyChannelID string, - state ibctypes.State, order ibctypes.Order, connectionID string, + state channeltypes.State, order channeltypes.Order, connectionID string, ) channeltypes.Channel { counterparty := channeltypes.NewCounterparty(counterpartyPortID, counterpartyChannelID) channel := channeltypes.NewChannel(state, order, counterparty, diff --git a/x/ibc/20-transfer/keeper/keeper.go b/x/ibc/20-transfer/keeper/keeper.go index ce9cc0add1..2e5badd0c4 100644 --- a/x/ibc/20-transfer/keeper/keeper.go +++ b/x/ibc/20-transfer/keeper/keeper.go @@ -13,7 +13,7 @@ import ( channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) const ( @@ -63,7 +63,7 @@ func NewKeeper( // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", ibctypes.ModuleName, types.ModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", host.ModuleName, types.ModuleName)) } // GetTransferAccount returns the ICS20 - transfers ModuleAccount @@ -75,7 +75,7 @@ func (k Keeper) GetTransferAccount(ctx sdk.Context) authexported.ModuleAccountI // in order to expose it to the ICS20 transfer handler. // Keeper retreives channel capability and passes it into channel keeper for authentication func (k Keeper) PacketExecuted(ctx sdk.Context, packet channelexported.PacketI, acknowledgement []byte) error { - chanCap, ok := k.scopedKeeper.GetCapability(ctx, ibctypes.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel())) + chanCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel())) if !ok { return sdkerrors.Wrap(channel.ErrChannelCapabilityNotFound, "channel capability could not be retrieved for packet") } @@ -85,7 +85,7 @@ func (k Keeper) PacketExecuted(ctx sdk.Context, packet channelexported.PacketI, // ChanCloseInit defines a wrapper function for the channel Keeper's function // in order to expose it to the ICS20 trasfer handler. func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error { - capName := ibctypes.ChannelCapabilityPath(portID, channelID) + capName := host.ChannelCapabilityPath(portID, channelID) chanCap, ok := k.scopedKeeper.GetCapability(ctx, capName) if !ok { return sdkerrors.Wrapf(channel.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName) @@ -95,7 +95,7 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error { // IsBound checks if the transfer module is already bound to the desired port func (k Keeper) IsBound(ctx sdk.Context, portID string) bool { - _, ok := k.scopedKeeper.GetCapability(ctx, ibctypes.PortPath(portID)) + _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID)) return ok } @@ -107,7 +107,7 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error { store.Set([]byte(types.PortKey), []byte(portID)) cap := k.portKeeper.BindPort(ctx, portID) - return k.ClaimCapability(ctx, cap, ibctypes.PortPath(portID)) + return k.ClaimCapability(ctx, cap, host.PortPath(portID)) } // GetPort returns the portID for the transfer module. Used in ExportGenesis diff --git a/x/ibc/20-transfer/keeper/keeper_test.go b/x/ibc/20-transfer/keeper/keeper_test.go index 8b0653d047..c9fef7b9e5 100644 --- a/x/ibc/20-transfer/keeper/keeper_test.go +++ b/x/ibc/20-transfer/keeper/keeper_test.go @@ -19,7 +19,8 @@ import ( ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" + "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -72,7 +73,7 @@ func (suite *KeeperTestSuite) SetupTest() { // nolint: unused func (suite *KeeperTestSuite) queryProof(key []byte) (proof commitmenttypes.MerkleProof, height int64) { res := suite.chainA.App.Query(abci.RequestQuery{ - Path: fmt.Sprintf("store/%s/key", ibctypes.StoreKey), + Path: fmt.Sprintf("store/%s/key", host.StoreKey), Data: key, Prove: true, }) @@ -252,7 +253,7 @@ func (chain *TestChain) updateClient(client *TestChain) { func (chain *TestChain) createConnection( connID, counterpartyConnID, clientID, counterpartyClientID string, - state ibctypes.State, + state connectiontypes.State, ) connectiontypes.ConnectionEnd { counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())) connection := connectiontypes.ConnectionEnd{ @@ -268,7 +269,7 @@ func (chain *TestChain) createConnection( func (chain *TestChain) createChannel( portID, channelID, counterpartyPortID, counterpartyChannelID string, - state ibctypes.State, order ibctypes.Order, connectionID string, + state channeltypes.State, order channeltypes.Order, connectionID string, ) channeltypes.Channel { counterparty := channeltypes.NewCounterparty(counterpartyPortID, counterpartyChannelID) channel := channeltypes.NewChannel(state, order, counterparty, diff --git a/x/ibc/20-transfer/keeper/relay.go b/x/ibc/20-transfer/keeper/relay.go index 6d6fb7b01c..6396731f44 100644 --- a/x/ibc/20-transfer/keeper/relay.go +++ b/x/ibc/20-transfer/keeper/relay.go @@ -7,7 +7,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // SendTransfer handles transfer sending logic. There are 2 possible cases: @@ -57,7 +57,7 @@ func (k Keeper) createOutgoingPacket( sender sdk.AccAddress, receiver string, ) error { - channelCap, ok := k.scopedKeeper.GetCapability(ctx, ibctypes.ChannelCapabilityPath(sourcePort, sourceChannel)) + channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel)) if !ok { return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } diff --git a/x/ibc/20-transfer/keeper/relay_test.go b/x/ibc/20-transfer/keeper/relay_test.go index 490af41486..25700140f4 100644 --- a/x/ibc/20-transfer/keeper/relay_test.go +++ b/x/ibc/20-transfer/keeper/relay_test.go @@ -5,14 +5,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank" + connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) func (suite *KeeperTestSuite) TestSendTransfer() { testCoins2 := sdk.NewCoins(sdk.NewCoin("testportid/secondchannel/atom", sdk.NewInt(100))) - capName := ibctypes.ChannelCapabilityPath(testPort1, testChannel1) + capName := host.ChannelCapabilityPath(testPort1, testChannel1) testCases := []struct { msg string @@ -25,8 +26,8 @@ func (suite *KeeperTestSuite) TestSendTransfer() { func() { suite.chainA.App.BankKeeper.AddCoins(suite.chainA.GetContext(), testAddr1, testCoins) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection) + suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connection.OPEN) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channeltypes.OPEN, channeltypes.ORDERED, testConnection) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1) }, true, true}, {"successful transfer from external chain", prefixCoins, @@ -35,8 +36,8 @@ func (suite *KeeperTestSuite) TestSendTransfer() { _, err := suite.chainA.App.BankKeeper.AddCoins(suite.chainA.GetContext(), testAddr1, prefixCoins) suite.Require().NoError(err) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection) + suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connection.OPEN) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channeltypes.OPEN, channeltypes.ORDERED, testConnection) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1) }, false, true}, {"source channel not found", testCoins, @@ -44,32 +45,32 @@ func (suite *KeeperTestSuite) TestSendTransfer() { {"next seq send not found", testCoins, func() { suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection) + suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connection.OPEN) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channeltypes.OPEN, channeltypes.ORDERED, testConnection) }, true, false}, // createOutgoingPacket tests // - source chain {"send coins failed", testCoins, func() { suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection) + suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connection.OPEN) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channeltypes.OPEN, channeltypes.ORDERED, testConnection) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1) }, true, false}, // - receiving chain {"send from module account failed", testCoins, func() { suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection) + suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connection.OPEN) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channeltypes.OPEN, channeltypes.ORDERED, testConnection) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1) }, false, false}, {"channel capability not found", testCoins, func() { suite.chainA.App.BankKeeper.AddCoins(suite.chainA.GetContext(), testAddr1, testCoins) suite.chainA.CreateClient(suite.chainB) - suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection) + suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connection.OPEN) + suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channeltypes.OPEN, channeltypes.ORDERED, testConnection) suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1) // Release channel capability cap, _ := suite.chainA.App.ScopedTransferKeeper.GetCapability(suite.chainA.GetContext(), capName) diff --git a/x/ibc/20-transfer/module.go b/x/ibc/20-transfer/module.go index dac2528b14..27806bbd09 100644 --- a/x/ibc/20-transfer/module.go +++ b/x/ibc/20-transfer/module.go @@ -23,7 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/client/cli" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/client/rest" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) var ( @@ -143,7 +143,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V // Implement IBCModule callbacks func (am AppModule) OnChanOpenInit( ctx sdk.Context, - order ibctypes.Order, + order channeltypes.Order, connectionHops []string, portID string, channelID string, @@ -164,7 +164,7 @@ func (am AppModule) OnChanOpenInit( } // Claim channel capability passed back by IBC module - if err := am.keeper.ClaimCapability(ctx, chanCap, ibctypes.ChannelCapabilityPath(portID, channelID)); err != nil { + if err := am.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return sdkerrors.Wrap(channel.ErrChannelCapabilityNotFound, err.Error()) } @@ -174,7 +174,7 @@ func (am AppModule) OnChanOpenInit( func (am AppModule) OnChanOpenTry( ctx sdk.Context, - order ibctypes.Order, + order channeltypes.Order, connectionHops []string, portID, channelID string, @@ -200,7 +200,7 @@ func (am AppModule) OnChanOpenTry( } // Claim channel capability passed back by IBC module - if err := am.keeper.ClaimCapability(ctx, chanCap, ibctypes.ChannelCapabilityPath(portID, channelID)); err != nil { + if err := am.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { return sdkerrors.Wrap(channel.ErrChannelCapabilityNotFound, err.Error()) } diff --git a/x/ibc/20-transfer/types/events.go b/x/ibc/20-transfer/types/events.go index 6b1f6295bb..a3f4376600 100644 --- a/x/ibc/20-transfer/types/events.go +++ b/x/ibc/20-transfer/types/events.go @@ -3,7 +3,7 @@ package types import ( "fmt" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // IBC transfer events @@ -22,5 +22,5 @@ const ( // IBC transfer events vars var ( - AttributeValueCategory = fmt.Sprintf("%s_%s", ibctypes.ModuleName, ModuleName) + AttributeValueCategory = fmt.Sprintf("%s_%s", host.ModuleName, ModuleName) ) diff --git a/x/ibc/20-transfer/types/keys.go b/x/ibc/20-transfer/types/keys.go index 1951f01461..1c74d3603b 100644 --- a/x/ibc/20-transfer/types/keys.go +++ b/x/ibc/20-transfer/types/keys.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) const ( @@ -49,5 +49,5 @@ func GetDenomPrefix(portID, channelID string) string { // GetModuleAccountName returns the IBC transfer module account name for supply func GetModuleAccountName() string { - return fmt.Sprintf("%s/%s", ibctypes.ModuleName, ModuleName) + return fmt.Sprintf("%s/%s", host.ModuleName, ModuleName) } diff --git a/x/ibc/types/keys.go b/x/ibc/24-host/keys.go similarity index 99% rename from x/ibc/types/keys.go rename to x/ibc/24-host/keys.go index 51ecb0c017..23cb060edb 100644 --- a/x/ibc/types/keys.go +++ b/x/ibc/24-host/keys.go @@ -1,4 +1,4 @@ -package types +package host import ( "fmt" diff --git a/x/ibc/alias.go b/x/ibc/alias.go index 29e616cc7c..f2de710349 100644 --- a/x/ibc/alias.go +++ b/x/ibc/alias.go @@ -6,23 +6,28 @@ package ibc // ALIASGEN: github.com/cosmos/cosmos-sdk/x/ibc/types import ( + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" "github.com/cosmos/cosmos-sdk/x/ibc/keeper" "github.com/cosmos/cosmos-sdk/x/ibc/types" ) const ( - ModuleName = types.ModuleName - StoreKey = types.StoreKey - QuerierRoute = types.QuerierRoute - RouterKey = types.RouterKey + ModuleName = host.ModuleName + StoreKey = host.StoreKey + QuerierRoute = host.QuerierRoute + RouterKey = host.RouterKey ) var ( // functions aliases - NewKeeper = keeper.NewKeeper - NewQuerier = keeper.NewQuerier + NewKeeper = keeper.NewKeeper + NewQuerier = keeper.NewQuerier + RegisterCodec = types.RegisterCodec + RegisterInterfaces = types.RegisterInterfaces + DefaultGenesisState = types.DefaultGenesisState ) type ( - Keeper = keeper.Keeper + Keeper = keeper.Keeper + GenesisState = types.GenesisState ) diff --git a/x/ibc/ante/ante_test.go b/x/ibc/ante/ante_test.go index 11cf8047ee..727a82a751 100644 --- a/x/ibc/ante/ante_test.go +++ b/x/ibc/ante/ante_test.go @@ -18,11 +18,12 @@ import ( channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" + "github.com/cosmos/cosmos-sdk/x/staking" commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" "github.com/cosmos/cosmos-sdk/x/ibc/ante" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // define constants used for testing @@ -55,13 +56,13 @@ func (suite *HandlerTestSuite) SetupTest() { // create client and connection during setups suite.chainA.CreateClient(suite.chainB) suite.chainB.CreateClient(suite.chainA) - suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN) - suite.chainB.createConnection(testConnection, testConnection, testClientIDA, testClientIDB, ibctypes.OPEN) + suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectiontypes.OPEN) + suite.chainB.createConnection(testConnection, testConnection, testClientIDA, testClientIDB, connectiontypes.OPEN) } func queryProof(chain *TestChain, key string) (proof commitmenttypes.MerkleProof, height int64) { res := chain.App.Query(abci.RequestQuery{ - Path: fmt.Sprintf("store/%s/key", ibctypes.StoreKey), + Path: fmt.Sprintf("store/%s/key", host.StoreKey), Data: []byte(key), Prove: true, }) @@ -96,10 +97,10 @@ func (suite *HandlerTestSuite) TestHandleMsgPacketOrdered() { _, err := handler(cctx, suite.newTx(msg), false) suite.Error(err, "%+v", err) // channel does not exist - suite.chainA.createChannel(cpportid, cpchanid, portid, chanid, ibctypes.OPEN, ibctypes.ORDERED, testConnection) - suite.chainB.createChannel(portid, chanid, cpportid, cpchanid, ibctypes.OPEN, ibctypes.ORDERED, testConnection) + suite.chainA.createChannel(cpportid, cpchanid, portid, chanid, channeltypes.OPEN, channeltypes.ORDERED, testConnection) + suite.chainB.createChannel(portid, chanid, cpportid, cpchanid, channeltypes.OPEN, channeltypes.ORDERED, testConnection) ctx = suite.chainA.GetContext() - packetCommitmentPath := ibctypes.PacketCommitmentPath(packet.SourcePort, packet.SourceChannel, packet.Sequence) + packetCommitmentPath := host.PacketCommitmentPath(packet.SourcePort, packet.SourceChannel, packet.Sequence) proof, proofHeight := queryProof(suite.chainB, packetCommitmentPath) msg = channel.NewMsgPacket(packet, proof, uint64(proofHeight), addr1) _, err = handler(cctx, suite.newTx(msg), false) @@ -120,7 +121,7 @@ func (suite *HandlerTestSuite) TestHandleMsgPacketOrdered() { _, err := handler(cctx, suite.newTx(msg), false) if err == nil { // retrieve channelCapability from scopedIBCKeeper and pass into PacketExecuted - chanCap, ok := suite.chainA.App.ScopedIBCKeeper.GetCapability(cctx, ibctypes.ChannelCapabilityPath( + chanCap, ok := suite.chainA.App.ScopedIBCKeeper.GetCapability(cctx, host.ChannelCapabilityPath( packet.GetDestPort(), packet.GetDestChannel()), ) suite.Require().True(ok, "could not retrieve capability") @@ -151,14 +152,14 @@ func (suite *HandlerTestSuite) TestHandleMsgPacketUnordered() { // suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), packet.SourcePort, packet.SourceChannel, uint64(10)) - suite.chainA.createChannel(cpportid, cpchanid, portid, chanid, ibctypes.OPEN, ibctypes.UNORDERED, testConnection) + suite.chainA.createChannel(cpportid, cpchanid, portid, chanid, channeltypes.OPEN, channeltypes.UNORDERED, testConnection) suite.chainA.updateClient(suite.chainB) for i := 10; i >= 0; i-- { cctx, write := suite.chainA.GetContext().CacheContext() packet = channel.NewPacket(newPacket(uint64(i)).GetData(), uint64(i), portid, chanid, cpportid, cpchanid, 100, 0) - packetCommitmentPath := ibctypes.PacketCommitmentPath(packet.SourcePort, packet.SourceChannel, uint64(i)) + packetCommitmentPath := host.PacketCommitmentPath(packet.SourcePort, packet.SourceChannel, uint64(i)) proof, proofHeight := queryProof(suite.chainB, packetCommitmentPath) msg := channel.NewMsgPacket(packet, proof, uint64(proofHeight), addr1) _, err := handler(cctx, suite.newTx(msg), false) @@ -326,7 +327,7 @@ func (chain *TestChain) updateClient(client *TestChain) { func (chain *TestChain) createConnection( connID, counterpartyConnID, clientID, counterpartyClientID string, - state ibctypes.State, + state connectiontypes.State, ) connectiontypes.ConnectionEnd { counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes())) connection := connectiontypes.ConnectionEnd{ @@ -342,7 +343,7 @@ func (chain *TestChain) createConnection( func (chain *TestChain) createChannel( portID, channelID, counterpartyPortID, counterpartyChannelID string, - state ibctypes.State, order ibctypes.Order, connectionID string, + state channeltypes.State, order channeltypes.Order, connectionID string, ) channeltypes.Channel { counterparty := channeltypes.NewCounterparty(counterpartyPortID, counterpartyChannelID) channel := channeltypes.NewChannel(state, order, counterparty, @@ -350,7 +351,7 @@ func (chain *TestChain) createChannel( ) ctx := chain.GetContext() chain.App.IBCKeeper.ChannelKeeper.SetChannel(ctx, portID, channelID, channel) - chain.App.ScopedIBCKeeper.NewCapability(ctx, ibctypes.ChannelCapabilityPath(portID, channelID)) + chain.App.ScopedIBCKeeper.NewCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) return channel } diff --git a/x/ibc/client/cli/cli.go b/x/ibc/client/cli/cli.go index dc0f52eaac..94b6c216f5 100644 --- a/x/ibc/client/cli/cli.go +++ b/x/ibc/client/cli/cli.go @@ -11,13 +11,13 @@ import ( channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/client/cli" localhost "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost" - "github.com/cosmos/cosmos-sdk/x/ibc/types" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) // GetTxCmd returns the transaction commands for this module func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command { ibcTxCmd := &cobra.Command{ - Use: types.ModuleName, + Use: host.ModuleName, Short: "IBC transaction subcommands", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, @@ -37,7 +37,7 @@ func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command { func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { // Group ibc queries under a subcommand ibcQueryCmd := &cobra.Command{ - Use: types.ModuleName, + Use: host.ModuleName, Short: "Querying commands for the IBC module", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, diff --git a/x/ibc/genesis.go b/x/ibc/genesis.go index 34dc368d04..617fd779c4 100644 --- a/x/ibc/genesis.go +++ b/x/ibc/genesis.go @@ -7,36 +7,6 @@ import ( channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" ) -// GenesisState defines the ibc module's genesis state. -type GenesisState struct { - ClientGenesis client.GenesisState `json:"client_genesis" yaml:"client_genesis"` - ConnectionGenesis connection.GenesisState `json:"connection_genesis" yaml:"connection_genesis"` - ChannelGenesis channel.GenesisState `json:"channel_genesis" yaml:"channel_genesis"` -} - -// DefaultGenesisState returns the ibc module's default genesis state. -func DefaultGenesisState() GenesisState { - return GenesisState{ - ClientGenesis: client.DefaultGenesisState(), - ConnectionGenesis: connection.DefaultGenesisState(), - ChannelGenesis: channel.DefaultGenesisState(), - } -} - -// Validate performs basic genesis state validation returning an error upon any -// failure. -func (gs GenesisState) Validate() error { - if err := gs.ClientGenesis.Validate(); err != nil { - return err - } - - if err := gs.ConnectionGenesis.Validate(); err != nil { - return err - } - - return gs.ChannelGenesis.Validate() -} - // InitGenesis initializes the ibc state from a provided genesis // state. func InitGenesis(ctx sdk.Context, k Keeper, createLocalhost bool, gs GenesisState) { diff --git a/x/ibc/genesis_test.go b/x/ibc/genesis_test.go index 14022c7257..c92750aa24 100644 --- a/x/ibc/genesis_test.go +++ b/x/ibc/genesis_test.go @@ -1,6 +1,8 @@ package ibc_test import ( + lite "github.com/tendermint/tendermint/lite2" + "github.com/cosmos/cosmos-sdk/x/ibc" client "github.com/cosmos/cosmos-sdk/x/ibc/02-client" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" @@ -9,8 +11,7 @@ import ( 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" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" - lite "github.com/tendermint/tendermint/lite2" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" ) func (suite *IBCTestSuite) TestValidateGenesis() { @@ -46,17 +47,17 @@ func (suite *IBCTestSuite) TestValidateGenesis() { ), ConnectionGenesis: connection.NewGenesisState( []connection.End{ - connection.NewConnectionEnd(ibctypes.INIT, connectionID, clientID, connection.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}), + connection.NewConnectionEnd(connection.INIT, connectionID, clientID, connection.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}), }, []connection.Paths{ - connection.NewConnectionPaths(clientID, []string{ibctypes.ConnectionPath(connectionID)}), + connection.NewConnectionPaths(clientID, []string{host.ConnectionPath(connectionID)}), }, ), ChannelGenesis: channel.NewGenesisState( []channel.IdentifiedChannel{ channel.NewIdentifiedChannel( port1, channel1, channel.NewChannel( - ibctypes.INIT, channelOrder, + channel.INIT, channelOrder, channel.NewCounterparty(port2, channel2), []string{connectionID}, channelVersion, ), ), @@ -98,10 +99,10 @@ func (suite *IBCTestSuite) TestValidateGenesis() { ClientGenesis: client.DefaultGenesisState(), ConnectionGenesis: connection.NewGenesisState( []connection.End{ - connection.NewConnectionEnd(ibctypes.INIT, connectionID, "CLIENTIDONE", connection.NewCounterparty(clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}), + connection.NewConnectionEnd(connection.INIT, connectionID, "CLIENTIDONE", connection.NewCounterparty(clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}), }, []connection.Paths{ - connection.NewConnectionPaths(clientID, []string{ibctypes.ConnectionPath(connectionID)}), + connection.NewConnectionPaths(clientID, []string{host.ConnectionPath(connectionID)}), }, ), }, diff --git a/x/ibc/ibc_test.go b/x/ibc/ibc_test.go index 25c9cc5585..55f96c2d80 100644 --- a/x/ibc/ibc_test.go +++ b/x/ibc/ibc_test.go @@ -12,8 +12,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" - ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types" ) const ( @@ -28,7 +28,7 @@ const ( channel1 = "firstchannel" channel2 = "secondchannel" - channelOrder = ibctypes.ORDERED + channelOrder = channeltypes.ORDERED channelVersion = "1.0" trustingPeriod time.Duration = time.Hour * 24 * 7 * 2 diff --git a/x/ibc/module.go b/x/ibc/module.go index 7af27b9bb5..71cb32f42a 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -15,14 +15,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" client "github.com/cosmos/cosmos-sdk/x/ibc/02-client" - connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" - channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" - 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" + host "github.com/cosmos/cosmos-sdk/x/ibc/24-host" "github.com/cosmos/cosmos-sdk/x/ibc/client/cli" "github.com/cosmos/cosmos-sdk/x/ibc/client/rest" - "github.com/cosmos/cosmos-sdk/x/ibc/types" ) // TODO: AppModuleSimulation @@ -38,17 +33,12 @@ var _ module.AppModuleBasic = AppModuleBasic{} // Name returns the ibc module's name. func (AppModuleBasic) Name() string { - return types.ModuleName + return host.ModuleName } // RegisterCodec registers the ibc module's types for the given codec. func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - client.RegisterCodec(cdc) - connection.RegisterCodec(cdc) - channel.RegisterCodec(cdc) - ibctmtypes.RegisterCodec(cdc) - localhosttypes.RegisterCodec(cdc) - commitmenttypes.RegisterCodec(cdc) + RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the ibc @@ -84,8 +74,7 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { // RegisterInterfaceTypes registers module concrete types into protobuf Any. func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) { - connection.RegisterInterfaces(registry) - channel.RegisterInterfaces(registry) + RegisterInterfaces(registry) } // AppModule implements an application module for the ibc module. diff --git a/x/ibc/types/codec.go b/x/ibc/types/codec.go new file mode 100644 index 0000000000..c4949ca68d --- /dev/null +++ b/x/ibc/types/codec.go @@ -0,0 +1,29 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + client "github.com/cosmos/cosmos-sdk/x/ibc/02-client" + connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" + channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" + 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" +) + +// RegisterCodec registers the necessary x/ibc interfaces and concrete types +// on the provided Amino codec. These types are used for Amino JSON serialization. +func RegisterCodec(cdc *codec.Codec) { + client.RegisterCodec(cdc) + connection.RegisterCodec(cdc) + channel.RegisterCodec(cdc) + ibctmtypes.RegisterCodec(cdc) + localhosttypes.RegisterCodec(cdc) + commitmenttypes.RegisterCodec(cdc) +} + +// RegisterInterfaces registers x/ibc interfaces into protobuf Any. +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + connection.RegisterInterfaces(registry) + channel.RegisterInterfaces(registry) +} diff --git a/x/ibc/types/errors.go b/x/ibc/types/errors.go deleted file mode 100644 index 8f83505254..0000000000 --- a/x/ibc/types/errors.go +++ /dev/null @@ -1,11 +0,0 @@ -package types - -import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// ibc module common sentinel errors -var ( - ErrInvalidHeight = sdkerrors.Register(ModuleName, 2, "invalid height") - ErrInvalidVersion = sdkerrors.Register(ModuleName, 3, "invalid version") -) diff --git a/x/ibc/types/genesis.go b/x/ibc/types/genesis.go new file mode 100644 index 0000000000..ca829153e5 --- /dev/null +++ b/x/ibc/types/genesis.go @@ -0,0 +1,37 @@ +package types + +import ( + client "github.com/cosmos/cosmos-sdk/x/ibc/02-client" + connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" + channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" +) + +// GenesisState defines the ibc module's genesis state. +type GenesisState struct { + ClientGenesis client.GenesisState `json:"client_genesis" yaml:"client_genesis"` + ConnectionGenesis connection.GenesisState `json:"connection_genesis" yaml:"connection_genesis"` + ChannelGenesis channel.GenesisState `json:"channel_genesis" yaml:"channel_genesis"` +} + +// DefaultGenesisState returns the ibc module's default genesis state. +func DefaultGenesisState() GenesisState { + return GenesisState{ + ClientGenesis: client.DefaultGenesisState(), + ConnectionGenesis: connection.DefaultGenesisState(), + ChannelGenesis: channel.DefaultGenesisState(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + if err := gs.ClientGenesis.Validate(); err != nil { + return err + } + + if err := gs.ConnectionGenesis.Validate(); err != nil { + return err + } + + return gs.ChannelGenesis.Validate() +} diff --git a/x/ibc/types/mock.go b/x/ibc/types/mock.go deleted file mode 100644 index f8a646e113..0000000000 --- a/x/ibc/types/mock.go +++ /dev/null @@ -1,74 +0,0 @@ -package types - -import ( - "bytes" - "errors" - - commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported" -) - -// Mocked types -// TODO: fix tests and replace for real proofs - -var ( - _ commitmentexported.Proof = ValidProof{nil, nil, nil} - _ commitmentexported.Proof = InvalidProof{} -) - -type ( - ValidProof struct { - root commitmentexported.Root - path commitmentexported.Path - value []byte - } - InvalidProof struct{} -) - -func (ValidProof) GetCommitmentType() commitmentexported.Type { - return commitmentexported.Merkle -} - -func (proof ValidProof) VerifyMembership( - root commitmentexported.Root, path commitmentexported.Path, value []byte, -) error { - if bytes.Equal(root.GetHash(), proof.root.GetHash()) && - path.String() == proof.path.String() && - bytes.Equal(value, proof.value) { - return nil - } - - return errors.New("invalid proof") -} - -func (ValidProof) VerifyNonMembership(root commitmentexported.Root, path commitmentexported.Path) error { - return nil -} - -func (ValidProof) ValidateBasic() error { - return nil -} - -func (ValidProof) IsEmpty() bool { - return false -} - -func (InvalidProof) GetCommitmentType() commitmentexported.Type { - return commitmentexported.Merkle -} - -func (InvalidProof) VerifyMembership( - root commitmentexported.Root, path commitmentexported.Path, value []byte) error { - return errors.New("proof failed") -} - -func (InvalidProof) VerifyNonMembership(root commitmentexported.Root, path commitmentexported.Path) error { - return errors.New("proof failed") -} - -func (InvalidProof) ValidateBasic() error { - return errors.New("invalid proof") -} - -func (InvalidProof) IsEmpty() bool { - return true -} diff --git a/x/ibc/types/types.pb.go b/x/ibc/types/types.pb.go deleted file mode 100644 index ab52afcc61..0000000000 --- a/x/ibc/types/types.pb.go +++ /dev/null @@ -1,129 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: x/ibc/types/types.proto - -package types - -import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// Order defines if a channel is ORDERED or UNORDERED -type Order int32 - -const ( - // zero-value for channel ordering - NONE Order = 0 - // packets can be delivered in any order, which may differ from the order in which they were sent. - UNORDERED Order = 1 - // packets are delivered exactly in the order which they were sent - ORDERED Order = 2 -) - -var Order_name = map[int32]string{ - 0: "ORDER_NONE_UNSPECIFIED", - 1: "ORDER_UNORDERED", - 2: "ORDER_ORDERED", -} - -var Order_value = map[string]int32{ - "ORDER_NONE_UNSPECIFIED": 0, - "ORDER_UNORDERED": 1, - "ORDER_ORDERED": 2, -} - -func (x Order) String() string { - return proto.EnumName(Order_name, int32(x)) -} - -func (Order) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_cc2eab1776b9fb6e, []int{0} -} - -// State defines if a channel or connection is in one of the following states: -// CLOSED, INIT, TRYOPEN, OPEN or UNINITIALIZED. -type State int32 - -const ( - // Default State - UNINITIALIZED State = 0 - // A channel or connection end has just started the opening handshake. - INIT State = 1 - // A channel or connection end has acknowledged the handshake step on the counterparty chain. - TRYOPEN State = 2 - // A channel or connection end has completed the handshake. Open channels are - // ready to send and receive packets. - OPEN State = 3 - // A channel end has been closed and can no longer be used to send or receive packets. - CLOSED State = 4 -) - -var State_name = map[int32]string{ - 0: "STATE_UNINITIALIZED_UNSPECIFIED", - 1: "STATE_INIT", - 2: "STATE_TRYOPEN", - 3: "STATE_OPEN", - 4: "STATE_CLOSED", -} - -var State_value = map[string]int32{ - "STATE_UNINITIALIZED_UNSPECIFIED": 0, - "STATE_INIT": 1, - "STATE_TRYOPEN": 2, - "STATE_OPEN": 3, - "STATE_CLOSED": 4, -} - -func (x State) String() string { - return proto.EnumName(State_name, int32(x)) -} - -func (State) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_cc2eab1776b9fb6e, []int{1} -} - -func init() { - proto.RegisterEnum("cosmos_sdk.x.ibc.v1.Order", Order_name, Order_value) - proto.RegisterEnum("cosmos_sdk.x.ibc.v1.State", State_name, State_value) -} - -func init() { proto.RegisterFile("x/ibc/types/types.proto", fileDescriptor_cc2eab1776b9fb6e) } - -var fileDescriptor_cc2eab1776b9fb6e = []byte{ - // 339 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xaf, 0xd0, 0xcf, 0x4c, - 0x4a, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, - 0xc2, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x99, 0x49, - 0xc9, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, - 0x95, 0xfa, 0x60, 0x75, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xb3, 0x56, 0x39, 0x17, - 0xab, 0x7f, 0x51, 0x4a, 0x6a, 0x91, 0x90, 0x0a, 0x97, 0x98, 0x7f, 0x90, 0x8b, 0x6b, 0x50, 0xbc, - 0x9f, 0xbf, 0x9f, 0x6b, 0x7c, 0xa8, 0x5f, 0x70, 0x80, 0xab, 0xb3, 0xa7, 0x9b, 0xa7, 0xab, 0x8b, - 0x00, 0x83, 0x14, 0x47, 0xd7, 0x5c, 0x05, 0x16, 0x90, 0xb8, 0x90, 0x12, 0x17, 0x3f, 0x44, 0x55, - 0xa8, 0x1f, 0x98, 0x76, 0x75, 0x11, 0x60, 0x94, 0xe2, 0xed, 0x9a, 0xab, 0xc0, 0x09, 0x17, 0x10, - 0x92, 0xe3, 0xe2, 0x85, 0xa8, 0x81, 0xa9, 0x60, 0x92, 0xe2, 0xee, 0x9a, 0xab, 0xc0, 0x0e, 0xe5, - 0x4a, 0xb1, 0x74, 0x2c, 0x96, 0x63, 0xd0, 0xda, 0xce, 0xc8, 0xc5, 0x1a, 0x5c, 0x92, 0x58, 0x92, - 0x2a, 0x64, 0xc6, 0x25, 0x1f, 0x1c, 0xe2, 0x18, 0x02, 0xb2, 0xd4, 0xd3, 0xcf, 0x33, 0xc4, 0xd3, - 0xd1, 0xc7, 0x33, 0xca, 0xd5, 0x05, 0xcd, 0x09, 0x82, 0x5d, 0x73, 0x15, 0x78, 0x51, 0x14, 0x08, - 0x49, 0x70, 0x71, 0x41, 0xf4, 0x81, 0x04, 0x05, 0x18, 0x21, 0xae, 0x04, 0xb1, 0x41, 0x2e, 0x80, - 0xc8, 0x84, 0x04, 0x45, 0xfa, 0x07, 0xb8, 0xfa, 0xc1, 0x5c, 0x00, 0xe5, 0x22, 0x74, 0x82, 0x25, - 0x99, 0x21, 0x3a, 0xc1, 0x32, 0x32, 0x5c, 0x3c, 0x10, 0x19, 0x67, 0x1f, 0xff, 0x60, 0x57, 0x17, - 0x01, 0x16, 0x29, 0xae, 0xae, 0xb9, 0x0a, 0x6c, 0x10, 0x1e, 0xc4, 0xe5, 0x4e, 0x4e, 0x27, 0x1e, - 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, - 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x91, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, - 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x89, 0x14, 0x28, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x8f, 0x14, 0x7f, - 0x49, 0x6c, 0xe0, 0xd0, 0x37, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x1c, 0xe7, 0x8b, 0xd5, - 0x01, 0x00, 0x00, -} diff --git a/x/ibc/types/types.proto b/x/ibc/types/types.proto deleted file mode 100644 index 8d21e43d20..0000000000 --- a/x/ibc/types/types.proto +++ /dev/null @@ -1,36 +0,0 @@ -syntax = "proto3"; -package cosmos_sdk.x.ibc.v1; - -option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/types"; - -import "third_party/proto/gogoproto/gogo.proto"; - -// Order defines if a channel is ORDERED or UNORDERED -enum Order { - option (gogoproto.goproto_enum_prefix) = false; - - // zero-value for channel ordering - ORDER_NONE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "NONE"]; - // packets can be delivered in any order, which may differ from the order in which they were sent. - ORDER_UNORDERED = 1 [(gogoproto.enumvalue_customname) = "UNORDERED"]; - // packets are delivered exactly in the order which they were sent - ORDER_ORDERED = 2 [(gogoproto.enumvalue_customname) = "ORDERED"]; -} - -// State defines if a channel or connection is in one of the following states: -// CLOSED, INIT, TRYOPEN, OPEN or UNINITIALIZED. -enum State { - option (gogoproto.goproto_enum_prefix) = false; - - // Default State - STATE_UNINITIALIZED_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNINITIALIZED"]; - // A channel or connection end has just started the opening handshake. - STATE_INIT = 1 [(gogoproto.enumvalue_customname) = "INIT"]; - // A channel or connection end has acknowledged the handshake step on the counterparty chain. - STATE_TRYOPEN = 2 [(gogoproto.enumvalue_customname) = "TRYOPEN"]; - // A channel or connection end has completed the handshake. Open channels are - // ready to send and receive packets. - STATE_OPEN = 3 [(gogoproto.enumvalue_customname) = "OPEN"]; - // A channel end has been closed and can no longer be used to send or receive packets. - STATE_CLOSED = 4 [(gogoproto.enumvalue_customname) = "CLOSED"]; -} \ No newline at end of file