Skip to content

Commit

Permalink
feat: grpc query total timeout fees (#1033)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
damiannolan authored Mar 2, 2022
1 parent 8d380ba commit 9137084
Show file tree
Hide file tree
Showing 6 changed files with 755 additions and 50 deletions.
33 changes: 33 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
- [QueryTotalAckFeesResponse](#ibc.applications.fee.v1.QueryTotalAckFeesResponse)
- [QueryTotalRecvFeesRequest](#ibc.applications.fee.v1.QueryTotalRecvFeesRequest)
- [QueryTotalRecvFeesResponse](#ibc.applications.fee.v1.QueryTotalRecvFeesResponse)
- [QueryTotalTimeoutFeesRequest](#ibc.applications.fee.v1.QueryTotalTimeoutFeesRequest)
- [QueryTotalTimeoutFeesResponse](#ibc.applications.fee.v1.QueryTotalTimeoutFeesResponse)

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

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




<a name="ibc.applications.fee.v1.QueryTotalTimeoutFeesRequest"></a>

### QueryTotalTimeoutFeesRequest
QueryTotalTimeoutFeesRequest defines the request type for the TotalTimeoutFees rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | the packet identifier for the associated fees |






<a name="ibc.applications.fee.v1.QueryTotalTimeoutFeesResponse"></a>

### QueryTotalTimeoutFeesResponse
QueryTotalTimeoutFeesResponse defines the response type for the TotalTimeoutFees rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `timeout_fees` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | the total packet timeout fees |





<!-- end messages -->

<!-- end enums -->
Expand All @@ -1065,6 +1097,7 @@ Query provides defines the gRPC querier service.
| `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}|
| `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}|
| `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}|
| `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}|

<!-- end services -->

Expand Down
26 changes: 26 additions & 0 deletions modules/apps/29-fee/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,29 @@ func (k Keeper) TotalAckFees(goCtx context.Context, req *types.QueryTotalAckFees
AckFees: ackFees,
}, nil
}

// TotalTimeoutFees implements the Query/TotalTimeoutFees gRPC method
func (k Keeper) TotalTimeoutFees(goCtx context.Context, req *types.QueryTotalTimeoutFeesRequest) (*types.QueryTotalTimeoutFeesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

feesInEscrow, found := k.GetFeesInEscrow(ctx, req.PacketId)
if !found {
return nil, status.Errorf(
codes.NotFound,
sdkerrors.Wrapf(types.ErrFeeNotFound, "channel: %s, port: %s, sequence: %d", req.PacketId.ChannelId, req.PacketId.PortId, req.PacketId.Sequence).Error(),
)
}

var timeoutFees sdk.Coins
for _, packetFee := range feesInEscrow.PacketFees {
timeoutFees = timeoutFees.Add(packetFee.Fee.TimeoutFee...)
}

return &types.QueryTotalTimeoutFeesResponse{
TimeoutFees: timeoutFees,
}, nil
}
64 changes: 64 additions & 0 deletions modules/apps/29-fee/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,67 @@ func (suite *KeeperTestSuite) TestQueryTotalAckFees() {
})
}
}

func (suite *KeeperTestSuite) TestQueryTotalTimeoutFees() {
var (
req *types.QueryTotalTimeoutFeesRequest
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success",
func() {},
true,
},
{
"packet not found",
func() {
req.PacketId = channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 100)
},
false,
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), ibctesting.MockFeePort, ibctesting.FirstChannelID)

packetID := channeltypes.NewPacketId(ibctesting.FirstChannelID, ibctesting.MockFeePort, 1)

fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee)
packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), []string(nil))

for i := 0; i < 3; i++ {
// escrow three packet fees for the same packet
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee)
suite.Require().NoError(err)
}

req = &types.QueryTotalTimeoutFeesRequest{
PacketId: packetID,
}

tc.malleate()

ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
res, err := suite.queryClient.TotalTimeoutFees(ctx, req)

if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)

// expected total is three times the default acknowledgement fee
expectedFees := defaultTimeoutFee.Add(defaultTimeoutFee...).Add(defaultTimeoutFee...)
suite.Require().Equal(expectedFees, res.TimeoutFees)
} else {
suite.Require().Error(err)
}
})
}
}
Loading

0 comments on commit 9137084

Please sign in to comment.