Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query): get next send sequence for transfer packets #4706

Merged
merged 9 commits into from
Sep 19, 2023
18 changes: 7 additions & 11 deletions modules/core/04-channel/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,25 +555,21 @@ func (k Keeper) NextSequenceSend(c context.Context, req *types.QueryNextSequence

ctx := sdk.UnwrapSDKContext(c)

channel, found := k.GetChannel(ctx, req.PortId, req.ChannelId)
_, found := k.GetChannel(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(),
)
}
dzmitry-lahoda marked this conversation as resolved.
Show resolved Hide resolved

// 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(),
)
}
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
dzmitry-lahoda marked this conversation as resolved.
Show resolved Hide resolved
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
Loading