Skip to content

Commit

Permalink
Add implementation for message server handling of ChanUpgradeOpen.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Jun 28, 2023
1 parent 77d91c2 commit 27afafa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 0 additions & 5 deletions modules/core/04-channel/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,3 @@ func (k Keeper) StartFlushUpgradeHandshake(
func (k Keeper) ValidateUpgradeFields(ctx sdk.Context, proposedUpgrade types.UpgradeFields, currentChannel types.Channel) error {
return k.validateUpgradeFields(ctx, proposedUpgrade, currentChannel)
}

// WriteUpgradeOpenChannel is a wrapper around writeUpgradeOpenChannel to allow the function to be directly called in tests.
func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) {
k.writeUpgradeOpenChannel(ctx, portID, channelID)
}
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (k Keeper) ChanUpgradeOpen(
// WriteUpgradeOpenChannel writes the agreed upon upgrade fields to the channel, sets the channel flush status to NOTINFLUSH and sets the channel state back to OPEN. This can be called in one of two cases:
// - In the UpgradeAck step of the handshake if both sides have already flushed all in-flight packets.
// - In the UpgradeOpen step of the handshake.
func (k Keeper) writeUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) {
func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) {
channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find existing channel when updating channel state, channelID: %s, portID: %s", channelID, portID))
Expand Down
27 changes: 26 additions & 1 deletion modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,32 @@ func (k Keeper) ChannelUpgradeAck(goCtx context.Context, msg *channeltypes.MsgCh

// ChannelUpgradeOpen defines a rpc handler method for MsgChannelUpgradeOpen.
func (k Keeper) ChannelUpgradeOpen(goCtx context.Context, msg *channeltypes.MsgChannelUpgradeOpen) (*channeltypes.MsgChannelUpgradeOpenResponse, error) {
return nil, nil
ctx := sdk.UnwrapSDKContext(goCtx)

module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId)
if err != nil {
ctx.Logger().Error("channel upgrade open failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id"))
return nil, errorsmod.Wrap(err, "could not retrieve module from port-id")
}

cbs, 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)
}

if err = k.ChannelKeeper.ChanUpgradeOpen(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyChannelState, msg.ProofChannel, msg.ProofHeight); err != nil {
ctx.Logger().Error("channel upgrade open failed", "error", errorsmod.Wrap(err, "channel handshake upgrade open failed"))
return nil, errorsmod.Wrap(err, "channel handshake upgrade open failed")
}

k.ChannelKeeper.WriteUpgradeOpenChannel(ctx, msg.PortId, msg.ChannelId)

cbs.OnChanUpgradeOpen(ctx, msg.PortId, msg.ChannelId)

ctx.Logger().Info("channel upgrade open callback succeeded", "channel-id", msg.ChannelId, "port-id", msg.PortId)

return &channeltypes.MsgChannelUpgradeOpenResponse{}, nil
}

// ChannelUpgradeTimeout defines a rpc handler method for MsgChannelUpgradeTimeout.
Expand Down

0 comments on commit 27afafa

Please sign in to comment.