Skip to content

Commit 9137084

Browse files
authored
feat: grpc query total timeout fees (#1033)
* adding query for total packet recv fees to proto query server * adding total packet recv fee query impl and tests * updating doc comments * adding protos and codegen * adding total ack fees query and tests * adding protos and codegen * adding query total timeout fees and tests * fixing protodoc comment * fixing protodoc comment
1 parent 8d380ba commit 9137084

File tree

6 files changed

+755
-50
lines changed

6 files changed

+755
-50
lines changed

docs/ibc/proto-docs.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
- [QueryTotalAckFeesResponse](#ibc.applications.fee.v1.QueryTotalAckFeesResponse)
5454
- [QueryTotalRecvFeesRequest](#ibc.applications.fee.v1.QueryTotalRecvFeesRequest)
5555
- [QueryTotalRecvFeesResponse](#ibc.applications.fee.v1.QueryTotalRecvFeesResponse)
56+
- [QueryTotalTimeoutFeesRequest](#ibc.applications.fee.v1.QueryTotalTimeoutFeesRequest)
57+
- [QueryTotalTimeoutFeesResponse](#ibc.applications.fee.v1.QueryTotalTimeoutFeesResponse)
5658

5759
- [Query](#ibc.applications.fee.v1.Query)
5860

@@ -1047,6 +1049,36 @@ QueryTotalRecvFeesResponse defines the response type for the TotalRecvFees rpc
10471049

10481050

10491051

1052+
1053+
<a name="ibc.applications.fee.v1.QueryTotalTimeoutFeesRequest"></a>
1054+
1055+
### QueryTotalTimeoutFeesRequest
1056+
QueryTotalTimeoutFeesRequest defines the request type for the TotalTimeoutFees rpc
1057+
1058+
1059+
| Field | Type | Label | Description |
1060+
| ----- | ---- | ----- | ----------- |
1061+
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | the packet identifier for the associated fees |
1062+
1063+
1064+
1065+
1066+
1067+
1068+
<a name="ibc.applications.fee.v1.QueryTotalTimeoutFeesResponse"></a>
1069+
1070+
### QueryTotalTimeoutFeesResponse
1071+
QueryTotalTimeoutFeesResponse defines the response type for the TotalTimeoutFees rpc
1072+
1073+
1074+
| Field | Type | Label | Description |
1075+
| ----- | ---- | ----- | ----------- |
1076+
| `timeout_fees` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | the total packet timeout fees |
1077+
1078+
1079+
1080+
1081+
10501082
<!-- end messages -->
10511083

10521084
<!-- end enums -->
@@ -1065,6 +1097,7 @@ Query provides defines the gRPC querier service.
10651097
| `IncentivizedPacket` | [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest) | [QueryIncentivizedPacketResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketResponse) | Gets the fees expected for submitting the ReceivePacket, AcknowledgementPacket, and TimeoutPacket messages for the given packet | GET|/ibc/apps/fee/v1/incentivized_packet/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
10661098
| `TotalRecvFees` | [QueryTotalRecvFeesRequest](#ibc.applications.fee.v1.QueryTotalRecvFeesRequest) | [QueryTotalRecvFeesResponse](#ibc.applications.fee.v1.QueryTotalRecvFeesResponse) | TotalRecvFees returns the total receive fees for a packet given its identifier | GET|/ibc/apps/fee/v1/total_recv_fees/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
10671099
| `TotalAckFees` | [QueryTotalAckFeesRequest](#ibc.applications.fee.v1.QueryTotalAckFeesRequest) | [QueryTotalAckFeesResponse](#ibc.applications.fee.v1.QueryTotalAckFeesResponse) | TotalAckFees returns the total acknowledgement fees for a packet given its identifier | GET|/ibc/apps/fee/v1/total_ack_fees/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
1100+
| `TotalTimeoutFees` | [QueryTotalTimeoutFeesRequest](#ibc.applications.fee.v1.QueryTotalTimeoutFeesRequest) | [QueryTotalTimeoutFeesResponse](#ibc.applications.fee.v1.QueryTotalTimeoutFeesResponse) | TotalTimeoutFees returns the total timeout fees for a packet given its identifier | GET|/ibc/apps/fee/v1/total_timeout_fees/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
10681101

10691102
<!-- end services -->
10701103

modules/apps/29-fee/keeper/grpc_query.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,29 @@ func (k Keeper) TotalAckFees(goCtx context.Context, req *types.QueryTotalAckFees
117117
AckFees: ackFees,
118118
}, nil
119119
}
120+
121+
// TotalTimeoutFees implements the Query/TotalTimeoutFees gRPC method
122+
func (k Keeper) TotalTimeoutFees(goCtx context.Context, req *types.QueryTotalTimeoutFeesRequest) (*types.QueryTotalTimeoutFeesResponse, error) {
123+
if req == nil {
124+
return nil, status.Error(codes.InvalidArgument, "empty request")
125+
}
126+
127+
ctx := sdk.UnwrapSDKContext(goCtx)
128+
129+
feesInEscrow, found := k.GetFeesInEscrow(ctx, req.PacketId)
130+
if !found {
131+
return nil, status.Errorf(
132+
codes.NotFound,
133+
sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(),
134+
)
135+
}
136+
137+
var timeoutFees sdk.Coins
138+
for _, packetFee := range feesInEscrow.PacketFees {
139+
timeoutFees = timeoutFees.Add(packetFee.Fee.TimeoutFee...)
140+
}
141+
142+
return &types.QueryTotalTimeoutFeesResponse{
143+
TimeoutFees: timeoutFees,
144+
}, nil
145+
}

modules/apps/29-fee/keeper/grpc_query_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,67 @@ func (suite *KeeperTestSuite) TestQueryTotalAckFees() {
267267
})
268268
}
269269
}
270+
271+
func (suite *KeeperTestSuite) TestQueryTotalTimeoutFees() {
272+
var (
273+
req *types.QueryTotalTimeoutFeesRequest
274+
)
275+
276+
testCases := []struct {
277+
name string
278+
malleate func()
279+
expPass bool
280+
}{
281+
{
282+
"success",
283+
func() {},
284+
true,
285+
},
286+
{
287+
"packet not found",
288+
func() {
289+
req.PacketId = channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 100)
290+
},
291+
false,
292+
},
293+
}
294+
295+
for _, tc := range testCases {
296+
suite.Run(tc.name, func() {
297+
suite.SetupTest() // reset
298+
299+
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID)
300+
301+
packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1)
302+
303+
fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee)
304+
packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil))
305+
306+
for i := 0; i < 3; i++ {
307+
// escrow three packet fees for the same packet
308+
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee)
309+
suite.Require().NoError(err)
310+
}
311+
312+
req = &types.QueryTotalTimeoutFeesRequest{
313+
PacketId: packetID,
314+
}
315+
316+
tc.malleate()
317+
318+
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
319+
res, err := suite.queryClient.TotalTimeoutFees(ctx, req)
320+
321+
if tc.expPass {
322+
suite.Require().NoError(err)
323+
suite.Require().NotNil(res)
324+
325+
// expected total is three times the default acknowledgement fee
326+
expectedFees := defaultTimeoutFee.Add(defaultTimeoutFee...).Add(defaultTimeoutFee...)
327+
suite.Require().Equal(expectedFees, res.TimeoutFees)
328+
} else {
329+
suite.Require().Error(err)
330+
}
331+
})
332+
}
333+
}

0 commit comments

Comments
 (0)