From 9ed5ca4121d52c8a99076360acf62e52cf7887ea Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 31 May 2022 15:56:17 +0100 Subject: [PATCH] Emit channel close event on ordered channel close (#1464) --- CHANGELOG.md | 3 ++- modules/core/04-channel/keeper/events.go | 15 +++++++++++++++ modules/core/04-channel/keeper/timeout.go | 4 ++++ modules/core/04-channel/types/events.go | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad49532bffb..c0ac41e180c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (app/29-fee) [\#1305](https://github.com/cosmos/ibc-go/pull/1305) Change version string for fee module to `ics29-1` * (app/29-fee) [\#1341](https://github.com/cosmos/ibc-go/pull/1341) Check if the fee module is locked and if the fee module is enabled before refunding all fees * (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 @@ -68,7 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (apps/29-fee) [\#1224](https://github.com/cosmos/ibc-go/pull/1224) Adding Query/CounterpartyAddress and CLI to ICS29 fee middleware * (apps/29-fee) [\#1225](https://github.com/cosmos/ibc-go/pull/1225) Adding Query/FeeEnabledChannel and Query/FeeEnabledChannels with CLIs to ICS29 fee middleware. * (modules/apps/29-fee) [\#1230](https://github.com/cosmos/ibc-go/pull/1230) Adding CLI command for getting incentivized packets for a specific channel-id. -* (modules/apps/transfer) [\#1416](https://github.com/cosmos/ibc-go/pull/1416) Adding gRPC endpoint for getting an escrow account for a given port-id and channel-id. +* (modules/apps/transfer) [\#1416](https://github.com/cosmos/ibc-go/pull/1416) Adding gRPC endpoint for getting an escrow account for a given port-id and channel-id. ### Bug Fixes diff --git a/modules/core/04-channel/keeper/events.go b/modules/core/04-channel/keeper/events.go index 731d298a2ae..66b47467216 100644 --- a/modules/core/04-channel/keeper/events.go +++ b/modules/core/04-channel/keeper/events.go @@ -252,3 +252,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 5a14ef85b6b..f29f1cca671 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -170,6 +170,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 e9f909a695d..8740c3838eb 100644 --- a/modules/core/04-channel/types/events.go +++ b/modules/core/04-channel/types/events.go @@ -48,6 +48,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) )