Skip to content

Commit

Permalink
fix(query): get next send sequence for transfer packets (#4706)
Browse files Browse the repository at this point in the history
* feat(packet): get next send sequence for transfer packets

* chore(channels): fixed tests for unordered sequence

* Update modules/core/04-channel/keeper/grpc_query_test.go

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* chore: removed useless error handling

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
  • Loading branch information
dzmitry-lahoda and Carlos Rodriguez authored Sep 19, 2023
1 parent c66d1e2 commit cd25f88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
17 changes: 2 additions & 15 deletions modules/core/04-channel/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,26 +555,13 @@ func (k Keeper) NextSequenceSend(c context.Context, req *types.QueryNextSequence

ctx := sdk.UnwrapSDKContext(c)

channel, found := k.GetChannel(ctx, req.PortId, req.ChannelId)
sequence, found := k.GetNextSequenceSend(ctx, req.PortId, req.ChannelId)
if !found {
return nil, status.Error(
codes.NotFound,
errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(),
errorsmod.Wrapf(types.ErrSequenceSendNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(),
)
}

// Return the next sequence send for ordered channels. Unordered channels
// do not make use of the next sequence send.
var sequence uint64
if channel.Ordering != types.UNORDERED {
sequence, found = k.GetNextSequenceSend(ctx, req.PortId, req.ChannelId)
if !found {
return nil, status.Error(
codes.NotFound,
errorsmod.Wrapf(types.ErrSequenceSendNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(),
)
}
}
selfHeight := clienttypes.GetSelfHeight(ctx)
return types.NewQueryNextSequenceSendResponse(sequence, nil, selfHeight), nil
}
Expand Down
6 changes: 4 additions & 2 deletions modules/core/04-channel/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,12 +1620,14 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() {
false,
},
{
"basic success on unordered channel returns zero",
"basic success on unordered channel returns the set send sequence",
func() {
path := ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

expSeq = 0
expSeq = 42
seq := uint64(42)
suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, seq)
req = &types.QueryNextSequenceSendRequest{
PortId: path.EndpointA.ChannelConfig.PortID,
ChannelId: path.EndpointA.ChannelID,
Expand Down

0 comments on commit cd25f88

Please sign in to comment.