From 7a0171f0189454834dc6655e5f5f06b58b23088e Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 18 Sep 2023 16:14:31 +0100 Subject: [PATCH 1/4] feat(packet): get next send sequence for transfer packets --- modules/core/04-channel/keeper/grpc_query.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 171c88d435f..c907246f17b 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -555,7 +555,7 @@ 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, @@ -563,17 +563,13 @@ func (k Keeper) NextSequenceSend(c context.Context, req *types.QueryNextSequence ) } - // 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 From 3645587e6b18cde8f6809718d9ec1787ec3c1982 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 18 Sep 2023 20:23:46 +0100 Subject: [PATCH 2/4] chore(channels): fixed tests for unordered sequence --- modules/core/04-channel/keeper/grpc_query_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/core/04-channel/keeper/grpc_query_test.go b/modules/core/04-channel/keeper/grpc_query_test.go index 725b6d1655a..6b5f059bc32 100644 --- a/modules/core/04-channel/keeper/grpc_query_test.go +++ b/modules/core/04-channel/keeper/grpc_query_test.go @@ -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(expSeq) + 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, From 9996c7df542fe9c08eba137a5742fdbf3ea11b78 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 19 Sep 2023 08:07:13 +0100 Subject: [PATCH 3/4] Update modules/core/04-channel/keeper/grpc_query_test.go Co-authored-by: Carlos Rodriguez --- modules/core/04-channel/keeper/grpc_query_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/04-channel/keeper/grpc_query_test.go b/modules/core/04-channel/keeper/grpc_query_test.go index 6b5f059bc32..00937161d97 100644 --- a/modules/core/04-channel/keeper/grpc_query_test.go +++ b/modules/core/04-channel/keeper/grpc_query_test.go @@ -1626,7 +1626,7 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { suite.coordinator.Setup(path) expSeq = 42 - seq := uint64(expSeq) + 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, From 50e3edcc20acae06a5a727fd2d9ac2e9660bb774 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 19 Sep 2023 10:12:06 +0100 Subject: [PATCH 4/4] chore: removed useless error handling --- modules/core/04-channel/keeper/grpc_query.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index c907246f17b..1802b2f4a1e 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -555,16 +555,7 @@ func (k Keeper) NextSequenceSend(c context.Context, req *types.QueryNextSequence ctx := sdk.UnwrapSDKContext(c) - _, 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(), - ) - } - - var sequence uint64 - sequence, found = k.GetNextSequenceSend(ctx, req.PortId, req.ChannelId) + sequence, found := k.GetNextSequenceSend(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound,