diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a13c9b169d..7a30be169c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking +* (transfer) [\#2377](https://github.com/cosmos/ibc-go/pull/2377) Adding `sequence` to `MsgTransferResponse`. + ### Improvements ### Features diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index ac68d818cd2..03db61a0cc7 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -2158,6 +2158,11 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf MsgTransferResponse defines the Msg/Transfer response type. +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sequence` | [uint64](#uint64) | | sequence number of the transfer packet sent | + + diff --git a/modules/apps/transfer/keeper/msg_server.go b/modules/apps/transfer/keeper/msg_server.go index 41368f3f984..e1cb4e8cc6e 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -19,9 +19,10 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. return nil, err } - if err := k.SendTransfer( + sequence, err := k.sendTransfer( ctx, msg.SourcePort, msg.SourceChannel, msg.Token, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp, - ); err != nil { + ) + if err != nil { return nil, err } @@ -39,5 +40,5 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types. ), }) - return &types.MsgTransferResponse{}, nil + return &types.MsgTransferResponse{Sequence: sequence}, nil } diff --git a/modules/apps/transfer/keeper/msg_server_test.go b/modules/apps/transfer/keeper/msg_server_test.go index 17900bd9b17..e0a9037e343 100644 --- a/modules/apps/transfer/keeper/msg_server_test.go +++ b/modules/apps/transfer/keeper/msg_server_test.go @@ -61,6 +61,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() { res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) if tc.expPass { + suite.Require().NotEqual(res.Sequence, uint64(0)) suite.Require().NoError(err) suite.Require().NotNil(res) } else { diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 48816f5356b..8576f849a52 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -60,17 +60,41 @@ func (k Keeper) SendTransfer( timeoutHeight clienttypes.Height, timeoutTimestamp uint64, ) error { + _, err := k.sendTransfer( + ctx, + sourcePort, + sourceChannel, + token, + sender, + receiver, + timeoutHeight, + timeoutTimestamp, + ) + return err +} + +// sendTransfer handles transfer sending logic. +func (k Keeper) sendTransfer( + ctx sdk.Context, + sourcePort, + sourceChannel string, + token sdk.Coin, + sender sdk.AccAddress, + receiver string, + timeoutHeight clienttypes.Height, + timeoutTimestamp uint64, +) (uint64, error) { if !k.GetSendEnabled(ctx) { - return types.ErrSendDisabled + return 0, types.ErrSendDisabled } if k.bankKeeper.BlockedAddr(sender) { - return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) + return 0, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender) } sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel) if !found { - return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) + return 0, sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel) } destinationPort := sourceChannelEnd.GetCounterparty().GetPortID() @@ -79,7 +103,7 @@ func (k Keeper) SendTransfer( // get the next sequence sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) if !found { - return sdkerrors.Wrapf( + return 0, sdkerrors.Wrapf( channeltypes.ErrSequenceSendNotFound, "source port: %s, source channel: %s", sourcePort, sourceChannel, ) @@ -89,7 +113,7 @@ func (k Keeper) SendTransfer( // 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 { - return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + return 0, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } // NOTE: denomination and hex hash correctness checked during msg.ValidateBasic @@ -102,7 +126,7 @@ func (k Keeper) SendTransfer( if strings.HasPrefix(token.Denom, "ibc/") { fullDenomPath, err = k.DenomPathFromHash(ctx, token.Denom) if err != nil { - return err + return 0, err } } @@ -125,7 +149,7 @@ func (k Keeper) SendTransfer( if err := k.bankKeeper.SendCoins( ctx, sender, escrowAddress, sdk.NewCoins(token), ); err != nil { - return err + return 0, err } } else { @@ -135,7 +159,7 @@ func (k Keeper) SendTransfer( if err := k.bankKeeper.SendCoinsFromAccountToModule( ctx, sender, types.ModuleName, sdk.NewCoins(token), ); err != nil { - return err + return 0, err } if err := k.bankKeeper.BurnCoins( @@ -164,7 +188,7 @@ func (k Keeper) SendTransfer( ) if err := k.ics4Wrapper.SendPacket(ctx, channelCap, packet); err != nil { - return err + return 0, err } defer func() { @@ -183,7 +207,7 @@ func (k Keeper) SendTransfer( ) }() - return nil + return sequence, nil } // OnRecvPacket processes a cross chain fungible token transfer. If the diff --git a/modules/apps/transfer/types/tx.pb.go b/modules/apps/transfer/types/tx.pb.go index 6d3c210450e..3ef41191c10 100644 --- a/modules/apps/transfer/types/tx.pb.go +++ b/modules/apps/transfer/types/tx.pb.go @@ -87,6 +87,8 @@ var xxx_messageInfo_MsgTransfer proto.InternalMessageInfo // MsgTransferResponse defines the Msg/Transfer response type. type MsgTransferResponse struct { + // sequence number of the transfer packet sent + Sequence uint64 `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"` } func (m *MsgTransferResponse) Reset() { *m = MsgTransferResponse{} } @@ -122,6 +124,13 @@ func (m *MsgTransferResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgTransferResponse proto.InternalMessageInfo +func (m *MsgTransferResponse) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + func init() { proto.RegisterType((*MsgTransfer)(nil), "ibc.applications.transfer.v1.MsgTransfer") proto.RegisterType((*MsgTransferResponse)(nil), "ibc.applications.transfer.v1.MsgTransferResponse") @@ -132,38 +141,39 @@ func init() { } var fileDescriptor_7401ed9bed2f8e09 = []byte{ - // 494 bytes of a gzipped FileDescriptorProto + // 506 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x6d, 0x92, 0x86, 0x70, 0x51, 0x2b, 0x30, 0xb4, 0x72, 0xa3, 0x62, 0x47, 0x96, 0x90, - 0xc2, 0xc0, 0x9d, 0x5c, 0x40, 0x95, 0x3a, 0xa1, 0x74, 0x81, 0xa1, 0x12, 0x58, 0x9d, 0x58, 0x8a, - 0x7d, 0x3d, 0x9c, 0x13, 0xf1, 0x3d, 0xeb, 0xee, 0x62, 0xd1, 0x6f, 0xc0, 0xc8, 0x47, 0xe8, 0xcc, - 0x27, 0xe9, 0xd8, 0x91, 0x29, 0x42, 0xc9, 0xc2, 0x9c, 0x4f, 0x80, 0xce, 0xbe, 0x84, 0x64, 0x41, - 0x4c, 0xf6, 0x7b, 0xff, 0xdf, 0xbb, 0xbf, 0xde, 0xbd, 0x77, 0xe8, 0x19, 0xcf, 0x28, 0x49, 0xcb, - 0x72, 0xc2, 0x69, 0xaa, 0x39, 0x08, 0x45, 0xb4, 0x4c, 0x85, 0xfa, 0xcc, 0x24, 0xa9, 0x62, 0xa2, - 0xbf, 0xe2, 0x52, 0x82, 0x06, 0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, 0x6e, 0xff, 0xc9, 0x1a, + 0x09, 0xa2, 0xfb, 0x4d, 0xee, 0x7c, 0x95, 0x3a, 0xe9, 0x7e, 0xbb, 0xf6, 0xad, 0xdf, 0xd7, 0xbe, + 0x15, 0x84, 0xe4, 0xe1, 0xc6, 0xac, 0x22, 0x50, 0x39, 0x4a, 0x05, 0xc6, 0xa9, 0x82, 0x2f, 0x53, + 0x90, 0x1c, 0xaa, 0x81, 0xb5, 0xa3, 0x75, 0x7c, 0x84, 0xa4, 0x75, 0xa6, 0x52, 0x67, 0x4c, 0xba, + 0xeb, 0x11, 0x3f, 0xa3, 0xff, 0x5a, 0x34, 0xba, 0xa1, 0xd0, 0x0f, 0xff, 0x1b, 0x5d, 0x7d, 0xcc, + 0xe8, 0xfd, 0xcd, 0xdc, 0xb3, 0x6f, 0xe7, 0x9e, 0xfd, 0x6b, 0xee, 0xd9, 0xdf, 0x17, 0x9e, 0x75, + 0xbb, 0xf0, 0xac, 0x9f, 0x0b, 0xcf, 0xfa, 0x70, 0x9c, 0x0a, 0x3d, 0x9e, 0x26, 0x94, 0x63, 0xc6, + 0x9a, 0xb5, 0x15, 0x09, 0x7f, 0x9e, 0x22, 0x2b, 0x5f, 0xb2, 0x0c, 0x2f, 0xa7, 0x13, 0x50, 0xe6, + 0x99, 0x6c, 0x3c, 0x0f, 0x7d, 0x95, 0x83, 0x4a, 0x3a, 0xd5, 0xaa, 0xbe, 0xf8, 0x13, 0x00, 0x00, + 0xff, 0xff, 0xb5, 0xaa, 0xe1, 0xd5, 0x48, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -344,6 +354,11 @@ func (m *MsgTransferResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Sequence != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -396,6 +411,9 @@ func (m *MsgTransferResponse) Size() (n int) { } var l int _ = l + if m.Sequence != 0 { + n += 1 + sovTx(uint64(m.Sequence)) + } return n } @@ -697,6 +715,25 @@ func (m *MsgTransferResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgTransferResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/proto/ibc/applications/transfer/v1/tx.proto b/proto/ibc/applications/transfer/v1/tx.proto index 5befdf2fbc3..2ec1dd2ebcb 100644 --- a/proto/ibc/applications/transfer/v1/tx.proto +++ b/proto/ibc/applications/transfer/v1/tx.proto @@ -41,4 +41,7 @@ message MsgTransfer { } // MsgTransferResponse defines the Msg/Transfer response type. -message MsgTransferResponse {} +message MsgTransferResponse { + // sequence number of the transfer packet sent + uint64 sequence = 1; +}