-
Notifications
You must be signed in to change notification settings - Fork 586
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
Changes from 9 commits
dbb2024
fffc893
1c86744
6f229c9
a8d18b8
7e48981
32ced7f
fc4d6cb
672e86a
82e96ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
ctx.Logger().Error("channel upgrade ack failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
cbs, ok := app.(porttypes.UpgradableModule) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade ack failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)) | ||
return nil, 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) | ||
ctx.Logger().Error("channel upgrade ack failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason not to reuse
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @damiannolan Using the err works fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah it won't. |
||
ctx.Logger().Error("channel upgrade ack failed", "error", errChanUpgradeFailed) | ||
if channeltypes.IsUpgradeError(err) { | ||
k.ChannelKeeper.MustAbortUpgrade(ctx, msg.PortId, msg.ChannelId, err) | ||
cbs.OnChanUpgradeRestore(ctx, msg.PortId, msg.ChannelId) | ||
|
@@ -879,7 +882,7 @@ func (k Keeper) ChannelUpgradeAck(goCtx context.Context, msg *channeltypes.MsgCh | |
} | ||
|
||
// NOTE: an error is returned to baseapp and transaction state is not committed. | ||
return nil, errorsmod.Wrap(err, "channel upgrade ack failed") | ||
return nil, errChanUpgradeFailed | ||
} | ||
|
||
cacheCtx, writeFn := ctx.CacheContext() | ||
|
@@ -914,14 +917,16 @@ func (k Keeper) ChannelUpgradeConfirm(goCtx context.Context, msg *channeltypes.M | |
|
||
app, ok := k.Router.GetRoute(module) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade confirm 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) | ||
ctx.Logger().Error("channel upgrade confirm failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
cbs, ok := app.(porttypes.UpgradableModule) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade confirm failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)) | ||
return nil, 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) | ||
ctx.Logger().Error("channel upgrade confirm failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
err = k.ChannelKeeper.ChanUpgradeConfirm(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelState, msg.CounterpartyUpgrade, msg.ProofChannel, msg.ProofUpgrade, msg.ProofHeight) | ||
|
@@ -974,14 +979,16 @@ func (k Keeper) ChannelUpgradeOpen(goCtx context.Context, msg *channeltypes.MsgC | |
|
||
app, ok := k.Router.GetRoute(module) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade open 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) | ||
ctx.Logger().Error("channel upgrade open failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
cbs, ok := app.(porttypes.UpgradableModule) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade open failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)) | ||
return nil, 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) | ||
ctx.Logger().Error("channel upgrade open failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
if err = k.ChannelKeeper.ChanUpgradeOpen(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelState, msg.ProofChannel, msg.ProofHeight); err != nil { | ||
|
@@ -1015,14 +1022,16 @@ func (k Keeper) ChannelUpgradeTimeout(goCtx context.Context, msg *channeltypes.M | |
|
||
app, ok := k.Router.GetRoute(module) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade timeout 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) | ||
ctx.Logger().Error("channel upgrade timeout failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
cbs, ok := app.(porttypes.UpgradableModule) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade timeout failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)) | ||
return nil, 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) | ||
ctx.Logger().Error("channel upgrade timeout failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
err = k.ChannelKeeper.ChanUpgradeTimeout(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannel, msg.ProofChannel, msg.ProofHeight) | ||
|
@@ -1051,14 +1060,16 @@ func (k Keeper) ChannelUpgradeCancel(goCtx context.Context, msg *channeltypes.Ms | |
|
||
app, ok := k.Router.GetRoute(module) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade cancel 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) | ||
ctx.Logger().Error("channel upgrade cancel failed", "port-id", msg.PortId, "error", err) | ||
return nil, err | ||
} | ||
|
||
cbs, ok := app.(porttypes.UpgradableModule) | ||
if !ok { | ||
ctx.Logger().Error("channel upgrade cancel failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "upgrade route not found to module: %s", module)) | ||
return nil, 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) | ||
ctx.Logger().Error("channel upgrade cancel failed", "port-id", msg.PortId, err) | ||
return nil, err | ||
} | ||
|
||
channel, found := k.ChannelKeeper.GetChannel(ctx, msg.PortId, msg.ChannelId) | ||
|
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.
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 reuseerr
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.
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)