diff --git a/.golangci.yml b/.golangci.yml index 56f4fbcf3c9..4e07742d050 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -63,4 +63,4 @@ linters-settings: revive: rules: - name: if-return - disabled: true \ No newline at end of file + disabled: true diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index e790e4ae120..4ec0d324ee0 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -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), + ), + }) +} diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index b0e38453443..fdc1d872c69 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -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 diff --git a/modules/core/04-channel/types/events.go b/modules/core/04-channel/types/events.go index e47a8e4d2af..d82703c40f3 100644 --- a/modules/core/04-channel/types/events.go +++ b/modules/core/04-channel/types/events.go @@ -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) )