Skip to content

Commit 66abe56

Browse files
mergify[bot]chattoncrodriguezvega
authored andcommitted
Emit channel close event on ordered channel close (backport cosmos#1464) (cosmos#1475)
* Emit channel close event on ordered channel close (cosmos#1464) (cherry picked from commit 9ed5ca4) * fix conflict Co-authored-by: Cian Hatton <[email protected]> Co-authored-by: Carlos Rodriguez <[email protected]>
1 parent f53dfef commit 66abe56

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

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

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

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
@@ -47,6 +47,7 @@ var (
4747
EventTypeChannelOpenConfirm = "channel_open_confirm"
4848
EventTypeChannelCloseInit = "channel_close_init"
4949
EventTypeChannelCloseConfirm = "channel_close_confirm"
50+
EventTypeChannelClosed = "channel_close"
5051

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

0 commit comments

Comments
 (0)