-
Notifications
You must be signed in to change notification settings - Fork 645
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
Skip distribution if refund fails to send on channel closure #1523
Changes from 7 commits
971c40a
85aba61
33606ee
7453287
a640f3c
7ba892d
59a42df
ea6033f
27daca3
c37dffc
cf024b7
5774011
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,7 @@ func (k Keeper) RefundFeesOnChannelClosure(ctx sdk.Context, portID, channelID st | |
cacheCtx, writeFn := ctx.CacheContext() | ||
|
||
for _, identifiedPacketFee := range identifiedPacketFees { | ||
var failedToSendCoins bool | ||
for _, packetFee := range identifiedPacketFee.PacketFees { | ||
|
||
if !k.EscrowAccountHasBalance(cacheCtx, packetFee.Fee.Total()) { | ||
|
@@ -214,21 +215,16 @@ func (k Keeper) RefundFeesOnChannelClosure(ctx sdk.Context, portID, channelID st | |
return err | ||
} | ||
|
||
// if the refund address is blocked, skip and continue distribution | ||
if k.bankKeeper.BlockedAddr(refundAddr) { | ||
continue | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this blocked check happens in |
||
|
||
// refund all fees to refund address | ||
// Use SendCoins rather than the module account send functions since refund address may be a user account or module address. | ||
moduleAcc := k.GetFeeModuleAddress() | ||
if err = k.bankKeeper.SendCoins(cacheCtx, moduleAcc, refundAddr, packetFee.Fee.Total()); err != nil { | ||
return err | ||
if err = k.bankKeeper.SendCoinsFromModuleToAccount(cacheCtx, types.ModuleName, refundAddr, packetFee.Fee.Total()); err != nil { | ||
failedToSendCoins = true | ||
continue | ||
} | ||
|
||
} | ||
|
||
k.DeleteFeesInEscrow(cacheCtx, identifiedPacketFee.PacketId) | ||
if !failedToSendCoins { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's possible an error occurred sending the coins, we don't want to remove them unless they were actually sent. |
||
k.DeleteFeesInEscrow(cacheCtx, identifiedPacketFee.PacketId) | ||
} | ||
} | ||
|
||
// NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,10 @@ package keeper_test | |
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
|
||
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" | ||
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" | ||
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
Comment on lines
-5
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: group imports by type, see #382 import (
// standard library imports
"fmt"
"testing"
// external library imports
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
// ibc-go library imports
"github.com/cosmos/ibc-go/modules/core/23-commitment/types"
) |
||
) | ||
|
||
func (suite *KeeperTestSuite) TestDistributeFee() { | ||
|
@@ -277,12 +276,13 @@ func (suite *KeeperTestSuite) TestDistributePacketFeesOnTimeout() { | |
|
||
func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() { | ||
var ( | ||
expIdentifiedPacketFees []types.IdentifiedPacketFees | ||
expEscrowBal sdk.Coins | ||
expRefundBal sdk.Coins | ||
refundAcc sdk.AccAddress | ||
fee types.Fee | ||
locked bool | ||
expIdentifiedPacketFees []types.IdentifiedPacketFees | ||
expEscrowBal sdk.Coins | ||
expRefundBal sdk.Coins | ||
refundAcc sdk.AccAddress | ||
fee types.Fee | ||
locked bool | ||
expectEscrowFeesToBeDeleted bool | ||
) | ||
|
||
testCases := []struct { | ||
|
@@ -389,6 +389,7 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() { | |
}, | ||
{ | ||
"distributing to blocked address is skipped", func() { | ||
expectEscrowFeesToBeDeleted = false | ||
blockedAddr := suite.chainA.GetSimApp().AccountKeeper.GetModuleAccount(suite.chainA.GetContext(), transfertypes.ModuleName).GetAddress().String() | ||
|
||
// store the fee in state & update escrow account balance | ||
|
@@ -418,6 +419,7 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() { | |
expIdentifiedPacketFees = []types.IdentifiedPacketFees{} | ||
expEscrowBal = sdk.Coins{} | ||
locked = false | ||
expectEscrowFeesToBeDeleted = true | ||
|
||
// setup | ||
refundAcc = suite.chainA.SenderAccount.GetAddress() | ||
|
@@ -464,8 +466,8 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() { | |
suite.Require().Equal(expEscrowBal, escrowBal) // escrow balance should be empty | ||
suite.Require().Equal(expRefundBal, refundBal) // all packets should have been refunded | ||
|
||
// all fees in escrow should be deleted for this channel | ||
suite.Require().Empty(suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)) | ||
// all fees in escrow should be deleted if expected for this channel | ||
suite.Require().Equal(expectEscrowFeesToBeDeleted, len(suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)) == 0) | ||
} | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this error also still needs to be handled so improperly formatted refund addr doesnt stop channel closure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah that's a good point, it's effectively the same situation. Nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤝