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

chore: remove OnChanUpgradeRestore callbacks and discard state changes on app upgrade callbacks #5696

Merged
merged 13 commits into from
Jan 24, 2024

Conversation

damiannolan
Copy link
Member

Description

  • Removes the OnChanUpgradeRestore callback
  • Discards state changes in Init, Try, Ack upgrade callback handlers

closes: #5692


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.

@damiannolan
Copy link
Member Author

Linter will likely cry oceans about defining consts for re-used strings. I can fix it later!

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

Nice and clean!

@@ -769,8 +769,9 @@ func (k Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.MsgC
return nil, errorsmod.Wrap(err, "channel upgrade init failed")
}

cacheCtx, _ := ctx.CacheContext() // NOTE: the writeFn is discarded and application state changes are not committed.
Copy link
Member

Choose a reason for hiding this comment

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

nit: would be nice to have the docstring above

Copy link
Member

Choose a reason for hiding this comment

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

Also a note that events will also not be emitted

Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] I wonder is it worth adding a helper function to like disposeContext() to make it super clear we're not using a cacheCtx to maybe call it later, we're ensuring it is thrown away from the get go.

Copy link
Contributor

Choose a reason for hiding this comment

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

It also might be nice to include the why for this docstring, I can see myself coming back to this later thinking "why did we do this again?" 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I added additional context in the in-line docstrings!

[nit] I wonder is it worth adding a helper function to like disposeContext() to make it super clear we're not using a cacheCtx to maybe call it later, we're ensuring it is thrown away from the get go.

I like the idea, but I feel like most cosmos devs are generally comfortable with the concept of the "cached context" and that terminology. It might be just introducing more cognitive load with a function which essentially just drops the writeFn. I think its clear what this is doing and I appreciate one less "go to definition" if I'm trying to verify code! Happy to discuss on an issue if there's appetite for changing it

Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

🪓

Beautiful, only nits from me thanks for smashing this one out!

@@ -769,8 +769,9 @@ func (k Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.MsgC
return nil, errorsmod.Wrap(err, "channel upgrade init failed")
}

cacheCtx, _ := ctx.CacheContext() // NOTE: the writeFn is discarded and application state changes are not committed.
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] I wonder is it worth adding a helper function to like disposeContext() to make it super clear we're not using a cacheCtx to maybe call it later, we're ensuring it is thrown away from the get go.

@@ -769,8 +769,9 @@ func (k Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.MsgC
return nil, errorsmod.Wrap(err, "channel upgrade init failed")
}

cacheCtx, _ := ctx.CacheContext() // NOTE: the writeFn is discarded and application state changes are not committed.
Copy link
Contributor

Choose a reason for hiding this comment

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

It also might be nice to include the why for this docstring, I can see myself coming back to this later thinking "why did we do this again?" 😅

@AdityaSripal
Copy link
Member

I like disposeContext!

@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (f4a618c) 81.18% compared to head (2857ac3) 81.27%.
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5696      +/-   ##
==========================================
+ Coverage   81.18%   81.27%   +0.09%     
==========================================
  Files         199      199              
  Lines       15289    15231      -58     
==========================================
- Hits        12412    12379      -33     
+ Misses       2408     2387      -21     
+ Partials      469      465       -4     
Files Coverage Δ
...7-interchain-accounts/controller/ibc_middleware.go 69.53% <ø> (+0.59%) ⬆️
...les/apps/27-interchain-accounts/host/ibc_module.go 91.93% <ø> (+1.45%) ⬆️
modules/apps/29-fee/ibc_middleware.go 86.94% <ø> (+1.59%) ⬆️
modules/apps/transfer/ibc_module.go 69.47% <ø> (+0.36%) ⬆️
modules/core/04-channel/keeper/handshake.go 89.71% <100.00%> (+0.06%) ⬆️
modules/core/04-channel/keeper/upgrade.go 92.30% <100.00%> (+0.03%) ⬆️
modules/core/04-channel/types/channel.go 81.33% <ø> (+4.11%) ⬆️
modules/core/keeper/msg_server.go 66.18% <100.00%> (-0.64%) ⬇️
...27-interchain-accounts/controller/keeper/keeper.go 92.68% <50.00%> (ø)
.../apps/27-interchain-accounts/host/keeper/keeper.go 90.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Superb work my friend! I love the red diffs ❤️

@damiannolan damiannolan enabled auto-merge (squash) January 24, 2024 10:09
@damiannolan damiannolan merged commit 9faaff5 into main Jan 24, 2024
62 of 64 checks passed
@damiannolan damiannolan deleted the damian/5692-remove-restore-cb-discard-app-state branch January 24, 2024 10:20
mergify bot pushed a commit that referenced this pull request Jan 24, 2024
…ges on app upgrade callbacks (#5696)

* docs: remove refs to OnChanUpgradeRestore in docs

* testing: rm OnChanUpgradeRestore callback from mock app test helpers

* chore: rm OnChanUpgradeRestore application callback from ibc core and apps

* chore: discard app state changes by using a cacheCtx and discarding writeFn

* docs: add godoc notes to app callbacks discarding state changes

* test: adding unit tests for discarding app state changes

* chore: clean imports

* chore: review suggestions for in-line docstring comments

* chore: fix linting tests, add mock types for testing kv and events

* doc: add more context to in-line docstrings

(cherry picked from commit 9faaff5)

# Conflicts:
#	docs/docs/01-ibc/06-channel-upgrades.md
#	modules/core/keeper/msg_server.go
#	modules/core/keeper/msg_server_test.go
colin-axner pushed a commit that referenced this pull request Jan 24, 2024
…ges on app upgrade callbacks (backport #5696) (#5701)

* chore: remove `OnChanUpgradeRestore` callbacks and discard state changes on app upgrade callbacks (#5696)

* docs: remove refs to OnChanUpgradeRestore in docs

* testing: rm OnChanUpgradeRestore callback from mock app test helpers

* chore: rm OnChanUpgradeRestore application callback from ibc core and apps

* chore: discard app state changes by using a cacheCtx and discarding writeFn

* docs: add godoc notes to app callbacks discarding state changes

* test: adding unit tests for discarding app state changes

* chore: clean imports

* chore: review suggestions for in-line docstring comments

* chore: fix linting tests, add mock types for testing kv and events

* doc: add more context to in-line docstrings

(cherry picked from commit 9faaff5)

# Conflicts:
#	docs/docs/01-ibc/06-channel-upgrades.md
#	modules/core/keeper/msg_server.go
#	modules/core/keeper/msg_server_test.go

* resolve conflicts

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove application callback OnChanUpgradeRestore and discard state changes in Init, Try, Ack callbacks
6 participants