Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

imp: create and reuse errors in core channel upgrades handlers (backport #5389) #5557

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading