Skip to content

Commit

Permalink
Add implementation for WriteUpgradeCancelChannel (#3773)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton authored Jun 14, 2023
1 parent 3092171 commit 87d8158
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ linters-settings:
revive:
rules:
- name: if-return
disabled: true
disabled: true
21 changes: 21 additions & 0 deletions modules/core/04-channel/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,24 @@ func emitErrorReceiptEvent(ctx sdk.Context, portID string, channelID string, cur
),
})
}

// emitChannelUpgradeCancelEvent emits an upgraded cancelled event.
func emitChannelUpgradeCancelEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) {
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelUpgradeCancel,
sdk.NewAttribute(types.AttributeKeyPortID, portID),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, currentChannel.Counterparty.PortId),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, currentChannel.Counterparty.ChannelId),
sdk.NewAttribute(types.AttributeKeyUpgradeConnectionHops, upgrade.Fields.ConnectionHops[0]),
sdk.NewAttribute(types.AttributeKeyUpgradeVersion, upgrade.Fields.Version),
sdk.NewAttribute(types.AttributeKeyUpgradeOrdering, upgrade.Fields.Ordering.String()),
sdk.NewAttribute(types.AttributeKeyUpgradeSequence, fmt.Sprintf("%d", currentChannel.UpgradeSequence)),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
})
}
20 changes: 20 additions & 0 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ func (k Keeper) WriteUpgradeAckChannel(
emitChannelUpgradeAckEvent(ctx, portID, channelID, channel, proposedUpgrade)
}

// WriteUpgradeCancelChannel writes a channel which has canceled the upgrade process.Auxiliary upgrade state is
// also deleted.
func (k Keeper) WriteUpgradeCancelChannel(ctx sdk.Context, portID, channelID string) {
defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-cancel")

upgrade, found := k.GetUpgrade(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find upgrade when updating channel state, channelID: %s, portID: %s", channelID, portID))
}

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

k.restoreChannel(ctx, portID, channelID, channel)

emitChannelUpgradeCancelEvent(ctx, portID, channelID, channel, upgrade)
}

// ChanUpgradeAck is called by a module to accept the ACKUPGRADE handshake step of the channel upgrade protocol.
// This method should only be called by the IBC core msg server.
// This method will verify that the counterparty has entered TRYUPGRADE
Expand Down
23 changes: 12 additions & 11 deletions modules/core/04-channel/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ const (

// IBC channel events vars
var (
EventTypeChannelOpenInit = "channel_open_init"
EventTypeChannelOpenTry = "channel_open_try"
EventTypeChannelOpenAck = "channel_open_ack"
EventTypeChannelOpenConfirm = "channel_open_confirm"
EventTypeChannelCloseInit = "channel_close_init"
EventTypeChannelCloseConfirm = "channel_close_confirm"
EventTypeChannelClosed = "channel_close"
EventTypeChannelUpgradeInit = "channel_upgrade_init"
EventTypeChannelUpgradeTry = "channel_upgrade_try"
EventTypeChannelUpgradeAck = "channel_upgrade_ack"
EventTypeChannelUpgradeOpen = "channel_upgrade_open"
EventTypeChannelOpenInit = "channel_open_init"
EventTypeChannelOpenTry = "channel_open_try"
EventTypeChannelOpenAck = "channel_open_ack"
EventTypeChannelOpenConfirm = "channel_open_confirm"
EventTypeChannelCloseInit = "channel_close_init"
EventTypeChannelCloseConfirm = "channel_close_confirm"
EventTypeChannelClosed = "channel_close"
EventTypeChannelUpgradeInit = "channel_upgrade_init"
EventTypeChannelUpgradeTry = "channel_upgrade_try"
EventTypeChannelUpgradeAck = "channel_upgrade_ack"
EventTypeChannelUpgradeOpen = "channel_upgrade_open"
EventTypeChannelUpgradeCancel = "channel_upgrade_cancelled"

AttributeValueCategory = fmt.Sprintf("%s_%s", ibcexported.ModuleName, SubModuleName)
)

0 comments on commit 87d8158

Please sign in to comment.