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

fee middleware: grpc queries #488

Merged
merged 55 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
435efc7
fix: adding second endpoint for async pay fee + renaming types
seantking Oct 1, 2021
8f2c51a
feat: adding escrow logic
seantking Oct 1, 2021
a410af6
feat: updating proto types & escrow logic
seantking Oct 4, 2021
0e6823f
fix: stub fn & proto comment
seantking Oct 5, 2021
f41e520
feat: adding PayFee & PayFeeTimeout & escrow_test
seantking Oct 6, 2021
e4bd49a
test: adding happy path for EscrowPacketFee
seantking Oct 6, 2021
ca7f4e2
fix: comments, error handling
seantking Oct 7, 2021
6a5add7
fix: comments & grammar
seantking Oct 7, 2021
952a3e3
grpc scaffold
charleenfei Oct 8, 2021
535e2c6
test: adding unhappy path for escrow
seantking Oct 8, 2021
5bd0e32
tests(escrow): adding hasBalance check for module acc
seantking Oct 8, 2021
31fcee3
test(PayFee): adding happy path for PayFee tests
seantking Oct 8, 2021
487f78d
tests(PayFee, PayFeeTimeout): adding tests
seantking Oct 8, 2021
f25932f
fix: adding relayers back to IdentifiedPacket
seantking Oct 11, 2021
90284c7
wip
charleenfei Oct 11, 2021
ea37edc
Merge branch 'sean/issue#-259-escrow-logic' of github.com:cosmos/ibc-…
charleenfei Oct 11, 2021
38566bc
fix: removing refund acc from key
seantking Oct 11, 2021
ceb49ca
Merge branch 'sean/issue#-259-escrow-logic' of github.com:cosmos/ibc-…
charleenfei Oct 11, 2021
dd0044b
fix: storing IdentifiedPacketFee in state instead of Fee
seantking Oct 11, 2021
526a13d
Merge branch 'sean/issue#-259-escrow-logic' of github.com:cosmos/ibc-…
charleenfei Oct 11, 2021
5b4a395
feat: adding msg_server test for registerCPAddr, wiring for codec + s…
seantking Oct 11, 2021
3c2dd24
Merge branch 'sean/issue#-259-escrow-logic' of github.com:cosmos/ibc-…
charleenfei Oct 11, 2021
c9af582
test: adding msg_server test for PayPacketFee
seantking Oct 12, 2021
980d748
Merge branch 'sean/issue#-259-escrow-logic' of github.com:cosmos/ibc-…
charleenfei Oct 12, 2021
d325146
test: adding PayPacketFeeAsync msg_server test
seantking Oct 12, 2021
b6ef099
Merge branch 'sean/issue#-259-escrow-logic' of github.com:cosmos/ibc-…
charleenfei Oct 12, 2021
ea9b30b
chore: updating PayFee -> DistributeFee & minor nits
seantking Oct 13, 2021
ac7584f
nit: removing unnecessary nil check
seantking Oct 13, 2021
5bd3382
update protos
charleenfei Oct 13, 2021
be4b865
Merge branch 'sean/issue#-259-escrow-logic' of github.com:cosmos/ibc-…
charleenfei Oct 13, 2021
ec2f0d4
query function
charleenfei Oct 13, 2021
46fe890
prefix & query heights
charleenfei Oct 13, 2021
c44a81c
refactor: add portId to store key & use packetId as param
seantking Oct 13, 2021
a8c3cff
fix: add DeleteFeeInEscrow & remove fee on successful distribution
seantking Oct 13, 2021
4f490ea
tests: adding validation & signer tests for PayFee/Async & updating p…
seantking Oct 13, 2021
f1fde1d
chore: adding NewIdentifiedPacketFee fn
seantking Oct 13, 2021
eeb4376
fix: getter/setter for counterparty address + fix NewIdentifiedPacketFee
seantking Oct 14, 2021
4612bf2
fix: updating EscrowPacketFee with correct usage of coins api
seantking Oct 14, 2021
3494a0f
test: adding balance check for refund acc after escrow
seantking Oct 14, 2021
f4c37e6
fix: remove unncessary errors
seantking Oct 14, 2021
f547a2c
Merge branch 'sean/issue#-259-escrow-logic' of github.com:cosmos/ibc-…
charleenfei Oct 14, 2021
b666224
wip
charleenfei Oct 15, 2021
96999c4
fix tests
charleenfei Oct 27, 2021
0b733ab
test: updating escrow tests + miscellaneous fixes
seantking Nov 3, 2021
2be4ab5
nit: updating var names
seantking Nov 3, 2021
cb2cbc3
docs: godoc
seantking Nov 3, 2021
66454c6
refactor: IdentifiedPacketFee & Fee no longer pointers
seantking Nov 3, 2021
06d4c25
fixes: small fixes
seantking Nov 3, 2021
8757f9a
fix merge conflict
charleenfei Nov 3, 2021
f7acaa4
Merge branch 'ics29-fee-middleware' into issue#479-grpc-query
charleenfei Nov 8, 2021
23c98ab
initial fix
charleenfei Nov 8, 2021
0864c55
interim fix
charleenfei Nov 8, 2021
8779ed7
merge conflict changes
charleenfei Nov 8, 2021
22b62b5
updates for nits
charleenfei Nov 8, 2021
fc4db7a
update for nits
charleenfei Nov 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 43 additions & 121 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,18 @@
- [GenesisState](#ibc.applications.fee.v1.GenesisState)

- [ibc/applications/fee/v1/query.proto](#ibc/applications/fee/v1/query.proto)
- [QueryAckFeeRequest](#ibc.applications.fee.v1.QueryAckFeeRequest)
- [QueryAckFeeResponse](#ibc.applications.fee.v1.QueryAckFeeResponse)
- [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest)
- [QueryIncentivizedPacketResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketResponse)
- [QueryIncentivizedPacketsRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketsRequest)
- [QueryIncentivizedPacketsResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketsResponse)
- [QueryReceiveFeeRequest](#ibc.applications.fee.v1.QueryReceiveFeeRequest)
- [QueryReceiveFeeResponse](#ibc.applications.fee.v1.QueryReceiveFeeResponse)
- [QueryTimeoutFeeRequest](#ibc.applications.fee.v1.QueryTimeoutFeeRequest)
- [QueryTimeoutFeeResponse](#ibc.applications.fee.v1.QueryTimeoutFeeResponse)

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

- [ibc/applications/fee/v1/tx.proto](#ibc/applications/fee/v1/tx.proto)
- [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee)
- [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse)
- [MsgPayPacketFee](#ibc.applications.fee.v1.MsgPayPacketFee)
- [MsgPayPacketFeeAsync](#ibc.applications.fee.v1.MsgPayPacketFeeAsync)
- [MsgPayPacketFeeAsyncResponse](#ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse)
- [MsgPayPacketFeeResponse](#ibc.applications.fee.v1.MsgPayPacketFeeResponse)
- [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress)
- [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse)

Expand Down Expand Up @@ -628,7 +624,9 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middl

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
| `receive_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
| `ack_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |
| `timeout_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | |



Expand All @@ -644,9 +642,7 @@ Fee associated with a packet_id
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | |
| `receive_fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |
| `ack_fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |
| `timeout_fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |
| `relayers` | [string](#string) | repeated | |


Expand Down Expand Up @@ -676,11 +672,6 @@ Fee associated with a packet_id
GenesisState defines the fee middleware genesis state


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packets_fees` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | repeated | A mapping of packets -> escrowed fees |





Expand All @@ -701,38 +692,6 @@ GenesisState defines the fee middleware genesis state



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

### QueryAckFeeRequest
QueryAckFeeRequest is the request type for querying the acknowledgement fee


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | PacketID |
| `relayer_address` | [string](#string) | | Caller should provide the intended relayer address in case the fee is dependent on specific relayer(s). |
| `query_height` | [uint64](#uint64) | | Height to query at |






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

### QueryAckFeeResponse
QueryAckFeeResponse is the response type for the AckFee RPC


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |






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

### QueryIncentivizedPacketRequest
Expand Down Expand Up @@ -794,121 +753,83 @@ QueryIncentivizedPacketsResponse is the response type for the incentivized packe



<!-- end messages -->

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

### QueryReceiveFeeRequest
QueryReceiveFeeRequest is the request type for querying the receive fee


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | PacketID |
| `relayer_address` | [string](#string) | | Caller should provide the intended relayer address in case the fee is dependent on specific relayer(s). |
| `query_height` | [uint64](#uint64) | | Height to query at |


<!-- end enums -->

<!-- end HasExtensions -->


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

<a name="ibc.applications.fee.v1.QueryReceiveFeeResponse"></a>
### Query
Query provides defines the gRPC querier service.

### QueryReceiveFeeResponse
QueryReceiveFeeResponse is the response type for the ReceiveFee RPC
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `IncentivizedPackets` | [QueryIncentivizedPacketsRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketsRequest) | [QueryIncentivizedPacketsResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketsResponse) | Gets all incentivized packets | GET|/ibc/apps/fee/v1/incentivized_packets|
| `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}|

<!-- end services -->

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |


<a name="ibc/applications/fee/v1/tx.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## ibc/applications/fee/v1/tx.proto



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

### QueryTimeoutFeeRequest
QueryTimeoutFeeRequest is the request type for querying the timeout fee
### MsgPayPacketFee
MsgPayPacketFee defines the request type EscrowPacketFee RPC


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | PacketID |
| `relayer_address` | [string](#string) | | Caller should provide the intended relayer address in case the fee is dependent on specific relayer(s). |
| `query_height` | [uint64](#uint64) | | Height to query at |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |
| `source_port_id` | [string](#string) | | source channel port identifier |
| `source_channel_id` | [string](#string) | | source channel unique identifier |
| `signer` | [string](#string) | | account address to refund fee if necessary |
| `relayers` | [string](#string) | repeated | |






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

### QueryTimeoutFeeResponse
QueryTimeoutFeeResponse is the response type for the timeout RPC
### MsgPayPacketFeeAsync
MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |

| `identified_packet_fee` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | packet to pay fee for |
| `signer` | [string](#string) | | account address to refund fee if necessary |




<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->
<a name="ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse"></a>


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

### Query
Query provides defines the gRPC querier service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `ReceiveFee` | [QueryReceiveFeeRequest](#ibc.applications.fee.v1.QueryReceiveFeeRequest) | [QueryReceiveFeeResponse](#ibc.applications.fee.v1.QueryReceiveFeeResponse) | Gets the fee expected for submitting ReceivePacket msg for the given packet | GET|/ibc/apps/fee/v1/receive_fee/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
| `AckFee` | [QueryAckFeeRequest](#ibc.applications.fee.v1.QueryAckFeeRequest) | [QueryAckFeeResponse](#ibc.applications.fee.v1.QueryAckFeeResponse) | Gets the fee expected for submitting AcknowledgePacket msg for the given packet | GET|/ibc/apps/fee/v1/ack_fee/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
| `TimeoutFee` | [QueryTimeoutFeeRequest](#ibc.applications.fee.v1.QueryTimeoutFeeRequest) | [QueryTimeoutFeeResponse](#ibc.applications.fee.v1.QueryTimeoutFeeResponse) | Gets the fee expected for submitting TimeoutPacket msg for the given packet | GET|/ibc/apps/fee/v1/timeout_fee/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|
| `IncentivizedPackets` | [QueryIncentivizedPacketsRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketsRequest) | [QueryIncentivizedPacketsResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketsResponse) | Gets all incentivized packets | GET|/ibc/apps/fee/v1/incentivized_packets|
| `IncentivizedPacket` | [QueryIncentivizedPacketRequest](#ibc.applications.fee.v1.QueryIncentivizedPacketRequest) | [QueryIncentivizedPacketResponse](#ibc.applications.fee.v1.QueryIncentivizedPacketResponse) | Gets the specified incentivized packet | GET|/ibc/apps/fee/v1/incentivized_packet/port/{packet_id.port_id}/channel/{packet_id.channel_id}/sequence/{packet_id.sequence}|

<!-- end services -->



<a name="ibc/applications/fee/v1/tx.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## ibc/applications/fee/v1/tx.proto



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

### MsgEscrowPacketFee
MsgEscrowPacketFee defines the request type EscrowPacketFee RPC


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `incentivized_packet` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | |
| `relayers` | [string](#string) | repeated | |
### MsgPayPacketFeeAsyncResponse
MsgPayPacketFeeAsyncResponse defines the response type for Msg/PayPacketFeeAsync






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

### MsgEscrowPacketFeeResponse
MsgEscrowPacketFeeResponse defines the response type for Msg/EscrowPacketFee
### MsgPayPacketFeeResponse
MsgPayPacketFeeResponse defines the response type for Msg/PayPacketFee



Expand Down Expand Up @@ -955,7 +876,8 @@ Msg defines the ibc/fee Msg service.
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `RegisterCounterpartyAddress` | [MsgRegisterCounterpartyAddress](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddress) | [MsgRegisterCounterpartyAddressResponse](#ibc.applications.fee.v1.MsgRegisterCounterpartyAddressResponse) | RegisterCounterpartyAddress defines a rpc handler method for MsgRegisterCounterpartyAddress RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying. This ensures they will be properly compensated for forward relaying since destination chain must send back relayer's source address (counterparty address) in acknowledgement. This function may be called more than once by a relayer, in which case, latest counterparty address is always used. | |
| `EscrowPacketFee` | [MsgEscrowPacketFee](#ibc.applications.fee.v1.MsgEscrowPacketFee) | [MsgEscrowPacketFeeResponse](#ibc.applications.fee.v1.MsgEscrowPacketFeeResponse) | EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to incentivize the relaying of the given packet. | |
| `PayPacketFee` | [MsgPayPacketFee](#ibc.applications.fee.v1.MsgPayPacketFee) | [MsgPayPacketFeeResponse](#ibc.applications.fee.v1.MsgPayPacketFeeResponse) | PayPacketFee defines a rpc handler method for MsgPayPacketFee PayPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to incentivize the relaying of the packet at the next sequence | |
| `PayPacketFeeAsync` | [MsgPayPacketFeeAsync](#ibc.applications.fee.v1.MsgPayPacketFeeAsync) | [MsgPayPacketFeeAsyncResponse](#ibc.applications.fee.v1.MsgPayPacketFeeAsyncResponse) | PayPacketFeeAsync defines a rpc handler method for MsgPayPacketFeeAsync PayPacketFeeAsync is an open callback that may be called by any module/user that wishes to escrow funds in order to incentivize the relaying of a known packet | |

<!-- end services -->

Expand Down
106 changes: 106 additions & 0 deletions modules/apps/29-fee/keeper/escrow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package keeper

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/cosmos/ibc-go/modules/apps/29-fee/types"
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
)

// EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow
func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, identifiedFee *types.IdentifiedPacketFee) error {
// check if the refund account exists
hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc)
if hasRefundAcc == nil {
return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc.String()))
}

coins := identifiedFee.Fee.AckFee
coins = coins.Add(identifiedFee.Fee.ReceiveFee...)
coins = coins.Add(identifiedFee.Fee.TimeoutFee...)

if err := k.bankKeeper.SendCoinsFromAccountToModule(
ctx, refundAcc, types.ModuleName, coins,
); err != nil {
return err
}

// Store fee in state for reference later
// feeInEscrow/<port-id>/<channel-id>/packet/<sequence-id>/ -> Fee (timeout, ack, onrecv)
k.SetFeeInEscrow(ctx, identifiedFee)
return nil
}

// DistributeFee pays the acknowledgement fee & receive fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee
func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error {
// check if there is a Fee in escrow for the given packetId
feeInEscrow, found := k.GetFeeInEscrow(ctx, packetID)
if !found {
return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String()))
}

// get module accAddr
feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName)

// send ack fee to reverse relayer
err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.AckFee)
if err != nil {
return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to reverse relayer"))
}

// send receive fee to forward relayer
err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, feeInEscrow.Fee.ReceiveFee)
if err != nil {
return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to forward relayer"))
}

// refund timeout fee to refundAddr
err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.TimeoutFee)
if err != nil {
return sdkerrors.Wrap(err, fmt.Sprintf("error refunding timeout fee"))
}

// removes the fee from the store as fee is now paid
k.DeleteFeeInEscrow(ctx, packetID)

return nil
}

// DistributeFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee
func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error {
// check if there is a Fee in escrow for the given packetId
feeInEscrow, hasFee := k.GetFeeInEscrow(ctx, packetID)
if !hasFee {
return sdkerrors.Wrap(types.ErrFeeNotFound, fmt.Sprintf("%s", refundAcc.String()))
}

// get module accAddr
feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName)

// refund the ack fee
err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.AckFee)
if err != nil {
return sdkerrors.Wrap(err, fmt.Sprintf("error refunding ack fee"))
}

// refund the receive fee
err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.ReceiveFee)
if err != nil {
return sdkerrors.Wrap(err, fmt.Sprintf("error refunding receive fee"))
}

// pay the timeout fee to the reverse relayer
err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.TimeoutFee)
if err != nil {
return sdkerrors.Wrap(err, fmt.Sprintf("error sending fee to timeout relayer"))
}

// removes the fee from the store as fee is now paid
k.DeleteFeeInEscrow(ctx, packetID)

return nil
}
Loading