Skip to content

Commit 51dc611

Browse files
mergify[bot]agouincrodriguezvega
authored
MsgTransferResponse add sequence (backport #2377) (#2464)
* MsgTransferResponse add sequence (#2377) ## Description Returns sequence from `sendTransfer`, and returns it with the `MsgTransferResponse`. This is not an API breaking change. Retrieving the sequence at the time of creating the transfer is necessary in the packet forward middleware for correlation with multihop packet flows. strangelove-ventures/packet-forward-middleware#33 strangelove-ventures/interchaintest#306 Closes #1969 --- - [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [x] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing) Existing test coverage exercises this new method due to the re-routing of `SendTransfer` through `SendPacketTransfer` - [x] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`) - [x] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [x] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [x] Re-reviewed `Files changed` in the Github PR explorer - [x] Review `Codecov Report` in the comment section below once CI passes (cherry picked from commit 3363917) # Conflicts: # CHANGELOG.md # modules/apps/transfer/keeper/msg_server.go # modules/apps/transfer/keeper/relay.go # modules/apps/transfer/types/tx.pb.go * fix conflicts * fix tests Co-authored-by: Andrew Gouin <andrew@gouin.io> Co-authored-by: crodriguezvega <carlos@interchain.io>
1 parent 96464aa commit 51dc611

File tree

7 files changed

+117
-45
lines changed

7 files changed

+117
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
4242

4343
### State Machine Breaking
4444

45+
* (transfer) [\#2377](https://github.com/cosmos/ibc-go/pull/2377) Adding `sequence` to `MsgTransferResponse`.
46+
4547
### Improvements
4648

4749
### Features

docs/ibc/proto-docs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,11 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transf
711711
MsgTransferResponse defines the Msg/Transfer response type.
712712

713713

714+
| Field | Type | Label | Description |
715+
| ----- | ---- | ----- | ----------- |
716+
| `sequence` | [uint64](#uint64) | | sequence number of the transfer packet sent |
717+
718+
714719

715720

716721

modules/apps/transfer/keeper/msg_server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.
1818
return nil, err
1919
}
2020

21-
if err := k.SendTransfer(
21+
sequence, err := k.sendTransfer(
2222
ctx, msg.SourcePort, msg.SourceChannel, msg.Token, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp,
23-
); err != nil {
23+
)
24+
if err != nil {
2425
return nil, err
2526
}
2627

@@ -38,5 +39,5 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.
3839
),
3940
})
4041

41-
return &types.MsgTransferResponse{}, nil
42+
return &types.MsgTransferResponse{Sequence: sequence}, nil
4243
}

modules/apps/transfer/keeper/msg_server_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() {
6161
res, err := suite.chainA.GetSimApp().TransferKeeper.Transfer(sdk.WrapSDKContext(suite.chainA.GetContext()), msg)
6262

6363
if tc.expPass {
64+
suite.Require().NotEqual(res.Sequence, uint64(0))
6465
suite.Require().NoError(err)
6566
suite.Require().NotNil(res)
6667
} else {

modules/apps/transfer/keeper/relay.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,41 @@ func (k Keeper) SendTransfer(
6060
timeoutHeight clienttypes.Height,
6161
timeoutTimestamp uint64,
6262
) error {
63+
_, err := k.sendTransfer(
64+
ctx,
65+
sourcePort,
66+
sourceChannel,
67+
token,
68+
sender,
69+
receiver,
70+
timeoutHeight,
71+
timeoutTimestamp,
72+
)
73+
return err
74+
}
6375

76+
// sendTransfer handles transfer sending logic.
77+
func (k Keeper) sendTransfer(
78+
ctx sdk.Context,
79+
sourcePort,
80+
sourceChannel string,
81+
token sdk.Coin,
82+
sender sdk.AccAddress,
83+
receiver string,
84+
timeoutHeight clienttypes.Height,
85+
timeoutTimestamp uint64,
86+
) (uint64, error) {
6487
if !k.GetSendEnabled(ctx) {
65-
return types.ErrSendDisabled
88+
return 0, types.ErrSendDisabled
6689
}
6790

6891
if k.bankKeeper.BlockedAddr(sender) {
69-
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender)
92+
return 0, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to send funds", sender)
7093
}
7194

7295
sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel)
7396
if !found {
74-
return sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel)
97+
return 0, sdkerrors.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", sourcePort, sourceChannel)
7598
}
7699

77100
destinationPort := sourceChannelEnd.GetCounterparty().GetPortID()
@@ -80,7 +103,7 @@ func (k Keeper) SendTransfer(
80103
// get the next sequence
81104
sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel)
82105
if !found {
83-
return sdkerrors.Wrapf(
106+
return 0, sdkerrors.Wrapf(
84107
channeltypes.ErrSequenceSendNotFound,
85108
"source port: %s, source channel: %s", sourcePort, sourceChannel,
86109
)
@@ -90,7 +113,7 @@ func (k Keeper) SendTransfer(
90113
// See spec for this logic: https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#packet-relay
91114
channelCap, ok := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(sourcePort, sourceChannel))
92115
if !ok {
93-
return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability")
116+
return 0, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability")
94117
}
95118

96119
// NOTE: denomination and hex hash correctness checked during msg.ValidateBasic
@@ -103,7 +126,7 @@ func (k Keeper) SendTransfer(
103126
if strings.HasPrefix(token.Denom, "ibc/") {
104127
fullDenomPath, err = k.DenomPathFromHash(ctx, token.Denom)
105128
if err != nil {
106-
return err
129+
return 0, err
107130
}
108131
}
109132

@@ -126,7 +149,7 @@ func (k Keeper) SendTransfer(
126149
if err := k.bankKeeper.SendCoins(
127150
ctx, sender, escrowAddress, sdk.NewCoins(token),
128151
); err != nil {
129-
return err
152+
return 0, err
130153
}
131154

132155
} else {
@@ -136,7 +159,7 @@ func (k Keeper) SendTransfer(
136159
if err := k.bankKeeper.SendCoinsFromAccountToModule(
137160
ctx, sender, types.ModuleName, sdk.NewCoins(token),
138161
); err != nil {
139-
return err
162+
return 0, err
140163
}
141164

142165
if err := k.bankKeeper.BurnCoins(
@@ -165,7 +188,7 @@ func (k Keeper) SendTransfer(
165188
)
166189

167190
if err := k.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil {
168-
return err
191+
return 0, err
169192
}
170193

171194
defer func() {
@@ -184,7 +207,7 @@ func (k Keeper) SendTransfer(
184207
)
185208
}()
186209

187-
return nil
210+
return sequence, nil
188211
}
189212

190213
// OnRecvPacket processes a cross chain fungible token transfer. If the

modules/apps/transfer/types/tx.pb.go

Lines changed: 68 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/ibc/applications/transfer/v1/tx.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ message MsgTransfer {
4141
}
4242

4343
// MsgTransferResponse defines the Msg/Transfer response type.
44-
message MsgTransferResponse {}
44+
message MsgTransferResponse {
45+
// sequence number of the transfer packet sent
46+
uint64 sequence = 1;
47+
}

0 commit comments

Comments
 (0)