Skip to content

Commit 166c467

Browse files
mergify[bot]chattoncrodriguezvega
authored andcommitted
Emit channel close event on ordered channel close (backport cosmos#1464) (cosmos#1476)
* Emit channel close event on ordered channel close (cosmos#1464) (cherry picked from commit 9ed5ca4) # Conflicts: # CHANGELOG.md * fix conflict Co-authored-by: Cian Hatton <cian@interchain.io> Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
1 parent 33b79c7 commit 166c467

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
5050
* (modules/core/04-channel) [\#1279](https://github.com/cosmos/ibc-go/pull/1279) Add selected channel version to MsgChanOpenInitResponse and MsgChanOpenTryResponse. Emit channel version during OpenInit/OpenTry
5151
* (modules/core/keeper) [\#1284](https://github.com/cosmos/ibc-go/pull/1284) Add sanity check for the keepers passed into `ibckeeper.NewKeeper`. `ibckeeper.NewKeeper` now panics if any of the keepers passed in is empty.
5252
* (transfer) [\#1414](https://github.com/cosmos/ibc-go/pull/1414) Emitting Sender address from `fungible_token_packet` events in `OnRecvPacket` and `OnAcknowledgementPacket`.
53+
* (modules/core/04-channel) [\#1464](https://github.com/cosmos/ibc-go/pull/1464) Emit a channel close event when an ordered channel is closed.
5354

5455
### Features
5556

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)