Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add events for ack packet. #7584

Open
wants to merge 3 commits into
base: feat/ibc-eureka
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions modules/core/04-channel/v2/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,26 @@ func EmitWriteAcknowledgementEvents(ctx context.Context, packet types.Packet, ac
// TODO: https://github.com/cosmos/ibc-go/issues/7386
}

// EmitAcknowledgePacketEvents emits events for the AcknowledgePacket handler.
func EmitAcknowledgePacketEvents(ctx context.Context, packet types.Packet) {
// TODO: https://github.com/cosmos/ibc-go/issues/7386
// emitAcknowledgePacketEvents emits events for the AcknowledgePacket handler.
func emitAcknowledgePacketEvents(ctx context.Context, packet types.Packet, ack types.Acknowledgement) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

for i, ack := range ack.AppAcknowledgements {
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeAcknowledgePacket,
sdk.NewAttribute(types.AttributeKeySrcChannel, packet.SourceChannel),
sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel),
sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)),
sdk.NewAttribute(types.AttributeKeyPayloadSequence, fmt.Sprintf("%d", i)),
sdk.NewAttribute(types.AttributeKeyAcknowledgement, hex.EncodeToString(ack)),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
),
})
}
}

// EmitTimeoutPacketEvents emits events for the TimeoutPacket handler.
Expand Down
4 changes: 2 additions & 2 deletions modules/core/04-channel/v2/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (k *Keeper) acknowledgePacket(ctx context.Context, packet types.Packet, ack
commitment := k.GetPacketCommitment(ctx, packet.SourceChannel, packet.Sequence)
if len(commitment) == 0 {
// TODO: signal noop in events?
EmitAcknowledgePacketEvents(ctx, packet)
emitAcknowledgePacketEvents(ctx, packet, acknowledgement)

// This error indicates that the acknowledgement has already been relayed
// or there is a misconfigured relayer attempting to prove an acknowledgement
Expand Down Expand Up @@ -265,7 +265,7 @@ func (k *Keeper) acknowledgePacket(ctx context.Context, packet types.Packet, ack

k.Logger(ctx).Info("packet acknowledged", "sequence", strconv.FormatUint(packet.GetSequence(), 10), "source_channel_id", packet.GetSourceChannel(), "destination_channel_id", packet.GetDestinationChannel())

EmitAcknowledgePacketEvents(ctx, packet)
emitAcknowledgePacketEvents(ctx, packet, acknowledgement)

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions modules/core/04-channel/v2/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
EventTypeRegisterCounterparty = "register_counterparty"
EventTypeSendPacket = "send_packet"
EventTypeRecvPacket = "recv_packet"
EventTypeAcknowledgePacket = "acknowledge_packet"

EventTypeSendPayload = "send_payload"
EventTypeRecvPayload = "recv_payload"
Expand All @@ -28,6 +29,7 @@ const (
AttributeKeyVersion = "payload_version"
AttributeKeyEncoding = "payload_encoding"
AttributeKeyData = "payload_data"
AttributeKeyAcknowledgement = "acknowledgement"
)

// IBC channel events vars
Expand Down
Loading