-
Notifications
You must be signed in to change notification settings - Fork 579
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d5a747
port code from #1056
colin-axner ca65d4f
refactor: deduplicate distribution code
colin-axner e91f849
add test case for on acknowledgement packet distribution
colin-axner 317aaa1
add check for timeout packet distribution
colin-axner 27ccd3b
merge main
colin-axner 8e73b5a
revert to duplicate code approach
colin-axner f968b78
add tests for DistributePacketFeesOnTimeout
colin-axner 558e852
chore: remove unnecessary comment
colin-axner b73b439
add back godoc
colin-axner 3ac48a2
Merge branch 'main' into colin/821-escrow-out-of-balance-check
colin-axner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andctx
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
anddistirbuteTimeoutPacketFees
functionality in comparison to the proposed waydistributePacketFeeOnAcknowledgement
anddistirbutePacketFeeOnTimeout
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:
..., OnTimeout)
or..., OnAcknowledgement)
...., 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...