diff --git a/CHANGELOG.md b/CHANGELOG.md index f2a200f1372..2844545f723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (modules/core/04-channel) [\#1160](https://github.com/cosmos/ibc-go/pull/1160) Improve `uint64 -> string` performance in `Logger`. * (modules/core/keeper) [\#1284](https://github.com/cosmos/ibc-go/pull/1284) Add sanity check for the keepers passed into `ibckeeper.NewKeeper`. `ibckeeper.NewKeeper` now panics if any of the keepers passed in is empty. * (transfer) [\#1414](https://github.com/cosmos/ibc-go/pull/1414) Emitting Sender address from `fungible_token_packet` events in `OnRecvPacket` and `OnAcknowledgementPacket`. +* (modules/core/04-channel) [\#1464](https://github.com/cosmos/ibc-go/pull/1464) Emit a channel close event when an ordered channel is closed. ### Features diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index bfdf925f2e6..6997c006065 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -137,3 +137,18 @@ func EmitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel ty ), }) } + +// EmitChannelClosedEvent emits a channel closed event. +func EmitChannelClosedEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) { + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelClosed, + sdk.NewAttribute(types.AttributeKeyPortID, packet.GetSourcePort()), + sdk.NewAttribute(types.AttributeKeyChannelID, packet.GetSourceChannel()), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()), + ), + }) +} diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index 7067a51964c..e7528b73ce8 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -169,6 +169,10 @@ func (k Keeper) TimeoutExecuted( // emit an event marking that we have processed the timeout EmitTimeoutPacketEvent(ctx, packet, channel) + if channel.Ordering == types.ORDERED && channel.State == types.CLOSED { + EmitChannelClosedEvent(ctx, packet, channel) + } + return nil } diff --git a/modules/core/04-channel/types/events.go b/modules/core/04-channel/types/events.go index 201fd26a0ed..4c7eb46a815 100644 --- a/modules/core/04-channel/types/events.go +++ b/modules/core/04-channel/types/events.go @@ -47,6 +47,7 @@ var ( EventTypeChannelOpenConfirm = "channel_open_confirm" EventTypeChannelCloseInit = "channel_close_init" EventTypeChannelCloseConfirm = "channel_close_confirm" + EventTypeChannelClosed = "channel_close" AttributeValueCategory = fmt.Sprintf("%s_%s", host.ModuleName, SubModuleName) )