Skip to content

Commit

Permalink
Fix/channel open/close events (#220)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
seantking and AdityaSripal committed Jun 18, 2021
1 parent 2e95805 commit 38b50b2
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 199 deletions.
186 changes: 0 additions & 186 deletions modules/core/04-channel/handler.go

This file was deleted.

67 changes: 67 additions & 0 deletions modules/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ func (k Keeper) ChanOpenInit(
telemetry.IncrCounter(1, "ibc", "channel", "open-init")
}()

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenInit,
sdk.NewAttribute(types.AttributeKeyPortID, portID),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, counterparty.PortId),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, counterparty.ChannelId),
sdk.NewAttribute(types.AttributeKeyConnectionID, connectionHops[0]),
),
})

return channelID, capKey, nil
}

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

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenTry,
sdk.NewAttribute(types.AttributeKeyPortID, portID),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
),
})

return channelID, capKey, nil
}

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

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenAck,
sdk.NewAttribute(types.AttributeKeyPortID, portID),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
),
})

return nil
}

Expand Down Expand Up @@ -375,6 +408,18 @@ func (k Keeper) ChanOpenConfirm(
defer func() {
telemetry.IncrCounter(1, "ibc", "channel", "open-confirm")
}()

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenConfirm,
sdk.NewAttribute(types.AttributeKeyPortID, portID),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
),
})

return nil
}

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

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelCloseInit,
sdk.NewAttribute(types.AttributeKeyPortID, portID),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
),
})

return nil
}

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

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelCloseConfirm,
sdk.NewAttribute(types.AttributeKeyPortID, portID),
sdk.NewAttribute(types.AttributeKeyChannelID, channelID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId),
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
),
})

return nil
}
Loading

0 comments on commit 38b50b2

Please sign in to comment.