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

imp: add defensive check on WriteErrorReceipt in addition to more in-line docs on edge cases #5734

Merged
merged 10 commits into from
Jan 29, 2024

Conversation

colin-axner
Copy link
Contributor

Description

closes: #XXXX

Commit Message / Changelog Entry

type: commit message

see the guidelines for commit messages. (view raw markdown for examples)


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 the correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@colin-axner colin-axner added priority PRs that need prompt reviews channel-upgradability Channel upgradability feature backport-to-v8.1.x labels Jan 25, 2024
Comment on lines +550 to +551
// hasCounterpartyUpgrade returns true if a counterparty upgrade exists in store
func (k Keeper) hasCounterpartyUpgrade(ctx sdk.Context, portID, channelID string) bool {
Copy link
Contributor Author

@colin-axner colin-axner Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied over same func @AdityaSripal used for HasUpgrade but chose to leave the hasCounterpartyUpgrade private since I don't see a reason to add it to the public API when it is used only for defensive checks in edge case scenarios (in general I think our get/set/has funcs should be private)

@colin-axner colin-axner marked this pull request as ready for review January 25, 2024 16:04
@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (310a4bd) 81.49% compared to head (dd0751a) 81.52%.
Report is 5 commits behind head on main.

❗ Current head dd0751a differs from pull request most recent head ef5faa5. Consider uploading reports for the commit ef5faa5 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5734      +/-   ##
==========================================
+ Coverage   81.49%   81.52%   +0.03%     
==========================================
  Files         199      199              
  Lines       15203    15229      +26     
==========================================
+ Hits        12389    12415      +26     
  Misses       2348     2348              
  Partials      466      466              
Files Coverage Δ
modules/core/04-channel/keeper/keeper.go 90.90% <100.00%> (+0.13%) ⬆️
modules/core/04-channel/keeper/upgrade.go 92.53% <100.00%> (+0.22%) ⬆️

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

@@ -55,6 +55,7 @@ func (k Keeper) WriteUpgradeInitChannel(ctx sdk.Context, portID, channelID strin

if k.hasUpgrade(ctx, portID, channelID) {
// invalidating previous upgrade
k.deleteUpgradeInfo(ctx, portID, channelID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @damiannolan. We decided to add an explicit deletion of the upgrade info when invalidating a previous attempt. Functionally this does not change the code as it stands right now because:

  • we overwrite the upgrade shortly after
  • no counterparty upgrade exists

but we need this change in order to keep the defensive check in WriteErrorReceipt and it prevents an accidental mistake of forgetting to delete information if more info is added to the upgrade process. So we change deletion of previous upgrade info from implicit to explicit at the gas of some extra reads/write but it'll make it harder for developers to make mistakes when changing any logic in channel upgradability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no counterparty upgrade exists because we can only meaningfully run init (and by extent, its write) before we enter flushing/flushcomplete, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, since we assert the channel.State is OPEN

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but I am just wondering that if we do deleteUpgradeInfo + WriteErrorReceipt now, would it be possible to basically call abortUpgrade?

Copy link
Contributor

@DimitrisJim DimitrisJim Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think you could @crodriguezvega but would definitely incur more gas in addition to not semantically fitting an abort which is used when channel state is either flushing/flush-complete. (maybe a refactoring could eventually be made tho)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it would do extra writes to set the channel state and upgrade sequence (to the existing values). Leaving as is

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final PR 🤞🏻 LFG!!!!!! 🚀

Thank you @colin-axner, amazing doc comments to save our future selves from many head scratchers ❤️

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last PR before release! Exciting!

I left just a nit question.

@@ -55,6 +55,7 @@ func (k Keeper) WriteUpgradeInitChannel(ctx sdk.Context, portID, channelID strin

if k.hasUpgrade(ctx, portID, channelID) {
// invalidating previous upgrade
k.deleteUpgradeInfo(ctx, portID, channelID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but I am just wondering that if we do deleteUpgradeInfo + WriteErrorReceipt now, would it be possible to basically call abortUpgrade?

@colin-axner colin-axner merged commit 4727e2c into main Jan 29, 2024
63 checks passed
@colin-axner colin-axner deleted the colin/audit-inline-docs-chanupgrade branch January 29, 2024 13:49
mergify bot pushed a commit that referenced this pull request Jan 29, 2024
…line docs on edge cases (#5734)

* imp: add defensive check + extra documentation for edge case scenarios

* imp: gas optimization

* self nit

* imp: HasUpgrade -> hasUpgrade

* fix: add explicit upgrade deletion in init

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit 4727e2c)
damiannolan pushed a commit that referenced this pull request Jan 29, 2024
…line docs on edge cases (#5734) (#5765)

* imp: add defensive check + extra documentation for edge case scenarios

* imp: gas optimization

* self nit

* imp: HasUpgrade -> hasUpgrade

* fix: add explicit upgrade deletion in init

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit 4727e2c)

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
channel-upgradability Channel upgradability feature priority PRs that need prompt reviews
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants