Skip to content

Commit efe0e24

Browse files
seantkingAdityaSripal
authored andcommitted
Fix/channel open/close events (#220)
* fix: moving event to keeper function instead of rpc handler * refactor: removing unnecessary handler * refactor: delete channel handler file * Apply suggestions from code review Co-authored-by: Aditya <adityasripal@gmail.com>
1 parent 2e95805 commit efe0e24

File tree

3 files changed

+129
-199
lines changed

3 files changed

+129
-199
lines changed

modules/core/04-channel/handler.go

-186
This file was deleted.

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

+67
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ func (k Keeper) ChanOpenInit(
9191
telemetry.IncrCounter(1, "ibc", "channel", "open-init")
9292
}()
9393

94+
ctx.EventManager().EmitEvents(sdk.Events{
95+
sdk.NewEvent(
96+
types.EventTypeChannelOpenInit,
97+
sdk.NewAttribute(types.AttributeKeyPortID, portID),
98+
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
99+
sdk.NewAttribute(types.AttributeCounterpartyPortID, counterparty.PortId),
100+
sdk.NewAttribute(types.AttributeCounterpartyChannelID, counterparty.ChannelId),
101+
sdk.NewAttribute(types.AttributeKeyConnectionID, connectionHops[0]),
102+
),
103+
})
104+
94105
return channelID, capKey, nil
95106
}
96107

@@ -232,6 +243,17 @@ func (k Keeper) ChanOpenTry(
232243
telemetry.IncrCounter(1, "ibc", "channel", "open-try")
233244
}()
234245

246+
ctx.EventManager().EmitEvents(sdk.Events{
247+
sdk.NewEvent(
248+
types.EventTypeChannelOpenTry,
249+
sdk.NewAttribute(types.AttributeKeyPortID, portID),
250+
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
251+
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
252+
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
253+
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
254+
),
255+
})
256+
235257
return channelID, capKey, nil
236258
}
237259

@@ -307,6 +329,17 @@ func (k Keeper) ChanOpenAck(
307329
channel.Counterparty.ChannelId = counterpartyChannelID
308330
k.SetChannel(ctx, portID, channelID, channel)
309331

332+
ctx.EventManager().EmitEvents(sdk.Events{
333+
sdk.NewEvent(
334+
types.EventTypeChannelOpenAck,
335+
sdk.NewAttribute(types.AttributeKeyPortID, portID),
336+
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
337+
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
338+
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
339+
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
340+
),
341+
})
342+
310343
return nil
311344
}
312345

@@ -375,6 +408,18 @@ func (k Keeper) ChanOpenConfirm(
375408
defer func() {
376409
telemetry.IncrCounter(1, "ibc", "channel", "open-confirm")
377410
}()
411+
412+
ctx.EventManager().EmitEvents(sdk.Events{
413+
sdk.NewEvent(
414+
types.EventTypeChannelOpenConfirm,
415+
sdk.NewAttribute(types.AttributeKeyPortID, portID),
416+
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
417+
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
418+
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
419+
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
420+
),
421+
})
422+
378423
return nil
379424
}
380425

@@ -425,6 +470,17 @@ func (k Keeper) ChanCloseInit(
425470
channel.State = types.CLOSED
426471
k.SetChannel(ctx, portID, channelID, channel)
427472

473+
ctx.EventManager().EmitEvents(sdk.Events{
474+
sdk.NewEvent(
475+
types.EventTypeChannelCloseInit,
476+
sdk.NewAttribute(types.AttributeKeyPortID, portID),
477+
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
478+
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
479+
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
480+
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
481+
),
482+
})
483+
428484
return nil
429485
}
430486

@@ -492,5 +548,16 @@ func (k Keeper) ChanCloseConfirm(
492548
channel.State = types.CLOSED
493549
k.SetChannel(ctx, portID, channelID, channel)
494550

551+
ctx.EventManager().EmitEvents(sdk.Events{
552+
sdk.NewEvent(
553+
types.EventTypeChannelCloseConfirm,
554+
sdk.NewAttribute(types.AttributeKeyPortID, portID),
555+
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
556+
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
557+
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
558+
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
559+
),
560+
})
561+
495562
return nil
496563
}

0 commit comments

Comments
 (0)