Skip to content

Commit

Permalink
feat: Emit channel close event on ordered channel close
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton committed May 30, 2022
1 parent f12f841 commit de5a656
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/core/04-channel/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
),
})
}
1 change: 1 addition & 0 deletions modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (k Keeper) TimeoutExecuted(
if channel.Ordering == types.ORDERED {
channel.State = types.CLOSED
k.SetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), channel)
EmitChannelClosedEvent(ctx, packet, channel)
}

k.Logger(ctx).Info(
Expand Down
1 change: 1 addition & 0 deletions modules/core/04-channel/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

0 comments on commit de5a656

Please sign in to comment.