diff --git a/modules/core/04-channel/v2/keeper/events.go b/modules/core/04-channel/v2/keeper/events.go index 75a9ff0efb8..5245b54901b 100644 --- a/modules/core/04-channel/v2/keeper/events.go +++ b/modules/core/04-channel/v2/keeper/events.go @@ -5,6 +5,8 @@ import ( "encoding/hex" "fmt" + "github.com/cosmos/gogoproto/proto" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" @@ -14,6 +16,11 @@ import ( func emitSendPacketEvents(ctx context.Context, packet types.Packet) { sdkCtx := sdk.UnwrapSDKContext(ctx) + encodedPacket, err := proto.Marshal(&packet) + if err != nil { + panic(err) + } + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeSendPacket, @@ -21,41 +28,24 @@ func emitSendPacketEvents(ctx context.Context, packet types.Packet) { sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel), sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)), sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.TimeoutTimestamp)), - sdk.NewAttribute(types.AttributeKeyPayloadLength, fmt.Sprintf("%d", len(packet.Payloads))), - sdk.NewAttribute(types.AttributeKeyVersion, packet.Payloads[0].Version), - sdk.NewAttribute(types.AttributeKeyEncoding, packet.Payloads[0].Encoding), - sdk.NewAttribute(types.AttributeKeyData, hex.EncodeToString(packet.Payloads[0].Value)), + sdk.NewAttribute(types.AttributeKeyPacketDataHex, hex.EncodeToString(encodedPacket)), ), sdk.NewEvent( sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), ), }) - - for i, payload := range packet.Payloads { - sdkCtx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeSendPayload, - 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.AttributeKeyVersion, payload.Version), - sdk.NewAttribute(types.AttributeKeyEncoding, payload.Encoding), - sdk.NewAttribute(types.AttributeKeyData, hex.EncodeToString(payload.Value)), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) - } } // emitRecvPacketEvents emits events for the RecvPacket handler. func emitRecvPacketEvents(ctx context.Context, packet types.Packet) { sdkCtx := sdk.UnwrapSDKContext(ctx) + encodedPacket, err := proto.Marshal(&packet) + if err != nil { + panic(err) + } + sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( types.EventTypeRecvPacket, @@ -63,50 +53,94 @@ func emitRecvPacketEvents(ctx context.Context, packet types.Packet) { sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel), sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)), sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.TimeoutTimestamp)), - sdk.NewAttribute(types.AttributeKeyPayloadLength, fmt.Sprintf("%d", len(packet.Payloads))), - sdk.NewAttribute(types.AttributeKeyVersion, packet.Payloads[0].Version), - sdk.NewAttribute(types.AttributeKeyEncoding, packet.Payloads[0].Encoding), - sdk.NewAttribute(types.AttributeKeyData, hex.EncodeToString(packet.Payloads[0].Value)), + sdk.NewAttribute(types.AttributeKeyPacketDataHex, hex.EncodeToString(encodedPacket)), ), sdk.NewEvent( sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), ), }) +} - for i, payload := range packet.Payloads { - sdkCtx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeRecvPayload, - 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.AttributeKeyVersion, payload.Version), - sdk.NewAttribute(types.AttributeKeyEncoding, payload.Encoding), - sdk.NewAttribute(types.AttributeKeyData, hex.EncodeToString(payload.Value)), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) +// emitWriteAcknowledgementEvents emits events for WriteAcknowledgement. +func emitWriteAcknowledgementEvents(ctx context.Context, packet types.Packet, ack types.Acknowledgement) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + encodedPacket, err := proto.Marshal(&packet) + if err != nil { + panic(err) } -} -// EmitWriteAcknowledgementEvents emits events for WriteAcknowledgement. -func EmitWriteAcknowledgementEvents(ctx context.Context, packet types.Packet, ack types.Acknowledgement) { - // TODO: https://github.com/cosmos/ibc-go/issues/7386 + encodedAck, err := proto.Marshal(&ack) + if err != nil { + panic(err) + } + + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeWriteAck, + sdk.NewAttribute(types.AttributeKeySrcChannel, packet.SourceChannel), + sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel), + sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)), + sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.TimeoutTimestamp)), + sdk.NewAttribute(types.AttributeKeyPacketDataHex, hex.EncodeToString(encodedPacket)), + sdk.NewAttribute(types.AttributeKeyAckDataHex, hex.EncodeToString(encodedAck)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) } -// 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) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + encodedPacket, err := proto.Marshal(&packet) + if err != nil { + panic(err) + } + + 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.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.TimeoutTimestamp)), + sdk.NewAttribute(types.AttributeKeyPacketDataHex, hex.EncodeToString(encodedPacket)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) } -// EmitTimeoutPacketEvents emits events for the TimeoutPacket handler. -func EmitTimeoutPacketEvents(ctx context.Context, packet types.Packet) { - // TODO: https://github.com/cosmos/ibc-go/issues/7386 +// emitTimeoutPacketEvents emits events for the TimeoutPacket handler. +func emitTimeoutPacketEvents(ctx context.Context, packet types.Packet) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + encodedPacket, err := proto.Marshal(&packet) + if err != nil { + panic(err) + } + + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeTimeoutPacket, + sdk.NewAttribute(types.AttributeKeySrcChannel, packet.SourceChannel), + sdk.NewAttribute(types.AttributeKeyDstChannel, packet.DestinationChannel), + sdk.NewAttribute(types.AttributeKeySequence, fmt.Sprintf("%d", packet.Sequence)), + sdk.NewAttribute(types.AttributeKeyTimeoutTimestamp, fmt.Sprintf("%d", packet.TimeoutTimestamp)), + sdk.NewAttribute(types.AttributeKeyPacketDataHex, hex.EncodeToString(encodedPacket)), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) } // emitCreateChannelEvent emits a channel create event. diff --git a/modules/core/04-channel/v2/keeper/packet.go b/modules/core/04-channel/v2/keeper/packet.go index 55553e18a53..392edb92db9 100644 --- a/modules/core/04-channel/v2/keeper/packet.go +++ b/modules/core/04-channel/v2/keeper/packet.go @@ -205,8 +205,7 @@ func (k Keeper) WriteAcknowledgement( k.Logger(ctx).Info("acknowledgement written", "sequence", strconv.FormatUint(packet.Sequence, 10), "dest-channel", packet.DestinationChannel) - // TODO: decide how relayers will reconstruct the packet as it is not being passed. - // EmitWriteAcknowledgementEvents(ctx, packet, ack) + emitWriteAcknowledgementEvents(ctx, packet, ack) // TODO: delete the packet that has been stored in ibc-core. @@ -230,7 +229,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) // This error indicates that the acknowledgement has already been relayed // or there is a misconfigured relayer attempting to prove an acknowledgement @@ -265,7 +264,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) return nil } @@ -308,7 +307,7 @@ func (k *Keeper) timeoutPacket( // check that the commitment has not been cleared and that it matches the packet sent by relayer commitment := k.GetPacketCommitment(ctx, packet.SourceChannel, packet.Sequence) if len(commitment) == 0 { - EmitTimeoutPacketEvents(ctx, packet) + emitTimeoutPacketEvents(ctx, packet) // 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 @@ -342,7 +341,7 @@ func (k *Keeper) timeoutPacket( k.Logger(ctx).Info("packet timed out", "sequence", strconv.FormatUint(packet.Sequence, 10), "src_channel_id", packet.SourceChannel, "dst_channel_id", packet.DestinationChannel) - EmitTimeoutPacketEvents(ctx, packet) + emitTimeoutPacketEvents(ctx, packet) return nil } diff --git a/modules/core/04-channel/v2/types/events.go b/modules/core/04-channel/v2/types/events.go index da7f25dd586..46ba862ac68 100644 --- a/modules/core/04-channel/v2/types/events.go +++ b/modules/core/04-channel/v2/types/events.go @@ -12,9 +12,9 @@ const ( EventTypeRegisterCounterparty = "register_counterparty" EventTypeSendPacket = "send_packet" EventTypeRecvPacket = "recv_packet" - - EventTypeSendPayload = "send_payload" - EventTypeRecvPayload = "recv_payload" + EventTypeTimeoutPacket = "timeout_packet" + EventTypeAcknowledgePacket = "acknowledge_packet" + EventTypeWriteAck = "write_acknowledgement" AttributeKeyChannelID = "channel_id" AttributeKeyClientID = "client_id" @@ -23,11 +23,8 @@ const ( AttributeKeyDstChannel = "packet_dest_channel" AttributeKeySequence = "packet_sequence" AttributeKeyTimeoutTimestamp = "packet_timeout_timestamp" - AttributeKeyPayloadLength = "packet_payload_length" - AttributeKeyPayloadSequence = "payload_sequence" - AttributeKeyVersion = "payload_version" - AttributeKeyEncoding = "payload_encoding" - AttributeKeyData = "payload_data" + AttributeKeyPacketDataHex = "packet_data_hex" + AttributeKeyAckDataHex = "acknowledgement_data_hex" ) // IBC channel events vars