Skip to content

Commit 9e632cd

Browse files
mergify[bot]chattoncrodriguezvega
authored
Emit channel close event on ordered channel close (backport #1464) (#1470)
* Emit channel close event on ordered channel close (#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 13ed620 commit 9e632cd

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
@@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4747
* (modules/core/04-channel) [\#1160](https://github.com/cosmos/ibc-go/pull/1160) Improve `uint64 -> string` performance in `Logger`.
4848
* (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.
4949
* (transfer) [\#1414](https://github.com/cosmos/ibc-go/pull/1414) Emitting Sender address from `fungible_token_packet` events in `OnRecvPacket` and `OnAcknowledgementPacket`.
50+
* (modules/core/04-channel) [\#1464](https://github.com/cosmos/ibc-go/pull/1464) Emit a channel close event when an ordered channel is closed.
5051

5152
### Features
5253

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

+15
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,18 @@ func EmitTimeoutPacketEvent(ctx sdk.Context, packet exported.PacketI, channel ty
137137
),
138138
})
139139
}
140+
141+
// EmitChannelClosedEvent emits a channel closed event.
142+
func EmitChannelClosedEvent(ctx sdk.Context, packet exported.PacketI, channel types.Channel) {
143+
ctx.EventManager().EmitEvents(sdk.Events{
144+
sdk.NewEvent(
145+
types.EventTypeChannelClosed,
146+
sdk.NewAttribute(types.AttributeKeyPortID, packet.GetSourcePort()),
147+
sdk.NewAttribute(types.AttributeKeyChannelID, packet.GetSourceChannel()),
148+
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
149+
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
150+
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
151+
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()),
152+
),
153+
})
154+
}

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

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

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

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)