-
Notifications
You must be signed in to change notification settings - Fork 588
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
ics29: gracefully handle escrow out of balance edge case during fee distribution #1251
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1251 +/- ##
==========================================
+ Coverage 80.17% 80.23% +0.06%
==========================================
Files 166 166
Lines 11942 11979 +37
==========================================
+ Hits 9574 9611 +37
Misses 1911 1911
Partials 457 457
|
modules/apps/29-fee/keeper/escrow.go
Outdated
@@ -50,50 +50,76 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId, | |||
} | |||
|
|||
// DistributePacketFees 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) DistributePacketFees(ctx sdk.Context, forwardRelayer string, reverseRelayer sdk.AccAddress, feesInEscrow []types.PacketFee) { | |||
func (k Keeper) DistributePacketFees(ctx sdk.Context, forwardRelayer string, reverseRelayer sdk.AccAddress, packetFees []types.PacketFee, isTimeout bool) { |
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.
The refactor here is great, I think in some ways splitting up the timeout and ack logic as you have is an improvement. I can't help but feel like I'd prefer to have two separate functions though rather than passing a boolean. I feel like the fact that we're adding a boolean here could be a sign this fn has too much responsibility.
I think I would probably prefer keeping two separate functions like DistributeAcknowledgementPacketFees
& DistributeTimeoutPacketFees
.
I'm pretty open to either way though :)
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.
Yeah, I agree. I think it might be worth exploring the option of two separate functions in favour of the boolean arg, considering that the forward relayer is always an empty string for timeout scenarios also.
I do appreciate that it would be a decent bit of duplicate code nonetheless, but I would lean towards having explicit APIs for each scenario (happy path/timeout)
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.
My main concern is the sensitivity of performing the cacheCtx. It can be hard to verify that we pass in cacheCtx
and ctx
in the correct functions. Doing this redundantly in two separate functions seems like a recipe for one of the functions to get out of sync with the other and potentially lead to a bug.
The actual distribution of fees on acknowledgement and fees on timeout are still separated. The logic this function is performing is wrapping packet fee distribution with an escrow out of balance check. The previously functionality not only distributed the packet fees for either ack or timeout but also wrapped it with an escrow out of balance check.
For reference you can see how this file differed before splitting. I actually find it harder to verify the distributeAcknowledgementPacketFees
and distirbuteTimeoutPacketFees
functionality in comparison to the proposed way distributePacketFeeOnAcknowledgement
and distirbutePacketFeeOnTimeout
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 agree with @seantking and @damiannolan. I think having two separate functions will make the code more explicit and easier to read.
If that's not possible because of the concerns that @colin-axner has regarding the context, then a couple of other alternatives could be:
- To have an enum value instead of a boolean as parameter. Then at least reading the function at call site would look like
..., OnTimeout)
or..., OnAcknowledgement)
. - To pass the function that actually does the distribution instead of a boolean as parameter. So at call site you would have something like
..., distributePacketFeeOnAcknowledgement)
or..., distributePacketFeeOnTimeout)
. But then you need to have both functions with the same signature, which is possible to work around, but might not lead to the most beautiful result...
… into separate functions (#1253) ## Description Reduces the complexity contained in `DistributePacketFees` and `DistributePacketFeesOnAcknowledgement` in anticipation of #1251 closes: #XXXX --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing) - [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`) - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [ ] Re-reviewed `Files changed` in the Github PR explorer - [ ] Review `Codecov Report` in the comment section below once CI passes
|
||
tc.expResult() | ||
}) | ||
} | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestDistributeTimeoutFee() { | ||
suite.coordinator.Setup(suite.path) // setup channel | ||
func (suite *KeeperTestSuite) TestDistributePacketFeesOnTimeout() { |
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.
duplicated TestDistributePacketFeesOnAcknowledgement
and adjusted the tests
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.
Awesome work! Thanks for going to the trouble of exploring both approaches with this, much appreciated! While there's a bit of duplication with the code I think from an API perspective having no forwardRelayer
arg in the timeout scenario looks much cleaner imo.
❤️
@@ -15,7 +15,7 @@ import ( | |||
) | |||
|
|||
var ( | |||
defaultReceiveFee = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}} | |||
defaultRecvFee = sdk.Coins{sdk.Coin{Denom: sdk.DefaultBondDenom, Amount: sdk.NewInt(100)}} |
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.
Nice, prefer this too! :)
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.
Great work!
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Closes: cosmos#1249 Also, fixes `markdown-lint` CI checks. <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [ ] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords Co-authored-by: Ganesha Upadhyaya <ganeshrvce@gmail.com>
Description
closes: #821
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes