Skip to content

Commit

Permalink
store refund address in IdentifiedPacketFee (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal authored Nov 18, 2021
1 parent 405f193 commit 8ebbe18
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 236 deletions.
76 changes: 7 additions & 69 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ CLOSED, INIT, TRYOPEN, OPEN or UNINITIALIZED.
<a name="ibc.applications.fee.v1.Fee"></a>

### Fee
Fee interface
Fee implements the ics29 Fee interface
See Fee Payment Middleware spec:
https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middleware-contract

Expand All @@ -636,13 +636,17 @@ https://github.com/cosmos/ibc/tree/master/spec/app/ics-029-fee-payment#fee-middl
<a name="ibc.applications.fee.v1.IdentifiedPacketFee"></a>

### IdentifiedPacketFee
Fee associated with a packet_id
IdentifiedPacketFee contains the relayer fee along with the associated metadata needed to process it.
This includes the PacketId identifying the packet the fee is paying for,
the refund address to which any unused funds are refunded,
and an optional list of relayers that are permitted to receive the fee.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `packet_id` | [ibc.core.channel.v1.PacketId](#ibc.core.channel.v1.PacketId) | | |
| `fee` | [Fee](#ibc.applications.fee.v1.Fee) | | |
| `refund_address` | [string](#string) | | |
| `relayers` | [string](#string) | repeated | |


Expand Down Expand Up @@ -781,71 +785,6 @@ Query provides defines the gRPC querier service.



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

### MsgPayPacketFee
MsgPayPacketFee defines the request type EscrowPacketFee RPC
This Msg can be used to pay for a packet at the next sequence send & should be combined with the Msg that will be
paid for


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `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.MsgPayPacketFeeAsync"></a>

### MsgPayPacketFeeAsync
MsgPayPacketFeeAsync defines the request type PayPacketFeeAsync RPC
This Msg can be used to pay for a packet at a specified sequence (instead of the next sequence send)


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






<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.MsgPayPacketFee"></a>

### MsgPayPacketFee
Expand Down Expand Up @@ -876,8 +815,7 @@ This Msg can be used to pay for a packet at a specified sequence (instead of the

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `identified_packet_fee` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | packet to pay fee for |
| `signer` | [string](#string) | | account address to refund fee if necessary |
| `identified_packet_fee` | [IdentifiedPacketFee](#ibc.applications.fee.v1.IdentifiedPacketFee) | | identified packet to pay fee for identified fee must contain the refund address which is also signer of this message |



Expand Down
6 changes: 5 additions & 1 deletion modules/apps/29-fee/keeper/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import (
)

// 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 {
func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee *types.IdentifiedPacketFee) error {
// check if the refund account exists
refundAcc, err := sdk.AccAddressFromBech32(identifiedFee.RefundAddress)
if err != nil {
return err
}
hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc)
if hasRefundAcc == nil {
return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc))
Expand Down
12 changes: 6 additions & 6 deletions modules/apps/29-fee/keeper/escrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() {

tc.malleate()
fee := types.Fee{ackFee, receiveFee, timeoutFee}
identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}}
identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}

// refundAcc balance before escrow
originalBal := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom)

// escrow the packet fee
err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee)
err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee)

if tc.expPass {
feeInEscrow, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId)
Expand Down Expand Up @@ -153,9 +153,9 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
fee := types.Fee{receiveFee, ackFee, timeoutFee}

// escrow the packet fee & store the fee in state
identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}}
identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}

err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, &identifiedPacketFee)
err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), &identifiedPacketFee)
suite.Require().NoError(err)

tc.malleate()
Expand Down Expand Up @@ -244,8 +244,8 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() {
fee := types.Fee{receiveFee, ackFee, timeoutFee}

// escrow the packet fee & store the fee in state
identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}}
err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, &identifiedPacketFee)
identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}
err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), &identifiedPacketFee)
suite.Require().NoError(err)

tc.malleate()
Expand Down
14 changes: 8 additions & 6 deletions modules/apps/29-fee/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() {
ReceiveFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))),
TimeoutFee: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))),
},
"", // leave empty here and then populate on each testcase since suite resets
[]string(nil),
)

Expand Down Expand Up @@ -61,10 +62,12 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacket() {
suite.SetupTest() // reset

refundAcc := suite.chainA.SenderAccount.GetAddress()
// populate RefundAddress field
identifiedPacketFee.RefundAddress = refundAcc.String()

tc.malleate()
ctx := sdk.WrapSDKContext(suite.chainA.GetContext())
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, identifiedPacketFee)
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee)
res, err := suite.queryClient.IncentivizedPacket(ctx, req)

if tc.expPass {
Expand Down Expand Up @@ -107,15 +110,15 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() {
func() {
refundAcc := suite.chainA.SenderAccount.GetAddress()

fee1 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 1), fee, []string(nil))
fee2 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 2), fee, []string(nil))
fee3 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 3), fee, []string(nil))
fee1 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 1), fee, refundAcc.String(), []string(nil))
fee2 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 2), fee, refundAcc.String(), []string(nil))
fee3 := types.NewIdentifiedPacketFee(types.NewPacketId(ibctesting.FirstChannelID, 3), fee, refundAcc.String(), []string(nil))

expPackets = []*types.IdentifiedPacketFee{}
expPackets = append(expPackets, fee1, fee2, fee3)

for _, p := range expPackets {
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), refundAcc, p)
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), p)
}

req = &types.QueryIncentivizedPacketsRequest{
Expand All @@ -141,7 +144,6 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() {
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
fmt.Println(expPackets)
suite.Require().Equal(expPackets, res.IncentivizedPackets)
} else {
suite.Require().Error(err)
Expand Down
16 changes: 3 additions & 13 deletions modules/apps/29-fee/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee)
Sequence: sequence,
}

refundAccAddr, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
}

identifiedPacket := types.NewIdentifiedPacketFee(packetId, msg.Fee, msg.Relayers)
err = k.EscrowPacketFee(ctx, refundAccAddr, identifiedPacket)
identifiedPacket := types.NewIdentifiedPacketFee(packetId, msg.Fee, msg.Signer, msg.Relayers)
err := k.EscrowPacketFee(ctx, identifiedPacket)
if err != nil {
return nil, err
}
Expand All @@ -63,12 +58,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee)
func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacketFeeAsync) (*types.MsgPayPacketFeeAsyncResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

refundAccAddr, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return nil, err
}

err = k.EscrowPacketFee(ctx, refundAccAddr, &msg.IdentifiedPacketFee)
err := k.EscrowPacketFee(ctx, &msg.IdentifiedPacketFee)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() {

// build fee
packetId := &channeltypes.PacketId{ChannelId: channelID, PortId: suite.path.EndpointA.ChannelConfig.PortID, Sequence: seq}
identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, Relayers: []string{}}
identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}

tc.malleate()

msg := types.NewMsgPayPacketFeeAsync(identifiedPacketFee, refundAcc.String())
msg := types.NewMsgPayPacketFeeAsync(identifiedPacketFee)
_, err = suite.chainA.SendMsgs(msg)

if tc.expPass {
Expand Down
Loading

0 comments on commit 8ebbe18

Please sign in to comment.