From 05e1d8679d011f30c24e08d26194e720a4dec1d6 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Thu, 14 Jul 2022 17:56:48 +0200 Subject: [PATCH 01/19] fix compile issues and channel keeper tests --- .../controller/ibc_middleware.go | 7 +- .../controller/keeper/relay.go | 40 +--- .../types/expected_keepers.go | 3 +- modules/apps/29-fee/ibc_middleware.go | 9 +- modules/apps/29-fee/keeper/relay.go | 13 +- modules/apps/29-fee/types/expected_keepers.go | 3 +- modules/apps/transfer/keeper/relay.go | 43 +---- .../apps/transfer/types/expected_keepers.go | 3 +- modules/core/04-channel/keeper/packet.go | 62 +++--- modules/core/04-channel/keeper/packet_test.go | 178 +++++++++--------- .../core/04-channel/keeper/timeout_test.go | 24 +-- modules/core/05-port/types/module.go | 7 +- testing/endpoint.go | 4 +- 13 files changed, 168 insertions(+), 228 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index b7c65874bfa..7dc28c37a21 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/keeper" "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported" @@ -177,7 +178,11 @@ func (im IBCMiddleware) OnTimeoutPacket( func (im IBCMiddleware) SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - packet ibcexported.PacketI, + srcPort string, + srcChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, ) error { panic("SendPacket not supported for ICA controller module. Please use SendTx") } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay.go b/modules/apps/27-interchain-accounts/controller/keeper/relay.go index 4eaf26c52a6..f47977245bd 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay.go @@ -21,57 +21,25 @@ func (k Keeper) SendTx(ctx sdk.Context, chanCap *capabilitytypes.Capability, con return 0, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID) } - sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID) - if !found { - return 0, sdkerrors.Wrap(channeltypes.ErrChannelNotFound, activeChannelID) - } - - destinationPort := sourceChannelEnd.GetCounterparty().GetPortID() - destinationChannel := sourceChannelEnd.GetCounterparty().GetChannelID() - if uint64(ctx.BlockTime().UnixNano()) >= timeoutTimestamp { return 0, icatypes.ErrInvalidTimeoutTimestamp } - return k.createOutgoingPacket(ctx, portID, activeChannelID, destinationPort, destinationChannel, chanCap, icaPacketData, timeoutTimestamp) -} - -func (k Keeper) createOutgoingPacket( - ctx sdk.Context, - sourcePort, - sourceChannel, - destinationPort, - destinationChannel string, - chanCap *capabilitytypes.Capability, - icaPacketData icatypes.InterchainAccountPacketData, - timeoutTimestamp uint64, -) (uint64, error) { if err := icaPacketData.ValidateBasic(); err != nil { return 0, sdkerrors.Wrap(err, "invalid interchain account packet data") } // get the next sequence - sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) + sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, portID, activeChannelID) if !found { - return 0, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "failed to retrieve next sequence send for channel %s on port %s", sourceChannel, sourcePort) + return 0, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "failed to retrieve next sequence send for channel %s on port %s", activeChannelID, portID) } - packet := channeltypes.NewPacket( - icaPacketData.GetBytes(), - sequence, - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - clienttypes.ZeroHeight(), - timeoutTimestamp, - ) - - if err := k.ics4Wrapper.SendPacket(ctx, chanCap, packet); err != nil { + if err := k.ics4Wrapper.SendPacket(ctx, chanCap, portID, activeChannelID, clienttypes.ZeroHeight(), timeoutTimestamp, icaPacketData.GetBytes()); err != nil { return 0, err } - return packet.Sequence, nil + return sequence, nil } // OnTimeoutPacket removes the active channel associated with the provided packet, the underlying channel end is closed diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index 8fb0b743cda..5b46ebc1724 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -5,6 +5,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported" ) @@ -20,7 +21,7 @@ type AccountKeeper interface { // ICS4Wrapper defines the expected ICS4Wrapper for middleware type ICS4Wrapper interface { - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, srcPort, srcChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) } diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 6a0477f5508..3f6ce645730 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/keeper" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types" "github.com/cosmos/ibc-go/v3/modules/core/exported" @@ -337,9 +338,13 @@ func (im IBCMiddleware) OnTimeoutPacket( func (im IBCMiddleware) SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - packet exported.PacketI, + srcPort string, + srcChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, ) error { - return im.keeper.SendPacket(ctx, chanCap, packet) + return im.keeper.SendPacket(ctx, chanCap, srcPort, srcChannel, timeoutHeight, timeoutTimestamp, data) } // WriteAcknowledgement implements the ICS4 Wrapper interface diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index 0c14726c9ed..dc421ba9ca4 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -8,13 +8,22 @@ import ( capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported" ) // SendPacket wraps IBC ChannelKeeper's SendPacket function -func (k Keeper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI) error { - return k.ics4Wrapper.SendPacket(ctx, chanCap, packet) +func (k Keeper) SendPacket( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + srcPort string, + srcChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, +) error { + return k.ics4Wrapper.SendPacket(ctx, chanCap, srcPort, srcChannel, timeoutHeight, timeoutTimestamp, data) } // WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index f725ff764b3..8c8ff7b82c0 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported" ) @@ -17,7 +18,7 @@ type AccountKeeper interface { // ICS4Wrapper defines the expected ICS4Wrapper for middleware type ICS4Wrapper interface { WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, srcPort, srcChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) } diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index cb4b8c59fd5..140d04904ff 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -62,24 +62,6 @@ func (k Keeper) SendTransfer( return types.ErrSendDisabled } - sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel) - if !found { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) - } - - destinationPort := sourceChannelEnd.GetCounterparty().GetPortID() - destinationChannel := sourceChannelEnd.GetCounterparty().GetChannelID() - - // get the next sequence - sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) - if !found { - return sdkerrors.Wrapf( - channeltypes.ErrSequenceSendNotFound, - "source port: %s, source channel: %s", sourcePort, sourceChannel, - ) - } - - // begin createOutgoingPacket logic // See spec for this logic: https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#packet-relay channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel)) if !ok { @@ -100,10 +82,7 @@ func (k Keeper) SendTransfer( } } - labels := []metrics.Label{ - telemetry.NewLabel(coretypes.LabelDestinationPort, destinationPort), - telemetry.NewLabel(coretypes.LabelDestinationChannel, destinationChannel), - } + labels := []metrics.Label{} // NOTE: SendTransfer simply sends the denomination as it exists on its own // chain inside the packet data. The receiving chain will perform denom @@ -113,15 +92,8 @@ func (k Keeper) SendTransfer( labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "true")) // create the escrow address for the tokens - escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel) // escrow source tokens. It fails if balance insufficient. - if err := k.bankKeeper.SendCoins( - ctx, sender, escrowAddress, sdk.NewCoins(token), - ); err != nil { - return err - } - } else { labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false")) @@ -146,18 +118,7 @@ func (k Keeper) SendTransfer( fullDenomPath, token.Amount.String(), sender.String(), receiver, ) - packet := channeltypes.NewPacket( - packetData.GetBytes(), - sequence, - sourcePort, - sourceChannel, - destinationPort, - destinationChannel, - timeoutHeight, - timeoutTimestamp, - ) - - if err := k.ics4Wrapper.SendPacket(ctx, channelCap, packet); err != nil { + if err := k.ics4Wrapper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetData.GetBytes()); err != nil { return err } diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index 22ad54b9e62..93e4a201afd 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported" @@ -28,7 +29,7 @@ type BankKeeper interface { // ICS4Wrapper defines the expected ICS4Wrapper for middleware type ICS4Wrapper interface { - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, srcPort, srcChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error } // ChannelKeeper defines the expected IBC channel keeper diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index c3e8e45b89c..ee30ece1dbd 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -22,15 +22,15 @@ import ( func (k Keeper) SendPacket( ctx sdk.Context, channelCap *capabilitytypes.Capability, - packet exported.PacketI, + srcPort string, + srcChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, ) error { - if err := packet.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "packet failed basic validation") - } - - channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) + channel, found := k.GetChannel(ctx, srcPort, srcChannel) if !found { - return sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetSourceChannel()) + return sdkerrors.Wrap(types.ErrChannelNotFound, srcChannel) } if channel.State == types.CLOSED { @@ -40,22 +40,24 @@ func (k Keeper) SendPacket( ) } - if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(packet.GetSourcePort(), packet.GetSourceChannel())) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", packet.GetSourcePort(), packet.GetSourceChannel()) + if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(srcPort, srcChannel)) { + return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", srcPort, srcChannel) } - if packet.GetDestPort() != channel.Counterparty.PortId { + sequence, found := k.GetNextSequenceSend(ctx, srcPort, srcChannel) + if !found { return sdkerrors.Wrapf( - types.ErrInvalidPacket, - "packet destination port doesn't match the counterparty's port (%s ≠ %s)", packet.GetDestPort(), channel.Counterparty.PortId, + types.ErrSequenceSendNotFound, + "source port: %s, source channel: %s", srcPort, srcChannel, ) } - if packet.GetDestChannel() != channel.Counterparty.ChannelId { - return sdkerrors.Wrapf( - types.ErrInvalidPacket, - "packet destination channel doesn't match the counterparty's channel (%s ≠ %s)", packet.GetDestChannel(), channel.Counterparty.ChannelId, - ) + // construct packet from given fields and channel state + packet := types.NewPacket(data, sequence, srcPort, srcChannel, + channel.Counterparty.PortId, channel.Counterparty.ChannelId, timeoutHeight, timeoutTimestamp) + + if err := packet.ValidateBasic(); err != nil { + return sdkerrors.Wrap(err, "constructed packet failed basic validation") } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) @@ -76,7 +78,6 @@ func (k Keeper) SendPacket( // check if packet is timed out on the receiving chain latestHeight := clientState.GetLatestHeight() - timeoutHeight := packet.GetTimeoutHeight() if !timeoutHeight.IsZero() && latestHeight.GTE(timeoutHeight) { return sdkerrors.Wrapf( types.ErrPacketTimeout, @@ -105,34 +106,19 @@ func (k Keeper) SendPacket( } } - nextSequenceSend, found := k.GetNextSequenceSend(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) - if !found { - return sdkerrors.Wrapf( - types.ErrSequenceSendNotFound, - "source port: %s, source channel: %s", packet.GetSourcePort(), packet.GetSourceChannel(), - ) - } - - if packet.GetSequence() != nextSequenceSend { - return sdkerrors.Wrapf( - types.ErrInvalidPacket, - "packet sequence ≠ next send sequence (%d ≠ %d)", packet.GetSequence(), nextSequenceSend, - ) - } - commitment := types.CommitPacket(k.cdc, packet) - nextSequenceSend++ - k.SetNextSequenceSend(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), nextSequenceSend) - k.SetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), commitment) + sequence++ + k.SetNextSequenceSend(ctx, srcPort, srcChannel, sequence) + k.SetPacketCommitment(ctx, srcPort, srcChannel, packet.GetSequence(), commitment) EmitSendPacketEvent(ctx, packet, channel, timeoutHeight) k.Logger(ctx).Info( "packet sent", "sequence", strconv.FormatUint(packet.GetSequence(), 10), - "src_port", packet.GetSourcePort(), - "src_channel", packet.GetSourceChannel(), + "src_port", srcPort, + "src_channel", srcChannel, "dst_port", packet.GetDestPort(), "dst_channel", packet.GetDestChannel(), ) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 4d05df46533..9d68009f2a2 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -20,7 +20,7 @@ import ( var ( disabledTimeoutTimestamp = uint64(0) disabledTimeoutHeight = clienttypes.ZeroHeight() - timeoutHeight = clienttypes.NewHeight(0, 100) + defaultTimeoutHeight = clienttypes.NewHeight(0, 100) // for when the testing package cannot be used clientIDA = "clientA" @@ -35,25 +35,33 @@ var ( // TestSendPacket tests SendPacket from chainA to chainB func (suite *KeeperTestSuite) TestSendPacket() { var ( - path *ibctesting.Path - packet exported.PacketI - channelCap *capabilitytypes.Capability + path *ibctesting.Path + srcPort string + srcChannel string + packetData []byte + timeoutHeight clienttypes.Height + timeoutTimestamp uint64 + channelCap *capabilitytypes.Capability ) testCases := []testCase{ {"success: UNORDERED channel", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + srcChannel = path.EndpointA.ChannelID + channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"success: ORDERED channel", func() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + srcChannel = path.EndpointA.ChannelID + channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"success with solomachine: UNORDERED channel", func() { suite.coordinator.Setup(path) + srcChannel = path.EndpointA.ChannelID + // swap client with solo machine solomachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachinesingle", "testing", 1) path.EndpointA.ClientID = clienttypes.FormatClientIdentifier(exported.Solomachine, 10) @@ -62,12 +70,13 @@ func (suite *KeeperTestSuite) TestSendPacket() { connection.ClientId = path.EndpointA.ClientID path.EndpointA.SetConnection(connection) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"success with solomachine: ORDERED channel", func() { path.SetChannelOrdered() suite.coordinator.Setup(path) + srcChannel = path.EndpointA.ChannelID + // swap client with solomachine solomachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachinesingle", "testing", 1) path.EndpointA.ClientID = clienttypes.FormatClientIdentifier(exported.Solomachine, 10) @@ -76,75 +85,53 @@ func (suite *KeeperTestSuite) TestSendPacket() { connection.ClientId = path.EndpointA.ClientID path.EndpointA.SetConnection(connection) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, - {"sending packet out of order on UNORDERED channel", func() { - // setup creates an unordered channel - suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 5, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }, false}, - {"sending packet out of order on ORDERED channel", func() { - path.SetChannelOrdered() - suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 5, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }, false}, {"packet basic validation failed, empty packet data", func() { suite.coordinator.Setup(path) - packet = types.NewPacket([]byte{}, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + srcChannel = path.EndpointA.ChannelID + channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + packetData = []byte{} }, false}, {"channel not found", func() { // use wrong channel naming suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + srcChannel = ibctesting.InvalidID channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"channel closed", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + srcChannel = path.EndpointA.ChannelID err := path.EndpointA.SetChannelClosed() suite.Require().NoError(err) }, false}, - {"packet dest port ≠ channel counterparty port", func() { - suite.coordinator.Setup(path) - // use wrong port for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }, false}, - {"packet dest channel ID ≠ channel counterparty channel ID", func() { - suite.coordinator.Setup(path) - // use wrong channel for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, timeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }, false}, {"connection not found", func() { // pass channel check suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel( suite.chainA.GetContext(), - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, + path.EndpointA.ChannelConfig.PortID, ibctesting.FirstChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{connIDA}, path.EndpointA.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + srcChannel = ibctesting.FirstChannelID suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"client state not found", func() { suite.coordinator.Setup(path) + srcChannel = path.EndpointA.ChannelID // change connection client ID connection := path.EndpointA.GetConnection() connection.ClientId = ibctesting.InvalidID suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chainA.GetContext(), path.EndpointA.ConnectionID, connection) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"client state is frozen", func() { suite.coordinator.Setup(path) + srcChannel = path.EndpointA.ChannelID connection := path.EndpointA.GetConnection() clientState := path.EndpointA.GetClientState() @@ -155,32 +142,37 @@ func (suite *KeeperTestSuite) TestSendPacket() { cs.FrozenHeight = clienttypes.NewHeight(0, 1) suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), connection.ClientId, cs) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"timeout height passed", func() { suite.coordinator.Setup(path) + srcChannel = path.EndpointA.ChannelID + // use client state latest height for timeout clientState := path.EndpointA.GetClientState() - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clientState.GetLatestHeight().(clienttypes.Height), disabledTimeoutTimestamp) + timeoutHeight = clientState.GetLatestHeight().(clienttypes.Height) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"timeout timestamp passed", func() { suite.coordinator.Setup(path) + srcChannel = path.EndpointA.ChannelID + // use latest time on client state clientState := path.EndpointA.GetClientState() connection := path.EndpointA.GetConnection() timestamp, err := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetTimestampAtHeight(suite.chainA.GetContext(), connection, clientState.GetLatestHeight()) suite.Require().NoError(err) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, disabledTimeoutHeight, timestamp) + timeoutHeight = disabledTimeoutHeight + timeoutTimestamp = timestamp channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"next sequence send not found", func() { path := ibctesting.NewPath(suite.chainA, suite.chainB) + srcChannel = path.EndpointA.ChannelID + suite.coordinator.SetupConnections(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) // manually creating channel prevents next sequence from being set suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel( suite.chainA.GetContext(), @@ -190,15 +182,10 @@ func (suite *KeeperTestSuite) TestSendPacket() { suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, - {"next sequence wrong", func() { - suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) - suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, 5) - channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - }, false}, {"channel capability not found", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + srcChannel = path.EndpointA.ChannelID + channelCap = capabilitytypes.NewCapability(5) }, false}, } @@ -209,9 +196,18 @@ func (suite *KeeperTestSuite) TestSendPacket() { suite.SetupTest() // reset path = ibctesting.NewPath(suite.chainA, suite.chainB) + // set default send packet arguments + // srcChannel is set after path is setup + srcPort = path.EndpointA.ChannelConfig.PortID + timeoutHeight = defaultTimeoutHeight + timeoutTimestamp = disabledTimeoutTimestamp + packetData = ibctesting.MockPacketData + + // malleate may modify send packet arguments above tc.malleate() - err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.SendPacket(suite.chainA.GetContext(), channelCap, packet) + err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.SendPacket(suite.chainA.GetContext(), channelCap, + srcPort, srcChannel, timeoutHeight, timeoutTimestamp, packetData) if tc.expPass { suite.Require().NoError(err) @@ -238,7 +234,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) @@ -246,7 +242,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { {"success UNORDERED channel", func() { // setup uses an UNORDERED channel suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) @@ -254,13 +250,13 @@ func (suite *KeeperTestSuite) TestRecvPacket() { {"success with out of order packet: UNORDERED channel", func() { // setup uses an UNORDERED channel suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // send 2 packets err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) // set sequence to 2 - packet = types.NewPacket(ibctesting.MockPacketData, 2, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 2, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err = path.EndpointA.SendPacket(packet) suite.Require().NoError(err) // attempts to receive packet 2 without receiving packet 1 @@ -272,7 +268,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) @@ -285,7 +281,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { // setup uses an UNORDERED channel suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) @@ -298,13 +294,13 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // send 2 packets err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) // set sequence to 2 - packet = types.NewPacket(ibctesting.MockPacketData, 2, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 2, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err = path.EndpointA.SendPacket(packet) suite.Require().NoError(err) // attempts to receive packet 2 without receiving packet 1 @@ -315,14 +311,14 @@ func (suite *KeeperTestSuite) TestRecvPacket() { // use wrong channel naming suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, ibctesting.InvalidID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, {"channel not open", func() { expError = types.ErrInvalidChannelState suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err := path.EndpointB.SetChannelClosed() suite.Require().NoError(err) @@ -334,7 +330,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) channelCap = capabilitytypes.NewCapability(3) @@ -344,7 +340,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { suite.coordinator.Setup(path) // use wrong port for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, {"packet source channel ID ≠ channel counterparty channel ID", func() { @@ -352,7 +348,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { suite.coordinator.Setup(path) // use wrong port for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, {"connection not found", func() { @@ -365,7 +361,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{connIDB}, path.EndpointB.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateChannelCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, @@ -383,7 +379,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointB.ConnectionID}, path.EndpointB.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) suite.chainB.CreateChannelCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, @@ -415,7 +411,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID), []string{path.EndpointB.ConnectionID}, path.EndpointB.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // manually set packet commitment suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, packet.GetSequence(), types.CommitPacket(suite.chainA.App.AppCodec(), packet)) @@ -430,7 +426,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { expError = types.ErrNoOpMsg suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) path.EndpointA.SendPacket(packet) suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetPacketReceipt(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, 1) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) @@ -440,7 +436,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { // packet commitment not set resulting in invalid proof suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, } @@ -501,7 +497,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { "success", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, @@ -510,13 +506,13 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { {"channel not found", func() { // use wrong channel naming suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, ibctesting.InvalidID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, {"channel not open", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement err := path.EndpointB.SetChannelClosed() @@ -527,7 +523,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { "capability authentication failed", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement channelCap = capabilitytypes.NewCapability(3) }, @@ -537,7 +533,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { "no-op, already acked", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chainB.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ack.Acknowledgement()) channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) @@ -548,7 +544,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { "empty acknowledgement", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.NewMockEmptyAcknowledgement() channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, @@ -558,7 +554,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { "acknowledgement is nil", func() { suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = nil channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, @@ -599,7 +595,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { {"success on ordered channel", func() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create packet commitment err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) @@ -613,7 +609,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { {"success on unordered channel", func() { // setup uses an UNORDERED channel suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create packet commitment err := path.EndpointA.SendPacket(packet) @@ -630,7 +626,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create packet commitment err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) @@ -649,7 +645,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // setup uses an UNORDERED channel suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create packet commitment err := path.EndpointA.SendPacket(packet) @@ -669,13 +665,13 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // use wrong channel naming suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) }, false}, {"channel not open", func() { expError = types.ErrInvalidChannelState suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) err := path.EndpointA.SetChannelClosed() suite.Require().NoError(err) @@ -687,7 +683,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create packet commitment err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) @@ -703,7 +699,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { suite.coordinator.Setup(path) // use wrong port for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"packet destination channel ID ≠ channel counterparty channel ID", func() { @@ -711,7 +707,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { suite.coordinator.Setup(path) // use wrong channel for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"connection not found", func() { @@ -724,7 +720,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{"connection-1000"}, path.EndpointA.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, @@ -741,7 +737,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{path.EndpointA.ConnectionID}, path.EndpointA.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, @@ -750,7 +746,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // packet commitment never written suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"packet ack verification failed", func() { @@ -758,7 +754,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // ack never written suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create packet commitment path.EndpointA.SendPacket(packet) @@ -769,7 +765,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { // setup uses an UNORDERED channel suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create packet commitment err := path.EndpointA.SendPacket(packet) @@ -797,7 +793,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{path.EndpointA.ConnectionID}, path.EndpointA.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // manually set packet commitment suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, packet.GetSequence(), types.CommitPacket(suite.chainA.App.AppCodec(), packet)) @@ -816,7 +812,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { expError = types.ErrPacketSequenceOutOfOrder path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create packet commitment err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index ae3a816ef16..d65fd442a14 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -78,7 +78,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { expError = types.ErrChannelNotFound // use wrong channel naming suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) }, false}, {"channel not open", func() { expError = types.ErrInvalidChannelState @@ -96,13 +96,13 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { expError = types.ErrInvalidPacket suite.coordinator.Setup(path) // use wrong port for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) }, false}, {"packet destination channel ID ≠ channel counterparty channel ID", func() { expError = types.ErrInvalidPacket suite.coordinator.Setup(path) // use wrong channel for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) }, false}, {"connection not found", func() { expError = connectiontypes.ErrConnectionNotFound @@ -112,12 +112,12 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{connIDA}, path.EndpointA.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) }, false}, {"timeout", func() { expError = types.ErrPacketTimeout suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) path.EndpointA.SendPacket(packet) path.EndpointA.UpdateClient() }, false}, @@ -129,7 +129,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { nextSeqRecv = 2 suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, uint64(suite.chainB.GetContext().BlockTime().UnixNano())) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, uint64(suite.chainB.GetContext().BlockTime().UnixNano())) path.EndpointA.SendPacket(packet) path.EndpointA.UpdateClient() }, false}, @@ -139,7 +139,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { path.SetChannelOrdered() suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, uint64(suite.chainB.GetContext().BlockTime().UnixNano())) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, uint64(suite.chainB.GetContext().BlockTime().UnixNano())) path.EndpointA.UpdateClient() }, false}, {"next seq receive verification failed", func() { @@ -232,7 +232,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() { {"channel not found", func() { // use wrong channel naming suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) }, false}, {"incorrect capability ORDERED", func() { path.SetChannelOrdered() @@ -305,18 +305,18 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { {"channel not found", func() { // use wrong channel naming suite.coordinator.Setup(path) - packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, ibctesting.InvalidID, ibctesting.InvalidID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) }, false}, {"packet dest port ≠ channel counterparty port", func() { suite.coordinator.Setup(path) // use wrong port for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"packet dest channel ID ≠ channel counterparty channel ID", func() { suite.coordinator.Setup(path) // use wrong channel for dest - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) chanCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"connection not found", func() { @@ -326,7 +326,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{connIDA}, path.EndpointA.ChannelConfig.Version), ) - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, timeoutHeight, disabledTimeoutTimestamp) + packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) // create chancap suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index 26501af313c..2b39711f536 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" "github.com/cosmos/ibc-go/v3/modules/core/exported" ) @@ -110,7 +111,11 @@ type ICS4Wrapper interface { SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - packet exported.PacketI, + srcPort string, + srcChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, ) error WriteAcknowledgement( diff --git a/testing/endpoint.go b/testing/endpoint.go index 94fa14f8b0d..0eed48ad991 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -375,7 +375,9 @@ func (endpoint *Endpoint) SendPacket(packet exported.PacketI) error { channelCap := endpoint.Chain.GetChannelCapability(packet.GetSourcePort(), packet.GetSourceChannel()) // no need to send message, acting as a module - err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SendPacket(endpoint.Chain.GetContext(), channelCap, packet) + // TODO: Change Endpoint SendPacket to take in arguments directly + err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SendPacket(endpoint.Chain.GetContext(), channelCap, + packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp(), packet.GetData()) if err != nil { return err } From 99db505fac41062b86db114f6237c6af9434fd61 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Thu, 14 Jul 2022 18:38:54 +0200 Subject: [PATCH 02/19] add back deleted code --- modules/apps/transfer/keeper/relay.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 140d04904ff..21733809db2 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -92,8 +92,14 @@ func (k Keeper) SendTransfer( labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "true")) // create the escrow address for the tokens + escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel) // escrow source tokens. It fails if balance insufficient. + if err := k.bankKeeper.SendCoins( + ctx, sender, escrowAddress, sdk.NewCoins(token), + ); err != nil { + return err + } } else { labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false")) From 3d4a0ebd55953babbdbc291da7b715b3044bc207 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Thu, 14 Jul 2022 18:59:32 +0200 Subject: [PATCH 03/19] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db771acd750..5c9ea03106c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (transfer)[\#1565](https://github.com/cosmos/ibc-go/pull/1565) Removing `NewErrorAcknowledgement` in favour of `channeltypes.NewErrorAcknowledgement`. * (channel)[\#1565](https://github.com/cosmos/ibc-go/pull/1565) Updating `NewErrorAcknowledgement` to accept an error instead of a string and removing the possibility of non-deterministic writes to application state. * (core/04-channel)[\#1636](https://github.com/cosmos/ibc-go/pull/1636) Removing `SplitChannelVersion` and `MergeChannelVersions` functions since they are not used. +* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update SendPacket API to take in necessary arguments and construct rest of packet rather than taking in entire packet. ### State Machine Breaking From 3cbbef66229e217fec2fac6bbc45f5409e540f6d Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Fri, 30 Sep 2022 12:22:23 -0500 Subject: [PATCH 04/19] fix var naming and remove unnecessary test cases --- .../controller/ibc_middleware.go | 4 +- .../controller/keeper/relay_test.go | 7 ---- .../types/expected_keepers.go | 4 +- modules/apps/29-fee/ibc_middleware.go | 6 +-- modules/apps/29-fee/keeper/relay.go | 6 +-- modules/apps/29-fee/types/expected_keepers.go | 4 +- modules/apps/transfer/keeper/relay_test.go | 9 ----- .../apps/transfer/types/expected_keepers.go | 4 +- modules/core/04-channel/keeper/packet.go | 26 ++++++------- modules/core/04-channel/keeper/packet_test.go | 38 +++++++++---------- modules/core/05-port/types/module.go | 4 +- 11 files changed, 48 insertions(+), 64 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index 6bbb5fcac6b..28f293e05b6 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -181,8 +181,8 @@ func (im IBCMiddleware) OnTimeoutPacket( func (im IBCMiddleware) SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - srcPort string, - srcChannel string, + sourcePort string, + sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go b/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go index a980d3f953d..0230ae36b52 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay_test.go @@ -93,13 +93,6 @@ func (suite *KeeperTestSuite) TestSendTx() { }, false, }, - { - "channel does not exist", - func() { - suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, "channel-100") - }, - false, - }, { "channel in INIT state - optimistic packet sends fail", func() { diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index e8fc7550dd2..5cf76b35ee0 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -21,13 +21,13 @@ type AccountKeeper interface { // ICS4Wrapper defines the expected ICS4Wrapper for middleware type ICS4Wrapper interface { - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, srcPort, srcChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) } // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) GetConnection(ctx sdk.Context, connectionID string) (ibcexported.ConnectionI, error) } diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index d0f37696d50..8096eb0d836 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -338,13 +338,13 @@ func (im IBCMiddleware) OnTimeoutPacket( func (im IBCMiddleware) SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - srcPort string, - srcChannel string, + sourcePort string, + sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, ) error { - return im.keeper.SendPacket(ctx, chanCap, srcPort, srcChannel, timeoutHeight, timeoutTimestamp, data) + return im.keeper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) } // WriteAcknowledgement implements the ICS4 Wrapper interface diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index 465ebce51e2..7f89e5f0273 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -17,13 +17,13 @@ import ( func (k Keeper) SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - srcPort string, - srcChannel string, + sourcePort string, + sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, ) error { - return k.ics4Wrapper.SendPacket(ctx, chanCap, srcPort, srcChannel, timeoutHeight, timeoutTimestamp, data) + return k.ics4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) } // WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index b3dad273387..e9136eb4522 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -19,13 +19,13 @@ type AccountKeeper interface { // ICS4Wrapper defines the expected ICS4Wrapper for middleware type ICS4Wrapper interface { WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, srcPort, srcChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) } // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) } diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index ac60ed3964b..61c3d8d8f6a 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -43,15 +43,6 @@ func (suite *KeeperTestSuite) TestSendTransfer() { amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.DefaultBondDenom, sdk.NewInt(100)) }, false, true, }, - { - "source channel not found", - func() { - // channel references wrong ID - suite.coordinator.CreateTransferChannels(path) - path.EndpointA.ChannelID = ibctesting.InvalidID - amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) - }, true, false, - }, { "next seq send not found", func() { diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index d012071aeb5..ca64c956b66 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -29,12 +29,12 @@ type BankKeeper interface { // ICS4Wrapper defines the expected ICS4Wrapper for middleware type ICS4Wrapper interface { - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, srcPort, srcChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error } // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) + GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) } diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index b4e24fdd0e7..c0c5488e277 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -22,15 +22,15 @@ import ( func (k Keeper) SendPacket( ctx sdk.Context, channelCap *capabilitytypes.Capability, - srcPort string, - srcChannel string, + sourcePort string, + sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, ) error { - channel, found := k.GetChannel(ctx, srcPort, srcChannel) + channel, found := k.GetChannel(ctx, sourcePort, sourceChannel) if !found { - return sdkerrors.Wrap(types.ErrChannelNotFound, srcChannel) + return sdkerrors.Wrap(types.ErrChannelNotFound, sourceChannel) } if channel.State == types.CLOSED { @@ -40,20 +40,20 @@ func (k Keeper) SendPacket( ) } - if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(srcPort, srcChannel)) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", srcPort, srcChannel) + if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(sourcePort, sourceChannel)) { + return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } - sequence, found := k.GetNextSequenceSend(ctx, srcPort, srcChannel) + sequence, found := k.GetNextSequenceSend(ctx, sourcePort, sourceChannel) if !found { return sdkerrors.Wrapf( types.ErrSequenceSendNotFound, - "source port: %s, source channel: %s", srcPort, srcChannel, + "source port: %s, source channel: %s", sourcePort, sourceChannel, ) } // construct packet from given fields and channel state - packet := types.NewPacket(data, sequence, srcPort, srcChannel, + packet := types.NewPacket(data, sequence, sourcePort, sourceChannel, channel.Counterparty.PortId, channel.Counterparty.ChannelId, timeoutHeight, timeoutTimestamp) if err := packet.ValidateBasic(); err != nil { @@ -109,16 +109,16 @@ func (k Keeper) SendPacket( commitment := types.CommitPacket(k.cdc, packet) sequence++ - k.SetNextSequenceSend(ctx, srcPort, srcChannel, sequence) - k.SetPacketCommitment(ctx, srcPort, srcChannel, packet.GetSequence(), commitment) + k.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence) + k.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment) EmitSendPacketEvent(ctx, packet, channel, timeoutHeight) k.Logger(ctx).Info( "packet sent", "sequence", strconv.FormatUint(packet.GetSequence(), 10), - "src_port", srcPort, - "src_channel", srcChannel, + "src_port", sourcePort, + "src_channel", sourceChannel, "dst_port", packet.GetDestPort(), "dst_channel", packet.GetDestChannel(), ) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 206c0961642..52631cd6a7e 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -36,8 +36,8 @@ var ( func (suite *KeeperTestSuite) TestSendPacket() { var ( path *ibctesting.Path - srcPort string - srcChannel string + sourcePort string + sourceChannel string packetData []byte timeoutHeight clienttypes.Height timeoutTimestamp uint64 @@ -47,20 +47,20 @@ func (suite *KeeperTestSuite) TestSendPacket() { testCases := []testCase{ {"success: UNORDERED channel", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"success: ORDERED channel", func() { path.SetChannelOrdered() suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, true}, {"success with solomachine: UNORDERED channel", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID // swap client with solo machine solomachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachinesingle", "testing", 1) @@ -75,7 +75,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { {"success with solomachine: ORDERED channel", func() { path.SetChannelOrdered() suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID // swap client with solomachine solomachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachinesingle", "testing", 1) @@ -89,7 +89,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { }, true}, {"packet basic validation failed, empty packet data", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) packetData = []byte{} @@ -97,12 +97,12 @@ func (suite *KeeperTestSuite) TestSendPacket() { {"channel not found", func() { // use wrong channel naming suite.coordinator.Setup(path) - srcChannel = ibctesting.InvalidID + sourceChannel = ibctesting.InvalidID channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"channel closed", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID err := path.EndpointA.SetChannelClosed() suite.Require().NoError(err) @@ -114,13 +114,13 @@ func (suite *KeeperTestSuite) TestSendPacket() { path.EndpointA.ChannelConfig.PortID, ibctesting.FirstChannelID, types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{connIDA}, path.EndpointA.ChannelConfig.Version), ) - srcChannel = ibctesting.FirstChannelID + sourceChannel = ibctesting.FirstChannelID suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"client state not found", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID // change connection client ID connection := path.EndpointA.GetConnection() @@ -131,7 +131,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { }, false}, {"client state is frozen", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID connection := path.EndpointA.GetConnection() clientState := path.EndpointA.GetClientState() @@ -147,7 +147,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { {"timeout height passed", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID // use client state latest height for timeout clientState := path.EndpointA.GetClientState() @@ -156,7 +156,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { }, false}, {"timeout timestamp passed", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID // use latest time on client state clientState := path.EndpointA.GetClientState() @@ -170,7 +170,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { }, false}, {"next sequence send not found", func() { path := ibctesting.NewPath(suite.chainA, suite.chainB) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID suite.coordinator.SetupConnections(path) // manually creating channel prevents next sequence from being set @@ -184,7 +184,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { }, false}, {"channel capability not found", func() { suite.coordinator.Setup(path) - srcChannel = path.EndpointA.ChannelID + sourceChannel = path.EndpointA.ChannelID channelCap = capabilitytypes.NewCapability(5) }, false}, @@ -197,8 +197,8 @@ func (suite *KeeperTestSuite) TestSendPacket() { path = ibctesting.NewPath(suite.chainA, suite.chainB) // set default send packet arguments - // srcChannel is set after path is setup - srcPort = path.EndpointA.ChannelConfig.PortID + // sourceChannel is set after path is setup + sourcePort = path.EndpointA.ChannelConfig.PortID timeoutHeight = defaultTimeoutHeight timeoutTimestamp = disabledTimeoutTimestamp packetData = ibctesting.MockPacketData @@ -207,7 +207,7 @@ func (suite *KeeperTestSuite) TestSendPacket() { tc.malleate() err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.SendPacket(suite.chainA.GetContext(), channelCap, - srcPort, srcChannel, timeoutHeight, timeoutTimestamp, packetData) + sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetData) if tc.expPass { suite.Require().NoError(err) diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index e7882556475..f600992b48c 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -111,8 +111,8 @@ type ICS4Wrapper interface { SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - srcPort string, - srcChannel string, + sourcePort string, + sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, From 847fd9883410cfcaba1e971e674a439289ff18c3 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Fri, 30 Sep 2022 13:01:08 -0500 Subject: [PATCH 05/19] add sequence to return argument of SendPacket --- .../controller/ibc_middleware.go | 2 +- .../controller/keeper/keeper.go | 5 +-- .../controller/keeper/relay.go | 9 ++---- .../types/expected_keepers.go | 7 ----- modules/apps/29-fee/ibc_middleware.go | 2 +- modules/apps/29-fee/keeper/keeper.go | 5 +-- modules/apps/29-fee/keeper/relay.go | 2 +- modules/apps/29-fee/types/expected_keepers.go | 9 ------ modules/apps/transfer/keeper/keeper.go | 5 +-- modules/apps/transfer/keeper/relay.go | 2 +- .../apps/transfer/types/expected_keepers.go | 6 ---- modules/core/04-channel/keeper/packet.go | 31 +++++++++---------- modules/core/04-channel/keeper/packet_test.go | 8 ++++- modules/core/05-port/types/module.go | 2 +- testing/endpoint.go | 2 +- 15 files changed, 39 insertions(+), 58 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index 28f293e05b6..ab550aa1c91 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -186,7 +186,7 @@ func (im IBCMiddleware) SendPacket( timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, -) error { +) (uint64, error) { panic("SendPacket not supported for ICA controller module. Please use SendTx") } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 3ecdb169197..9aa9309b180 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v4/modules/core/24-host" ) @@ -24,7 +25,7 @@ type Keeper struct { cdc codec.BinaryCodec paramSpace paramtypes.Subspace - ics4Wrapper icatypes.ICS4Wrapper + ics4Wrapper porttypes.ICS4Wrapper channelKeeper icatypes.ChannelKeeper portKeeper icatypes.PortKeeper @@ -36,7 +37,7 @@ type Keeper struct { // NewKeeper creates a new interchain accounts controller Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - ics4Wrapper icatypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, + ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, msgRouter *baseapp.MsgServiceRouter, ) Keeper { // set KeyTable if it has not already been set diff --git a/modules/apps/27-interchain-accounts/controller/keeper/relay.go b/modules/apps/27-interchain-accounts/controller/keeper/relay.go index f7c6e6e8097..f1bc237efa6 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/relay.go @@ -29,13 +29,8 @@ func (k Keeper) SendTx(ctx sdk.Context, chanCap *capabilitytypes.Capability, con return 0, sdkerrors.Wrap(err, "invalid interchain account packet data") } - // get the next sequence - sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, portID, activeChannelID) - if !found { - return 0, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "failed to retrieve next sequence send for channel %s on port %s", activeChannelID, portID) - } - - if err := k.ics4Wrapper.SendPacket(ctx, chanCap, portID, activeChannelID, clienttypes.ZeroHeight(), timeoutTimestamp, icaPacketData.GetBytes()); err != nil { + sequence, err := k.ics4Wrapper.SendPacket(ctx, chanCap, portID, activeChannelID, clienttypes.ZeroHeight(), timeoutTimestamp, icaPacketData.GetBytes()) + if err != nil { return 0, err } diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index 5cf76b35ee0..87957864903 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -5,7 +5,6 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported" ) @@ -19,12 +18,6 @@ type AccountKeeper interface { GetModuleAddress(name string) sdk.AccAddress } -// ICS4Wrapper defines the expected ICS4Wrapper for middleware -type ICS4Wrapper interface { - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error - GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) -} - // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 8096eb0d836..425f832773c 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -343,7 +343,7 @@ func (im IBCMiddleware) SendPacket( timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, -) error { +) (uint64, error) { return im.keeper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) } diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index c60942debea..b863d36013c 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" + porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v4/modules/core/24-host" ) @@ -25,7 +26,7 @@ type Keeper struct { cdc codec.BinaryCodec authKeeper types.AccountKeeper - ics4Wrapper types.ICS4Wrapper + ics4Wrapper porttypes.ICS4Wrapper channelKeeper types.ChannelKeeper portKeeper types.PortKeeper bankKeeper types.BankKeeper @@ -34,7 +35,7 @@ type Keeper struct { // NewKeeper creates a new 29-fee Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - ics4Wrapper types.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, + ics4Wrapper porttypes.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, ) Keeper { return Keeper{ cdc: cdc, diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index 7f89e5f0273..ddc66c9f274 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -22,7 +22,7 @@ func (k Keeper) SendPacket( timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, -) error { +) (uint64, error) { return k.ics4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data) } diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index e9136eb4522..e4793505040 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -5,9 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" - ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported" ) // AccountKeeper defines the contract required for account APIs. @@ -16,13 +14,6 @@ type AccountKeeper interface { GetAccount(sdk.Context, sdk.AccAddress) types.AccountI } -// ICS4Wrapper defines the expected ICS4Wrapper for middleware -type ICS4Wrapper interface { - WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error - GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) -} - // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 2a9c5c16db0..2446d4a93ce 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -11,6 +11,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" + porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v4/modules/core/24-host" ) @@ -20,7 +21,7 @@ type Keeper struct { cdc codec.BinaryCodec paramSpace paramtypes.Subspace - ics4Wrapper types.ICS4Wrapper + ics4Wrapper porttypes.ICS4Wrapper channelKeeper types.ChannelKeeper portKeeper types.PortKeeper authKeeper types.AccountKeeper @@ -31,7 +32,7 @@ type Keeper struct { // NewKeeper creates a new IBC transfer Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - ics4Wrapper types.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, + ics4Wrapper porttypes.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) Keeper { // ensure ibc transfer module account is set diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index e278f48ec50..5438e344a16 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -124,7 +124,7 @@ func (k Keeper) SendTransfer( fullDenomPath, token.Amount.String(), sender.String(), receiver, ) - if err := k.ics4Wrapper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetData.GetBytes()); err != nil { + if _, err := k.ics4Wrapper.SendPacket(ctx, channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetData.GetBytes()); err != nil { return err } diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index ca64c956b66..94328b77e2d 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v4/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported" @@ -27,11 +26,6 @@ type BankKeeper interface { BlockedAddr(addr sdk.AccAddress) bool } -// ICS4Wrapper defines the expected ICS4Wrapper for middleware -type ICS4Wrapper interface { - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, sourcePort, sourceChannel string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) error -} - // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index c0c5488e277..d0a544066f1 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -27,26 +27,26 @@ func (k Keeper) SendPacket( timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, -) error { +) (uint64, error) { channel, found := k.GetChannel(ctx, sourcePort, sourceChannel) if !found { - return sdkerrors.Wrap(types.ErrChannelNotFound, sourceChannel) + return 0, sdkerrors.Wrap(types.ErrChannelNotFound, sourceChannel) } if channel.State == types.CLOSED { - return sdkerrors.Wrapf( + return 0, sdkerrors.Wrapf( types.ErrInvalidChannelState, "channel is CLOSED (got %s)", channel.State.String(), ) } if !k.scopedKeeper.AuthenticateCapability(ctx, channelCap, host.ChannelCapabilityPath(sourcePort, sourceChannel)) { - return sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel) + return 0, sdkerrors.Wrapf(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } sequence, found := k.GetNextSequenceSend(ctx, sourcePort, sourceChannel) if !found { - return sdkerrors.Wrapf( + return 0, sdkerrors.Wrapf( types.ErrSequenceSendNotFound, "source port: %s, source channel: %s", sourcePort, sourceChannel, ) @@ -57,29 +57,29 @@ func (k Keeper) SendPacket( channel.Counterparty.PortId, channel.Counterparty.ChannelId, timeoutHeight, timeoutTimestamp) if err := packet.ValidateBasic(); err != nil { - return sdkerrors.Wrap(err, "constructed packet failed basic validation") + return 0, sdkerrors.Wrap(err, "constructed packet failed basic validation") } connectionEnd, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0]) if !found { - return sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) + return 0, sdkerrors.Wrap(connectiontypes.ErrConnectionNotFound, channel.ConnectionHops[0]) } clientState, found := k.clientKeeper.GetClientState(ctx, connectionEnd.GetClientID()) if !found { - return clienttypes.ErrConsensusStateNotFound + return 0, clienttypes.ErrConsensusStateNotFound } // prevent accidental sends with clients that cannot be updated clientStore := k.clientKeeper.ClientStore(ctx, connectionEnd.GetClientID()) if status := clientState.Status(ctx, clientStore, k.cdc); status != exported.Active { - return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.GetClientID(), status) + return 0, sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.GetClientID(), status) } // check if packet is timed out on the receiving chain latestHeight := clientState.GetLatestHeight() if !timeoutHeight.IsZero() && latestHeight.GTE(timeoutHeight) { - return sdkerrors.Wrapf( + return 0, sdkerrors.Wrapf( types.ErrPacketTimeout, "receiving chain block height >= packet timeout height (%s >= %s)", latestHeight, timeoutHeight, ) @@ -87,7 +87,7 @@ func (k Keeper) SendPacket( clientType, _, err := clienttypes.ParseClientIdentifier(connectionEnd.GetClientID()) if err != nil { - return err + return 0, err } // NOTE: this is a temporary fix. Solo machine does not support usage of 'GetTimestampAtHeight' @@ -95,11 +95,11 @@ func (k Keeper) SendPacket( if clientType != exported.Solomachine { latestTimestamp, err := k.connectionKeeper.GetTimestampAtHeight(ctx, connectionEnd, latestHeight) if err != nil { - return err + return 0, err } if packet.GetTimeoutTimestamp() != 0 && latestTimestamp >= packet.GetTimeoutTimestamp() { - return sdkerrors.Wrapf( + return 0, sdkerrors.Wrapf( types.ErrPacketTimeout, "receiving chain block timestamp >= packet timeout timestamp (%s >= %s)", time.Unix(0, int64(latestTimestamp)), time.Unix(0, int64(packet.GetTimeoutTimestamp())), ) @@ -108,9 +108,8 @@ func (k Keeper) SendPacket( commitment := types.CommitPacket(k.cdc, packet) - sequence++ k.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence) - k.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment) + k.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence()+1, commitment) EmitSendPacketEvent(ctx, packet, channel, timeoutHeight) @@ -123,7 +122,7 @@ func (k Keeper) SendPacket( "dst_channel", packet.GetDestChannel(), ) - return nil + return packet.GetSequence(), nil } // RecvPacket is called by a module in order to receive & process an IBC packet diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 52631cd6a7e..4f8045c933a 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -206,11 +206,17 @@ func (suite *KeeperTestSuite) TestSendPacket() { // malleate may modify send packet arguments above tc.malleate() - err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.SendPacket(suite.chainA.GetContext(), channelCap, + // only check if nextSequenceSend exists in no error case since it is a tested error case above. + expectedSequence, ok := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceSend(suite.chainA.GetContext(), sourcePort, sourceChannel) + + sequence, err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.SendPacket(suite.chainA.GetContext(), channelCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, packetData) if tc.expPass { suite.Require().NoError(err) + // verify that the returned sequence matches expected value + suite.Require().True(ok) + suite.Require().Equal(expectedSequence, sequence, "send packet did not return the expected sequence of the outgoing packet") } else { suite.Require().Error(err) } diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index f600992b48c..ed0c9d0e9f6 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -116,7 +116,7 @@ type ICS4Wrapper interface { timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte, - ) error + ) (sequence uint64, err error) WriteAcknowledgement( ctx sdk.Context, diff --git a/testing/endpoint.go b/testing/endpoint.go index f6513145b24..01ab7d08fb5 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -376,7 +376,7 @@ func (endpoint *Endpoint) SendPacket(packet exported.PacketI) error { // no need to send message, acting as a module // TODO: Change Endpoint SendPacket to take in arguments directly - err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SendPacket(endpoint.Chain.GetContext(), channelCap, + _, err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SendPacket(endpoint.Chain.GetContext(), channelCap, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp(), packet.GetData()) if err != nil { return err From 8386d5db5451a8736a956cafd4818853b65cda38 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Fri, 30 Sep 2022 16:36:00 -0500 Subject: [PATCH 06/19] remove print --- testing/endpoint.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testing/endpoint.go b/testing/endpoint.go index dd029e016a9..c56d4853748 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -428,14 +428,12 @@ func (endpoint *Endpoint) SendPacket(packet exported.PacketI) error { // no need to send message, acting as a module // TODO: Change Endpoint SendPacket to take in arguments directly - sequence, err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SendPacket(endpoint.Chain.GetContext(), channelCap, + _, err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.SendPacket(endpoint.Chain.GetContext(), channelCap, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetTimeoutHeight().(clienttypes.Height), packet.GetTimeoutTimestamp(), packet.GetData()) if err != nil { return err } - fmt.Println(sequence) - // commit changes since no message was sent endpoint.Chain.Coordinator.CommitBlock(endpoint.Chain) From 302d32ab24af8e8f5230330dafde7fd445968134 Mon Sep 17 00:00:00 2001 From: Aditya Date: Fri, 30 Sep 2022 16:37:43 -0500 Subject: [PATCH 07/19] Remove unnecessary diffs --- modules/apps/27-interchain-accounts/types/expected_keepers.go | 2 +- modules/apps/29-fee/types/expected_keepers.go | 2 +- modules/apps/transfer/types/expected_keepers.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/apps/27-interchain-accounts/types/expected_keepers.go b/modules/apps/27-interchain-accounts/types/expected_keepers.go index 1a68a4231ce..534f6d617bc 100644 --- a/modules/apps/27-interchain-accounts/types/expected_keepers.go +++ b/modules/apps/27-interchain-accounts/types/expected_keepers.go @@ -20,7 +20,7 @@ type AccountKeeper interface { // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) GetConnection(ctx sdk.Context, connectionID string) (ibcexported.ConnectionI, error) GetAllChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []channeltypes.IdentifiedChannel diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index 52919b31247..c7168eef370 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -16,7 +16,7 @@ type AccountKeeper interface { // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) } diff --git a/modules/apps/transfer/types/expected_keepers.go b/modules/apps/transfer/types/expected_keepers.go index f8a2c38f2d2..47dd6cb0ee2 100644 --- a/modules/apps/transfer/types/expected_keepers.go +++ b/modules/apps/transfer/types/expected_keepers.go @@ -28,7 +28,7 @@ type BankKeeper interface { // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - GetChannel(ctx sdk.Context, sourcePort, srcChan string) (channel channeltypes.Channel, found bool) + GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) } From 8dc0c4a53a6cea1056904a3f297d33157904f24f Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Fri, 30 Sep 2022 16:41:02 -0500 Subject: [PATCH 08/19] update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dc4dd9290d..c17b58634e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (transfer) [\#2034](https://github.com/cosmos/ibc-go/pull/2034) Transfer Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (05-port) [\#2025](https://github.com/cosmos/ibc-go/pull/2025) Port Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (04-channel) [\#2024](https://github.com/cosmos/ibc-go/pull/2024) Channel Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. +* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update SendPacket API to take in necessary arguments and construct rest of packet rather than taking in entire packet. +* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Transfer SendPacket telemetry no longer includes destination portID and channelID. ### State Machine Breaking @@ -148,7 +150,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (transfer)[\#1565](https://github.com/cosmos/ibc-go/pull/1565) Removing `NewErrorAcknowledgement` in favour of `channeltypes.NewErrorAcknowledgement`. * (channel)[\#1565](https://github.com/cosmos/ibc-go/pull/1565) Updating `NewErrorAcknowledgement` to accept an error instead of a string and removing the possibility of non-deterministic writes to application state. * (core/04-channel)[\#1636](https://github.com/cosmos/ibc-go/pull/1636) Removing `SplitChannelVersion` and `MergeChannelVersions` functions since they are not used. -* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update SendPacket API to take in necessary arguments and construct rest of packet rather than taking in entire packet. ### State Machine Breaking From c6d98614a0e6a88a375a9578fc8b2f0a7e94c7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 3 Oct 2022 14:11:40 +0200 Subject: [PATCH 09/19] Apply suggestions from code review --- modules/apps/29-fee/keeper/relay.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index 24a7a20ba45..b9d3c8eb123 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -13,7 +13,7 @@ import ( ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported" ) -// SendPacket wraps IBC ChannelKeeper's SendPacket function +// SendPacket wraps the ICS4Wrapper SendPacket function func (k Keeper) SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, From 36742b02764a1daebd0f8902ec64538f6f0706cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 3 Oct 2022 14:11:51 +0200 Subject: [PATCH 10/19] Apply suggestions from code review Co-authored-by: Carlos Rodriguez --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c17b58634e4..fbfd2009a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,8 +59,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (transfer) [\#2034](https://github.com/cosmos/ibc-go/pull/2034) Transfer Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (05-port) [\#2025](https://github.com/cosmos/ibc-go/pull/2025) Port Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (04-channel) [\#2024](https://github.com/cosmos/ibc-go/pull/2024) Channel Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. -* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update SendPacket API to take in necessary arguments and construct rest of packet rather than taking in entire packet. -* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Transfer SendPacket telemetry no longer includes destination portID and channelID. +* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update `SendPacket` API to take in necessary arguments and construct rest of packet rather than taking in entire packet. +* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Transfer `SendPacket` telemetry no longer includes destination portID and channelID. ### State Machine Breaking From e8b8a331dafe1b3896b6552e79fee2a5244c7b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 3 Oct 2022 16:55:26 +0200 Subject: [PATCH 11/19] chore: remove unnecessary test --- modules/apps/transfer/keeper/relay_test.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index 1c03c0fa851..b2afa4881f4 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -45,21 +45,6 @@ func (suite *KeeperTestSuite) TestSendTransfer() { amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.DefaultBondDenom, sdk.NewInt(100)) }, false, true, }, - { - "next seq send not found", - func() { - path.EndpointA.ChannelID = "channel-0" - path.EndpointB.ChannelID = "channel-0" - // manually create channel so next seq send is never set - suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel( - suite.chainA.GetContext(), - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, - channeltypes.NewChannel(channeltypes.OPEN, channeltypes.ORDERED, channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{path.EndpointA.ConnectionID}, ibctesting.DefaultChannelVersion), - ) - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) - amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) - }, true, false, - }, { "transfer failed - sender account is blocked", func() { From c348aa47678573ec30ebf2b7e71363cc9bbfd4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 3 Oct 2022 17:03:55 +0200 Subject: [PATCH 12/19] chore: add migration docs --- docs/v5-to-v6.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 docs/v5-to-v6.md diff --git a/docs/v5-to-v6.md b/docs/v5-to-v6.md new file mode 100644 index 00000000000..9c83e94b184 --- /dev/null +++ b/docs/v5-to-v6.md @@ -0,0 +1,40 @@ + +# Migrating from ibc-go v5 to v6 + +This document is intended to highlight significant changes which may require more information than presented in the CHANGELOG. +Any changes that must be done by a user of ibc-go should be documented here. + +There are four sections based on the four potential user groups of this document: +- Chains +- IBC Apps +- Relayers +- IBC Light Clients + +**Note:** ibc-go supports golang semantic versioning and therefore all imports must be updated to bump the version number on major releases. + +## Chains + +## IBC Apps + +### ICS04 - SendPacket API change + +The `SendPacket` API has been simplified: + +```diff +// SendPacket is called by a module in order to send an IBC packet on a channel +@@ -22,122 +22,98 @@ import ( + func (k Keeper) SendPacket( + ctx sdk.Context, + channelCap *capabilitytypes.Capability, +- packet exported.PacketI, +-) error { ++ sourcePort string, ++ sourceChannel string, ++ timeoutHeight clienttypes.Height, ++ timeoutTimestamp uint64, ++ data []byte, ++) (uint64, error) { +``` + +Callers no longer need to pass in a pre-constructed packet. +The destination port/channel identifiers and the packet sequence will be determined by core IBC. From c30f011d4f475529980d42b14beba22c9f9b6417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 3 Oct 2022 17:12:47 +0200 Subject: [PATCH 13/19] revert breaking telemetry --- CHANGELOG.md | 1 - modules/apps/transfer/keeper/relay.go | 13 ++++++++++++- modules/apps/transfer/keeper/relay_test.go | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbfd2009a18..03096f5eb73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,7 +60,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (05-port) [\#2025](https://github.com/cosmos/ibc-go/pull/2025) Port Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (04-channel) [\#2024](https://github.com/cosmos/ibc-go/pull/2024) Channel Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update `SendPacket` API to take in necessary arguments and construct rest of packet rather than taking in entire packet. -* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Transfer `SendPacket` telemetry no longer includes destination portID and channelID. ### State Machine Breaking diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 774a15b6a01..b6d8963a231 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -91,6 +91,14 @@ func (k Keeper) sendTransfer( return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) } + channel, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel) + if !found { + return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) + } + + destinationPort := channel.GetCounterparty().GetPortID() + destinationChannel := channel.GetCounterparty().GetChannelID() + // begin createOutgoingPacket logic // See spec for this logic: https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#packet-relay channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel)) @@ -112,7 +120,10 @@ func (k Keeper) sendTransfer( } } - labels := []metrics.Label{} + labels := []metrics.Label{ + telemetry.NewLabel(coretypes.LabelDestinationPort, destinationPort), + telemetry.NewLabel(coretypes.LabelDestinationChannel, destinationChannel), + } // NOTE: SendTransfer simply sends the denomination as it exists on its own // chain inside the packet data. The receiving chain will perform denom diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index b2afa4881f4..7fc80eeb679 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -45,6 +45,15 @@ func (suite *KeeperTestSuite) TestSendTransfer() { amount = types.GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, sdk.DefaultBondDenom, sdk.NewInt(100)) }, false, true, }, + { + "source channel not found", + func() { + // channel references wrong ID + suite.coordinator.CreateTransferChannels(path) + path.EndpointA.ChannelID = ibctesting.InvalidID + amount = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)) + }, true, false, + }, { "transfer failed - sender account is blocked", func() { From 079c3a1945da0680c90734121067bc8c736b91d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 3 Oct 2022 17:14:52 +0200 Subject: [PATCH 14/19] fix: migration docs was in wrong location --- docs/{ => migrations}/v5-to-v6.md | 1 + 1 file changed, 1 insertion(+) rename docs/{ => migrations}/v5-to-v6.md (96%) diff --git a/docs/v5-to-v6.md b/docs/migrations/v5-to-v6.md similarity index 96% rename from docs/v5-to-v6.md rename to docs/migrations/v5-to-v6.md index 9c83e94b184..00f2754a4f5 100644 --- a/docs/v5-to-v6.md +++ b/docs/migrations/v5-to-v6.md @@ -38,3 +38,4 @@ The `SendPacket` API has been simplified: Callers no longer need to pass in a pre-constructed packet. The destination port/channel identifiers and the packet sequence will be determined by core IBC. +`SendPacket` will return the packet sequence. From 90e5e0841e5417d4a965a7d6890447d35d845197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 5 Oct 2022 14:55:10 +0200 Subject: [PATCH 15/19] Update docs/migrations/v5-to-v6.md Co-authored-by: Damian Nolan --- docs/migrations/v5-to-v6.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/migrations/v5-to-v6.md b/docs/migrations/v5-to-v6.md index 00f2754a4f5..49efe3f1978 100644 --- a/docs/migrations/v5-to-v6.md +++ b/docs/migrations/v5-to-v6.md @@ -22,7 +22,6 @@ The `SendPacket` API has been simplified: ```diff // SendPacket is called by a module in order to send an IBC packet on a channel -@@ -22,122 +22,98 @@ import ( func (k Keeper) SendPacket( ctx sdk.Context, channelCap *capabilitytypes.Capability, From 827529abfd9b15eb0f1137a0df518c4bd9be8269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 5 Oct 2022 14:59:45 +0200 Subject: [PATCH 16/19] update 'SendPacket' godoc --- modules/core/04-channel/keeper/packet.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 16562177a43..e3fb1c25e8e 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -16,9 +16,9 @@ import ( "github.com/cosmos/ibc-go/v6/modules/core/exported" ) -// SendPacket is called by a module in order to send an IBC packet on a channel -// end owned by the calling module to the corresponding module on the counterparty -// chain. +// SendPacket is called by a module in order to send an IBC packet on a channel. +// The packet sequence generated for the packet to be sent is returned. An error +// is returned if one occurs. func (k Keeper) SendPacket( ctx sdk.Context, channelCap *capabilitytypes.Capability, From 9a7737e8772d193ec923e4e29560d591e71ad55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 5 Oct 2022 15:05:43 +0200 Subject: [PATCH 17/19] chore: update changelog entry to include packet seq return --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a95682364..0f6ac505248 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,7 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (transfer) [\#2034](https://github.com/cosmos/ibc-go/pull/2034) Transfer Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (05-port) [\#2025](https://github.com/cosmos/ibc-go/pull/2025) Port Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. * (04-channel) [\#2024](https://github.com/cosmos/ibc-go/pull/2024) Channel Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper. -* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update `SendPacket` API to take in necessary arguments and construct rest of packet rather than taking in entire packet. +* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update `SendPacket` API to take in necessary arguments and construct rest of packet rather than taking in entire packet. The generated packet sequence is returned by the `SendPacket` function. * (modules/apps/27-interchain-accounts) [\#2433](https://github.com/cosmos/ibc-go/pull/2450) Renamed icatypes.PortPrefix to icatypes.ControllerPortPrefix & icatypes.PortID to icatypes.HostPortID ### State Machine Breaking From 6ad76d13beebb1d0e34f948b4f3b04432c9b495a Mon Sep 17 00:00:00 2001 From: crodriguezvega Date: Wed, 5 Oct 2022 22:18:44 +0200 Subject: [PATCH 18/19] update documentation --- docs/ibc/apps.md | 24 ++++++++++++++--- docs/ibc/apps/ibcmodule.md | 11 ++++++-- docs/ibc/apps/packets_acks.md | 14 ++++++++-- docs/ibc/middleware/develop.md | 47 ++++++++++++++++++++++++++++------ docs/migrations/v5-to-v6.md | 2 +- 5 files changed, 82 insertions(+), 16 deletions(-) diff --git a/docs/ibc/apps.md b/docs/ibc/apps.md index 11fa1e84b7e..48d517176e0 100644 --- a/docs/ibc/apps.md +++ b/docs/ibc/apps.md @@ -238,10 +238,21 @@ DecodePacketData(encoded []byte) (CustomPacketData) { Then a module must encode its packet data before sending it through IBC. ```go +// retrieve the dynamic capability for this channel +channelCap := scopedKeeper.GetCapability(ctx, channelCapName) // Sending custom application packet data data := EncodePacketData(customPacketData) packet.Data = data -IBCChannelKeeper.SendPacket(ctx, packet) +// Send packet to IBC, authenticating with channelCap +sequence, err := IBCChannelKeeper.SendPacket( + ctx, + channelCap, + sourcePort, + sourceChannel, + timeoutHeight, + timeoutTimestamp, + data, +) ``` A module receiving a packet must decode the `PacketData` into a structure it expects so that it can @@ -284,9 +295,16 @@ packet a module simply needs to call `SendPacket` on the `IBCChannelKeeper`. channelCap := scopedKeeper.GetCapability(ctx, channelCapName) // Sending custom application packet data data := EncodePacketData(customPacketData) -packet.Data = data // Send packet to IBC, authenticating with channelCap -IBCChannelKeeper.SendPacket(ctx, channelCap, packet) +sequence, err := IBCChannelKeeper.SendPacket( + ctx, + channelCap, + sourcePort, + sourceChannel, + timeoutHeight, + timeoutTimestamp, + data, +) ``` ::: warning diff --git a/docs/ibc/apps/ibcmodule.md b/docs/ibc/apps/ibcmodule.md index d5864435700..2a4a7473657 100644 --- a/docs/ibc/apps/ibcmodule.md +++ b/docs/ibc/apps/ibcmodule.md @@ -232,9 +232,16 @@ module must trigger execution on the port-bound module through the use of callba channelCap := scopedKeeper.GetCapability(ctx, channelCapName) // Sending custom application packet data data := EncodePacketData(customPacketData) -packet.Data = data // Send packet to IBC, authenticating with channelCap -IBCChannelKeeper.SendPacket(ctx, channelCap, packet) +sequence, err := IBCChannelKeeper.SendPacket( + ctx, + channelCap, + sourcePort, + sourceChannel, + timeoutHeight, + timeoutTimestamp, + data, +) ``` ::: warning diff --git a/docs/ibc/apps/packets_acks.md b/docs/ibc/apps/packets_acks.md index 1871eca8915..a46c60fa9c1 100644 --- a/docs/ibc/apps/packets_acks.md +++ b/docs/ibc/apps/packets_acks.md @@ -43,10 +43,20 @@ DecodePacketData(encoded []byte) (CustomPacketData) { Then a module must encode its packet data before sending it through IBC. ```go +// retrieve the dynamic capability for this channel +channelCap := scopedKeeper.GetCapability(ctx, channelCapName) // Sending custom application packet data data := EncodePacketData(customPacketData) -packet.Data = data -IBCChannelKeeper.SendPacket(ctx, packet) +// Send packet to IBC, authenticating with channelCap +sequence, err := IBCChannelKeeper.SendPacket( + ctx, + channelCap, + sourcePort, + sourceChannel, + timeoutHeight, + timeoutTimestamp, + data, +) ``` A module receiving a packet must decode the `PacketData` into a structure it expects so that it can diff --git a/docs/ibc/middleware/develop.md b/docs/ibc/middleware/develop.md index 7ee020ca9c8..e05a3f6cd31 100644 --- a/docs/ibc/middleware/develop.md +++ b/docs/ibc/middleware/develop.md @@ -47,9 +47,28 @@ type Middleware interface { // The base application will call `sendPacket` or `writeAcknowledgement` of the middleware directly above them // which will call the next middleware until it reaches the core IBC handler. type ICS4Wrapper interface { - SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet exported.Packet) error - WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet exported.Packet, ack exported.Acknowledgement) error - GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) + SendPacket( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + sourcePort string, + sourceChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + data []byte, + ) (sequence uint64, err error) + + WriteAcknowledgement( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + packet exported.PacketI, + ack exported.Acknowledgement, + ) error + + GetAppVersion( + ctx sdk.Context, + portID, + channelID string, + ) (string, bool) } ``` @@ -352,12 +371,24 @@ Middleware must also wrap ICS-4 so that any communication from the application t func SendPacket( ctx sdk.Context, chanCap *capabilitytypes.Capability, - appPacket exported.PacketI, + sourcePort string, + sourceChannel string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, + appData []byte, ) { - // middleware may modify packet - packet = doCustomLogic(appPacket) - - return ics4Keeper.SendPacket(ctx, chanCap, packet) + // middleware may modify data + data = doCustomLogic(appData) + + return ics4Keeper.SendPacket( + ctx, + chanCap, + sourcePort, + sourceChannel, + timeoutHeight, + timeoutTimestamp, + data, + ) } ``` diff --git a/docs/migrations/v5-to-v6.md b/docs/migrations/v5-to-v6.md index 49efe3f1978..b41d01d19c1 100644 --- a/docs/migrations/v5-to-v6.md +++ b/docs/migrations/v5-to-v6.md @@ -16,7 +16,7 @@ There are four sections based on the four potential user groups of this document ## IBC Apps -### ICS04 - SendPacket API change +### ICS04 - `SendPacket` API change The `SendPacket` API has been simplified: From 17882e691bf523e105e3ea3390cb75873e6764c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 6 Oct 2022 13:06:12 +0200 Subject: [PATCH 19/19] chore: fix test case to increase code coverage --- modules/core/04-channel/keeper/packet_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index e7fb19d3294..111384c714b 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -109,13 +109,13 @@ func (suite *KeeperTestSuite) TestSendPacket() { }, false}, {"connection not found", func() { // pass channel check - suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetChannel( - suite.chainA.GetContext(), - path.EndpointA.ChannelConfig.PortID, ibctesting.FirstChannelID, - types.NewChannel(types.OPEN, types.ORDERED, types.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID), []string{connIDA}, path.EndpointA.ChannelConfig.Version), - ) - sourceChannel = ibctesting.FirstChannelID - suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) + suite.coordinator.Setup(path) + sourceChannel = path.EndpointA.ChannelID + + channel := path.EndpointA.GetChannel() + channel.ConnectionHops[0] = "invalid-connection" + path.EndpointA.SetChannel(channel) + channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"client state not found", func() {