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: create and reuse errors in core channel upgrades handlers #5389

Merged
merged 10 commits into from
Jan 9, 2024

Conversation

vishal-kanna
Copy link
Contributor

@vishal-kanna vishal-kanna commented Dec 12, 2023

closes #5378

@damiannolan
Copy link
Member

Hi, it looks like there's some compiler errors here from a redeclared function.

I would also suggest naming the errors err as is standard in golang apps.

- invalidupgraderoute := errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)
+ err = errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)

@crodriguezvega crodriguezvega changed the base branch from 04-channel-upgrades to main December 21, 2023 22:51
@DimitrisJim
Copy link
Contributor

cleaned the history up since it was bringing in 350 commits with a 25k diff 😅. should ideally look clean and reviewable now ✨

@codecov-commenter
Copy link

codecov-commenter commented Dec 24, 2023

Codecov Report

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

Comparison is base (bf12ce3) 81.27% compared to head (32ced7f) 81.20%.
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5389      +/-   ##
==========================================
- Coverage   81.27%   81.20%   -0.08%     
==========================================
  Files         197      197              
  Lines       15234    15235       +1     
==========================================
- Hits        12382    12372      -10     
- Misses       2391     2400       +9     
- Partials      461      463       +2     
Files Coverage Δ
modules/core/03-connection/keeper/verify.go 78.79% <ø> (-0.55%) ⬇️
modules/core/04-channel/keeper/upgrade.go 92.26% <ø> (-0.05%) ⬇️
modules/core/keeper/msg_server.go 66.43% <52.94%> (-0.59%) ⬇️

It is uneeded if the if guard fails.
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!

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.

LGTM! Thanks @vishal-kanna

@@ -856,19 +856,22 @@ func (k Keeper) ChannelUpgradeAck(goCtx context.Context, msg *channeltypes.MsgCh

app, ok := k.Router.GetRoute(module)
if !ok {
ctx.Logger().Error("channel upgrade ack failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module))
return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)
err = errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)
Copy link
Member

Choose a reason for hiding this comment

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

we could reinitialise new errors here as they'd be within the scope of the if, but I don't really feel super strong on it and happy to reuse err

Copy link
Contributor

Choose a reason for hiding this comment

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

will push it in as is for now, can't say I have a strong pref either way too (slight preference for yours since it scopes values nicely but not enough pref to make the change)

}

err = k.ChannelKeeper.ChanUpgradeAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyUpgrade, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight)
if err != nil {
ctx.Logger().Error("channel upgrade ack failed", "error", errorsmod.Wrap(err, "channel upgrade ack failed"))
errChanUpgradeFailed := errorsmod.Wrap(err, "channel upgrade ack failed")
Copy link
Member

Choose a reason for hiding this comment

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

any reason not to reuse err here instead of creating a new var with a different name?

err = errorsmod.Wrap(err, "channel upgrade ack failed") should work fine too, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@damiannolan Using the err works fine.

Copy link
Contributor

@DimitrisJim DimitrisJim Jan 9, 2024

Choose a reason for hiding this comment

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

ah it won't. IsUpgradeError is a direct cast to UpgradeError, wrapping causes it to fail. (I think Cian mentioned this in a call at some point).

@damiannolan damiannolan changed the title feat : reused the error imp: create and reuse errors in core channel upgrades handlers Jan 9, 2024
@DimitrisJim DimitrisJim merged commit b68c4aa into cosmos:main Jan 9, 2024
62 checks passed
@DimitrisJim
Copy link
Contributor

do we backport to 8.1? cc @crodriguezvega

mergify bot pushed a commit that referenced this pull request Jan 9, 2024
imp: create and reuse errors in core channel upgrades handlers

---------

Co-authored-by: DimitrisJim <[email protected]>
Co-authored-by: Cian Hatton <[email protected]>
(cherry picked from commit b68c4aa)
crodriguezvega pushed a commit that referenced this pull request Jan 9, 2024
#5557)

imp: create and reuse errors in core channel upgrades handlers

---------

Co-authored-by: DimitrisJim <[email protected]>
Co-authored-by: Cian Hatton <[email protected]>
(cherry picked from commit b68c4aa)

Co-authored-by: Vishal Potpelliwar <[email protected]>
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.

Duplicate error creation in core msg server handlers for error logging and returns
6 participants