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

refactor: use explicit checks in ica controller upgrade handlers #5472

Merged
merged 11 commits into from
Jan 4, 2024

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented Dec 20, 2023

Description

ref: #5462

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.

@@ -162,30 +187,49 @@ func (k Keeper) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, ord
return "", err
}

if err := icatypes.ValidateControllerMetadata(ctx, k.channelKeeper, connectionHops, metadata); err != nil {
return "", errorsmod.Wrap(err, "invalid metadata")
// ValidateControllerMetadata will ensure the interchain account version has not changed and that the
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could pull here down into a helper func ValidateUpgradeMetadata, pulling out the relevant checks from ValidateControllerMetadata, but left as duplication between upgrade init and upgrade ack for now

@colin-axner colin-axner changed the base branch from 04-channel-upgrades to main December 21, 2023 18:49
…troller

Updated UpgradeInit logic
Updated UpgradeAck logic
Refactored UpgradeInit tests
@colin-axner colin-axner force-pushed the colin/5462-controller-cbs branch from 33769a6 to 6fe19e1 Compare December 21, 2023 18:50
@colin-axner colin-axner added the channel-upgradability Channel upgradability feature label Dec 21, 2023
@codecov-commenter
Copy link

codecov-commenter commented Dec 21, 2023

Codecov Report

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

Comparison is base (f6e3425) 80.96% compared to head (4226d8c) 81.09%.
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5472      +/-   ##
==========================================
+ Coverage   80.96%   81.09%   +0.13%     
==========================================
  Files         197      197              
  Lines       15221    15234      +13     
==========================================
+ Hits        12323    12354      +31     
+ Misses       2427     2412      -15     
+ Partials      471      468       -3     
Files Coverage Δ
modules/core/04-channel/keeper/keeper.go 90.77% <100.00%> (ø)
modules/core/04-channel/types/msgs.go 94.80% <ø> (+2.16%) ⬆️
modules/core/04-channel/types/params.go 100.00% <100.00%> (+42.85%) ⬆️
modules/core/keeper/msg_server.go 63.67% <100.00%> (-0.05%) ⬇️
modules/core/04-channel/keeper/upgrade.go 92.30% <80.00%> (-0.13%) ⬇️
...interchain-accounts/controller/keeper/handshake.go 84.17% <65.62%> (-0.87%) ⬇️

... and 1 file with indirect coverage changes

@colin-axner colin-axner marked this pull request as ready for review December 21, 2023 19:53
order channeltypes.Order
)

// updateMetadata is a helper function which modifies the metadata stored in the channel version
// and marshals it into a string to pass to OnChanUpgradeInit as the counterpartyVersion string.
updateMetadata := func(modificationFn func(*icatypes.Metadata)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to match upgrade ack

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.

LGTM, very nice test coverage ❤️

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.

Nice work, @colin-axner

Comment on lines +202 to 208
if currentMetadata.ControllerConnectionId != proposedMetadata.ControllerConnectionId {
return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed controller connection ID must not change")
}

if currentMetadata.HostConnectionId != proposedMetadata.HostConnectionId {
return "", errorsmod.Wrap(connectiontypes.ErrInvalidConnection, "proposed host connection ID must not change")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel too strongly about it, but if these checks are not reachable in either OnChanUpgradeInit and OnChanUpgradeAck, couldn't we just remove them and add a comment above the call to ValidateControllerMetadata to explain that this function protects against these changes?

@crodriguezvega crodriguezvega merged commit 4a021a3 into main Jan 4, 2024
61 checks passed
@crodriguezvega crodriguezvega deleted the colin/5462-controller-cbs branch January 4, 2024 20:14
mergify bot pushed a commit that referenced this pull request Jan 4, 2024
* refactor: explicit checks in upgrade init and upgrade ack for ica controller

Updated UpgradeInit logic
Updated UpgradeAck logic
Refactored UpgradeInit tests

* test: complete upgrade ack tests

* test: add code cov

* lint appease

* nit: use correct error type

* nit comment change

* fix typo

---------

Co-authored-by: Cian Hatton <cian@interchain.io>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit 4a021a3)
crodriguezvega pushed a commit that referenced this pull request Jan 5, 2024
…) (#5518)

* refactor: explicit checks in upgrade init and upgrade ack for ica controller

Updated UpgradeInit logic
Updated UpgradeAck logic
Refactored UpgradeInit tests

* test: complete upgrade ack tests

* test: add code cov

* lint appease

* nit: use correct error type

* nit comment change

* fix typo

---------

Co-authored-by: Cian Hatton <cian@interchain.io>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit 4a021a3)

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants