Skip to content

Commit

Permalink
Merge branch 'feat/ibc-eureka' into damian/7478-packet-ack-query
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Oct 23, 2024
2 parents aefd9d3 + 4e5e5c3 commit b8df8b2
Show file tree
Hide file tree
Showing 40 changed files with 890 additions and 1,217 deletions.
5 changes: 0 additions & 5 deletions modules/core/02-client/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ const (
// AllowAllClients is the value that if set in AllowedClients param
// would allow any wired up light client modules to be allowed
AllowAllClients = "*"

// CounterpartyKey is the key used to store counterparty in the client store.
// the counterparty key is imported from types instead of host because
// the counterparty key is not a part of the ics-24 host specification
CounterpartyKey = "counterparty"
)

// FormatClientIdentifier returns the client identifier with the sequence appended.
Expand Down
164 changes: 64 additions & 100 deletions modules/core/04-channel/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,25 @@ func emitChannelCloseConfirmEvent(ctx context.Context, portID string, channelID

// emitSendPacketEvent emits an event with packet data along with other packet information for relayer
// to pick up and relay to other chain
func EmitSendPacketEvent(ctx context.Context, packet types.Packet, channel *types.Channel, timeoutHeight exported.Height) {
func emitSendPacketEvent(ctx context.Context, packet types.Packet, channel types.Channel, timeoutHeight exported.Height) {
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917
eventAttributes := []sdk.Attribute{
sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, timeoutHeight.String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
}

if channel != nil {
eventAttributes = append(eventAttributes,
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeSendPacket,
sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, timeoutHeight.String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()),
// we only support 1-hop packets now, and that is the most important hop for a relayer
// (is it going to a chain I am connected to)
sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), // DEPRECATED
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
)
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeSendPacket,
eventAttributes...,
),
sdk.NewEvent(
sdk.EventTypeMessage,
Expand All @@ -163,35 +155,27 @@ func EmitSendPacketEvent(ctx context.Context, packet types.Packet, channel *type
})
}

// EmitRecvPacketEvent emits a receive packet event. It will be emitted both the first time a packet
// emitRecvPacketEvent emits a receive packet event. It will be emitted both the first time a packet
// is received for a certain sequence and for all duplicate receives.
func EmitRecvPacketEvent(ctx context.Context, packet types.Packet, channel *types.Channel) {
func emitRecvPacketEvent(ctx context.Context, packet types.Packet, channel types.Channel) {
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917
eventAttributes := []sdk.Attribute{
sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
}

if channel != nil {
eventAttributes = append(eventAttributes,
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRecvPacket,
sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()),
// we only support 1-hop packets now, and that is the most important hop for a relayer
// (is it going to a chain I am connected to)
sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), // DEPRECATED
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
)
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRecvPacket,
eventAttributes...,
),
sdk.NewEvent(
sdk.EventTypeMessage,
Expand All @@ -200,35 +184,27 @@ func EmitRecvPacketEvent(ctx context.Context, packet types.Packet, channel *type
})
}

// EmitWriteAcknowledgementEvent emits an event that the relayer can query for
func EmitWriteAcknowledgementEvent(ctx context.Context, packet types.Packet, channel *types.Channel, acknowledgement []byte) {
// emitWriteAcknowledgementEvent emits an event that the relayer can query for
func emitWriteAcknowledgementEvent(ctx context.Context, packet types.Packet, channel types.Channel, acknowledgement []byte) {
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917
eventAttributes := []sdk.Attribute{
sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
sdk.NewAttribute(types.AttributeKeyAckHex, hex.EncodeToString(acknowledgement)),
}

if channel != nil {
eventAttributes = append(eventAttributes,
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeWriteAck,
sdk.NewAttribute(types.AttributeKeyDataHex, hex.EncodeToString(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
sdk.NewAttribute(types.AttributeKeyAckHex, hex.EncodeToString(acknowledgement)),
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()),
// we only support 1-hop packets now, and that is the most important hop for a relayer
// (is it going to a chain I am connected to)
sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), // DEPRECATED
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
)
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeWriteAck,
eventAttributes...,
),
sdk.NewEvent(
sdk.EventTypeMessage,
Expand All @@ -237,34 +213,26 @@ func EmitWriteAcknowledgementEvent(ctx context.Context, packet types.Packet, cha
})
}

// EmitAcknowledgePacketEvent emits an acknowledge packet event. It will be emitted both the first time
// emitAcknowledgePacketEvent emits an acknowledge packet event. It will be emitted both the first time
// a packet is acknowledged for a certain sequence and for all duplicate acknowledgements.
func EmitAcknowledgePacketEvent(ctx context.Context, packet types.Packet, channel *types.Channel) {
func emitAcknowledgePacketEvent(ctx context.Context, packet types.Packet, channel types.Channel) {
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223
eventAttributes := []sdk.Attribute{
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
}

if channel != nil {
eventAttributes = append(eventAttributes,
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeAcknowledgePacket,
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()),
// we only support 1-hop packets now, and that is the most important hop for a relayer
// (is it going to a chain I am connected to)
sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), // DEPRECATED
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
)
}

sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeAcknowledgePacket,
eventAttributes...,
),
sdk.NewEvent(
sdk.EventTypeMessage,
Expand All @@ -275,28 +243,24 @@ func EmitAcknowledgePacketEvent(ctx context.Context, packet types.Packet, channe

// emitTimeoutPacketEvent emits a timeout packet event. It will be emitted both the first time a packet
// is timed out for a certain sequence and for all duplicate timeouts.
func EmitTimeoutPacketEvent(ctx context.Context, packet types.Packet, channel *types.Channel) {
func emitTimeoutPacketEvent(ctx context.Context, packet types.Packet, channel types.Channel) {
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223
eventAttributes := []sdk.Attribute{
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
}

if channel != nil {
eventAttributes = append(eventAttributes,
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()),
)
}
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeTimeoutPacket,
eventAttributes...,
sdk.NewAttribute(types.AttributeKeyTimeoutHeight, packet.GetTimeoutHeight().String()),
sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.GetTimeoutTimestamp())),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.GetSequence())),
sdk.NewAttribute(types.AttributeKeySrcPort, packet.GetSourcePort()),
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.GetSourceChannel()),
sdk.NewAttribute(types.AttributeKeyDstPort, packet.GetDestPort()),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.GetDestChannel()),
sdk.NewAttribute(types.AttributeKeyChannelOrdering, channel.Ordering.String()),
// we only support 1-hop packets now, and that is the most important hop for a relayer
// (is it going to a chain I am connected to)
sdk.NewAttribute(types.AttributeKeyConnection, channel.ConnectionHops[0]), // DEPRECATED
sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]),
),
sdk.NewEvent(
sdk.EventTypeMessage,
Expand Down
14 changes: 7 additions & 7 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (k *Keeper) SendPacket(
k.SetNextSequenceSend(ctx, sourcePort, sourceChannel, sequence+1)
k.SetPacketCommitment(ctx, sourcePort, sourceChannel, packet.GetSequence(), commitment)

EmitSendPacketEvent(sdkCtx, packet, &channel, timeoutHeight)
emitSendPacketEvent(sdkCtx, packet, channel, timeoutHeight)

k.Logger(ctx).Info(
"packet sent",
Expand Down Expand Up @@ -190,7 +190,7 @@ func (k *Keeper) RecvPacket(
)

// emit an event that the relayer can query for
EmitRecvPacketEvent(sdkCtx, packet, &channel)
emitRecvPacketEvent(sdkCtx, packet, channel)

return channel.Version, nil
}
Expand All @@ -215,7 +215,7 @@ func (k *Keeper) applyReplayProtection(ctx context.Context, packet types.Packet,
// by the increase of the recvStartSequence.
_, found := k.GetPacketReceipt(ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
if found {
EmitRecvPacketEvent(sdkCtx, packet, &channel)
emitRecvPacketEvent(sdkCtx, packet, channel)
// This error indicates that the packet has already been relayed. Core IBC will
// treat this error as a no-op in order to prevent an entire relay transaction
// from failing and consuming unnecessary fees.
Expand All @@ -239,7 +239,7 @@ func (k *Keeper) applyReplayProtection(ctx context.Context, packet types.Packet,
}

if packet.GetSequence() < nextSequenceRecv {
EmitRecvPacketEvent(sdkCtx, packet, &channel)
emitRecvPacketEvent(sdkCtx, packet, channel)
// This error indicates that the packet has already been relayed. Core IBC will
// treat this error as a no-op in order to prevent an entire relay transaction
// from failing and consuming unnecessary fees.
Expand Down Expand Up @@ -335,7 +335,7 @@ func (k *Keeper) WriteAcknowledgement(
)

sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/7223
EmitWriteAcknowledgementEvent(sdkCtx, packet.(types.Packet), &channel, bz)
emitWriteAcknowledgementEvent(sdkCtx, packet.(types.Packet), channel, bz)

return nil
}
Expand Down Expand Up @@ -392,7 +392,7 @@ func (k *Keeper) AcknowledgePacket(
commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())

if len(commitment) == 0 {
EmitAcknowledgePacketEvent(ctx, packet, &channel)
emitAcknowledgePacketEvent(ctx, packet, channel)
// This error indicates that the acknowledgement has already been relayed
// or there is a misconfigured relayer attempting to prove an acknowledgement
// for a packet never sent. Core IBC will treat this error as a no-op in order to
Expand Down Expand Up @@ -454,7 +454,7 @@ func (k *Keeper) AcknowledgePacket(
)

// emit an event marking that we have processed the acknowledgement
EmitAcknowledgePacketEvent(ctx, packet, &channel)
emitAcknowledgePacketEvent(ctx, packet, channel)

// if an upgrade is in progress, handling packet flushing and update channel state appropriately
if channel.State == types.FLUSHING {
Expand Down
6 changes: 3 additions & 3 deletions modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (k *Keeper) TimeoutPacket(
commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())

if len(commitment) == 0 {
EmitTimeoutPacketEvent(ctx, packet, &channel)
emitTimeoutPacketEvent(ctx, packet, channel)
// This error indicates that the timeout has already been relayed
// or there is a misconfigured relayer attempting to prove a timeout
// for a packet never sent. Core IBC will treat this error as a no-op in order to
Expand Down Expand Up @@ -167,7 +167,7 @@ func (k *Keeper) timeoutExecuted(
)

// emit an event marking that we have processed the timeout
EmitTimeoutPacketEvent(ctx, packet, &channel)
emitTimeoutPacketEvent(ctx, packet, channel)

return nil
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func (k *Keeper) TimeoutOnClose(
commitment := k.GetPacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())

if len(commitment) == 0 {
EmitTimeoutPacketEvent(ctx, packet, &channel)
emitTimeoutPacketEvent(ctx, packet, channel)
// This error indicates that the timeout has already been relayed
// or there is a misconfigured relayer attempting to prove a timeout
// for a packet never sent. Core IBC will treat this error as a no-op in order to
Expand Down
Loading

0 comments on commit b8df8b2

Please sign in to comment.