Skip to content

Commit

Permalink
Emit channel close event on ordered channel close (backport cosmos#1464
Browse files Browse the repository at this point in the history
…) (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]>
  • Loading branch information
3 people authored and dudong2 committed Jan 19, 2023
1 parent f53dfef commit 66abe56
Show file tree
Hide file tree
Showing 3 changed files with 20 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 @@ -250,3 +250,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()),
),
})
}
4 changes: 4 additions & 0 deletions modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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 @@ -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)
)

0 comments on commit 66abe56

Please sign in to comment.