Skip to content

Commit

Permalink
Chore: Addtional check against wrapped upgrade error in `ChannelUpgra…
Browse files Browse the repository at this point in the history
…deTry` (cosmos#5823)

* addtional check

* upgradeErr

* errors.As

* nit

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
  • Loading branch information
3 people committed Mar 4, 2024
1 parent 1229c46 commit c489ee4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"errors"

metrics "github.com/hashicorp/go-metrics"

Expand Down Expand Up @@ -815,10 +816,14 @@ func (k Keeper) ChannelUpgradeTry(goCtx context.Context, msg *channeltypes.MsgCh
if err != nil {
ctx.Logger().Error("channel upgrade try failed", "error", errorsmod.Wrap(err, "channel upgrade try failed"))
if channeltypes.IsUpgradeError(err) {
k.ChannelKeeper.WriteErrorReceipt(ctx, msg.PortId, msg.ChannelId, err.(*channeltypes.UpgradeError))
// NOTE: a FAILURE result is returned to the client and an error receipt is written to state.
// This signals to the relayer to begin the cancel upgrade handshake subprotocol.
return &channeltypes.MsgChannelUpgradeTryResponse{Result: channeltypes.FAILURE}, nil
// In case the error is a wrapped upgrade error, we need to extract the inner error else process as normal
var upgradeErr *channeltypes.UpgradeError
if errors.As(err, &upgradeErr) {
k.ChannelKeeper.WriteErrorReceipt(ctx, msg.PortId, msg.ChannelId, upgradeErr)
// NOTE: a FAILURE result is returned to the client and an error receipt is written to state.
// This signals to the relayer to begin the cancel upgrade handshake subprotocol.
return &channeltypes.MsgChannelUpgradeTryResponse{Result: channeltypes.FAILURE}, nil
}
}

// NOTE: an error is returned to baseapp and transaction state is not committed.
Expand Down

0 comments on commit c489ee4

Please sign in to comment.