Skip to content

Commit 9ed5ca4

Browse files
authored
Emit channel close event on ordered channel close (#1464)
1 parent 899f791 commit 9ed5ca4

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
6060
* (app/29-fee) [\#1305](https://github.com/cosmos/ibc-go/pull/1305) Change version string for fee module to `ics29-1`
6161
* (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
6262
* (transfer) [\#1414](https://github.com/cosmos/ibc-go/pull/1414) Emitting Sender address from `fungible_token_packet` events in `OnRecvPacket` and `OnAcknowledgementPacket`.
63+
* (modules/core/04-channel) [\#1464](https://github.com/cosmos/ibc-go/pull/1464) Emit a channel close event when an ordered channel is closed.
6364

6465
### Features
6566

@@ -68,7 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
6869
* (apps/29-fee) [\#1224](https://github.com/cosmos/ibc-go/pull/1224) Adding Query/CounterpartyAddress and CLI to ICS29 fee middleware
6970
* (apps/29-fee) [\#1225](https://github.com/cosmos/ibc-go/pull/1225) Adding Query/FeeEnabledChannel and Query/FeeEnabledChannels with CLIs to ICS29 fee middleware.
7071
* (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.
71-
* (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.
72+
* (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.
7273

7374
### Bug Fixes
7475

modules/core/04-channel/keeper/events.go

+15
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,18 @@ func EmitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel ty
252252
),
253253
})
254254
}
255+
256+
// EmitChannelClosedEvent emits a channel closed event.
257+
func EmitChannelClosedEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) {
258+
ctx.EventManager().EmitEvents(sdk.Events{
259+
sdk.NewEvent(
260+
types.EventTypeChannelClosed,
261+
sdk.NewAttribute(types.AttributeKeyPortID, packet.GetSourcePort()),
262+
sdk.NewAttribute(types.AttributeKeyChannelID, packet.GetSourceChannel()),
263+
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
264+
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
265+
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
266+
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()),
267+
),
268+
})
269+
}

modules/core/04-channel/keeper/timeout.go

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ func (k Keeper) TimeoutExecuted(
170170
// emit an event marking that we have processed the timeout
171171
EmitTimeoutPacketEvent(ctx, packet, channel)
172172

173+
if channel.Ordering == types.ORDERED && channel.State == types.CLOSED {
174+
EmitChannelClosedEvent(ctx, packet, channel)
175+
}
176+
173177
return nil
174178
}
175179

modules/core/04-channel/types/events.go

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848
EventTypeChannelOpenConfirm = "channel_open_confirm"
4949
EventTypeChannelCloseInit = "channel_close_init"
5050
EventTypeChannelCloseConfirm = "channel_close_confirm"
51+
EventTypeChannelClosed = "channel_close"
5152

5253
AttributeValueCategory = fmt.Sprintf("%s_%s", host.ModuleName, SubModuleName)
5354
)

0 commit comments

Comments
 (0)