diff --git a/CHANGELOG.md b/CHANGELOG.md index a38758f4f44..e9ab5c1b778 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 c8e4c0a3ecf..5aaf1fd55f4 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -711,6 +711,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 d2688cc0163..84c4c6d59ce 100644 --- a/modules/apps/transfer/keeper/msg_server.go +++ b/modules/apps/transfer/keeper/msg_server.go @@ -18,9 +18,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 } @@ -38,5 +39,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 ff043b8d5c6..f884413aa96 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 ba934c87e68..3716d7cccb3 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -60,18 +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() @@ -80,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, ) @@ -90,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 @@ -103,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 } } @@ -126,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 { @@ -136,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( @@ -165,7 +188,7 @@ func (k Keeper) SendTransfer( ) if err := k.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil { - return err + return 0, err } defer func() { @@ -184,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 9440631dd96..ba9f0397b36 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{ - // 495 bytes of a gzipped FileDescriptorProto + // 508 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0xc1, 0x6e, 0xd3, 0x4c, - 0x10, 0xc7, 0xed, 0x2f, 0x69, 0xbe, 0xb0, 0x51, 0x2b, 0x30, 0xb4, 0x72, 0xa3, 0x62, 0x47, 0x96, - 0x90, 0xc2, 0x81, 0x5d, 0x39, 0x08, 0x55, 0xea, 0x09, 0xa5, 0x17, 0x38, 0x54, 0x02, 0xab, 0x27, - 0x2e, 0xc5, 0xde, 0x2e, 0xce, 0x8a, 0x78, 0xc7, 0xda, 0xdd, 0x58, 0xf4, 0x0d, 0x38, 0xf2, 0x08, - 0x3d, 0xf3, 0x24, 0x3d, 0xf6, 0xc8, 0x29, 0x42, 0xc9, 0x85, 0x73, 0x9e, 0x00, 0xad, 0xbd, 0x09, - 0xc9, 0x05, 0x71, 0xb2, 0x67, 0xfe, 0xbf, 0xd9, 0xbf, 0x66, 0x67, 0x16, 0x3d, 0xe3, 0x19, 0x25, - 0x69, 0x59, 0x4e, 0x39, 0x4d, 0x35, 0x07, 0xa1, 0x88, 0x96, 0xa9, 0x50, 0x9f, 0x98, 0x24, 0x55, - 0x4c, 0xf4, 0x17, 0x5c, 0x4a, 0xd0, 0xe0, 0x9d, 0xf0, 0x8c, 0x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 0x00, 0x00, 0xff, 0xff, 0x10, 0x10, 0xcc, 0xb9, 0x2c, 0x03, 0x00, 0x00, + 0x10, 0xc7, 0xed, 0x2f, 0x69, 0xbe, 0xb0, 0x51, 0x2b, 0x30, 0x50, 0xb9, 0x51, 0xb1, 0x23, 0x4b, + 0x48, 0xe1, 0xc0, 0xae, 0x1c, 0x84, 0x2a, 0xf5, 0x84, 0xd2, 0x0b, 0x1c, 0x2a, 0x81, 0xd5, 0x13, + 0x97, 0x62, 0x6f, 0x07, 0x67, 0x45, 0xbc, 0x63, 0xbc, 0x1b, 0x8b, 0xbe, 0x01, 0x47, 0x1e, 0xa1, + 0x67, 0x9e, 0xa4, 0xc7, 0x1e, 0x39, 0x45, 0x28, 0xb9, 0x70, 0xce, 0x13, 0xa0, 0xb5, 0x9d, 0x90, + 0x5c, 0x10, 0xa7, 0xec, 0xcc, 0xfc, 0x26, 0x7f, 0xff, 0x77, 0x66, 0xc9, 0x53, 0x91, 0x70, 0x16, + 0xe7, 0xf9, 0x54, 0xf0, 0x58, 0x0b, 0x94, 0x8a, 0xe9, 0x22, 0x96, 0xea, 0x23, 0x14, 0xac, 0x0c, + 0x99, 0xfe, 0x42, 0xf3, 0x02, 0x35, 0x3a, 0xc7, 0x22, 0xe1, 0x74, 0x1b, 0xa3, 0x6b, 0x8c, 0x96, + 0x61, 0xff, 0x51, 0x8a, 0x29, 0x56, 0x20, 0x33, 0xa7, 0xba, 0xa7, 0xef, 0x71, 0x54, 0x19, 0x2a, + 0x96, 0xc4, 0x0a, 0x58, 0x19, 0x26, 0xa0, 0xe3, 0x90, 0x71, 0x14, 0xb2, 0xa9, 0xfb, 0x46, 0x9a, + 0x63, 0x01, 0x8c, 0x4f, 0x05, 0x48, 0x6d, 0x04, 0xeb, 0x53, 0x0d, 0x04, 0xdf, 0x5b, 0xa4, 0x77, + 0xae, 0xd2, 0x8b, 0x46, 0xc9, 0x39, 0x21, 0x3d, 0x85, 0xb3, 0x82, 0xc3, 0x65, 0x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 0x74, 0xbf, 0xc9, 0x5d, 0xac, 0x53, 0xa7, 0xdd, 0xaf, 0x37, 0xbe, 0xf5, 0xeb, + 0xc6, 0xb7, 0x82, 0x90, 0x3c, 0xdc, 0x9a, 0x55, 0x04, 0x2a, 0x47, 0xa9, 0xc0, 0x38, 0x55, 0xf0, + 0x79, 0x06, 0x92, 0x43, 0x35, 0xb0, 0x76, 0xb4, 0x89, 0x47, 0x48, 0x5a, 0xe7, 0x2a, 0x75, 0x26, + 0xa4, 0xbb, 0x19, 0xf1, 0x33, 0xfa, 0xb7, 0x45, 0xa3, 0x5b, 0x0a, 0xfd, 0xf0, 0x9f, 0xd1, 0xf5, + 0xc7, 0x8c, 0xdf, 0xdd, 0x2e, 0x3c, 0xfb, 0x6e, 0xe1, 0xd9, 0x3f, 0x17, 0x9e, 0xfd, 0x6d, 0xe9, + 0x59, 0x77, 0x4b, 0xcf, 0xfa, 0xb1, 0xf4, 0xac, 0xf7, 0x27, 0xa9, 0xd0, 0x93, 0x59, 0x42, 0x39, + 0x66, 0xac, 0x59, 0x5b, 0x91, 0xf0, 0xe7, 0x29, 0xb2, 0x72, 0xc4, 0x32, 0xbc, 0x9a, 0x4d, 0x41, + 0x99, 0x67, 0xb2, 0xf5, 0x3c, 0xf4, 0x75, 0x0e, 0x2a, 0xe9, 0x54, 0xab, 0xfa, 0xe2, 0x77, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x75, 0xd4, 0x23, 0x61, 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 dfc480d07a4..d571d276a6c 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; +}