Skip to content

Commit

Permalink
Hex Packet Data (#144)
Browse files Browse the repository at this point in the history
* add non-breaking event attribute

* CHANGELOG

* add migration doc
  • Loading branch information
AdityaSripal authored Apr 28, 2021
1 parent cd7077e commit 5b9e3c0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* (modules/core/04-channel) [\#7949](https://github.com/cosmos/cosmos-sdk/issues/7949) Standardized channel `Acknowledgement` moved to its own file. Codec registration redundancy removed.
* (modules/core/04-channel) [\#144](https://github.com/cosmos/ibc-go/pull/144) Introduced a `packet_data_hex` attribute to emit the hex-encoded packet data in events. This allows for raw binary (proto-encoded message) to be sent over events and decoded correctly on relayer. Original `packet_data` is DEPRECATED. All relayers and IBC event consumers are encouraged to switch to `packet_data_hex` as soon as possible.
* (modules/light-clients/07-tendermint) [\#125](https://github.com/cosmos/ibc-go/pull/125) Implement efficient iteration of consensus states and pruning of earliest expired consensus state on UpdateClient.

## IBC in the Cosmos SDK Repository
Expand Down
4 changes: 4 additions & 0 deletions docs/migrations/ibc-migration-043.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ The gRPC querier service endpoints have changed slightly. The previous files use
Application developers need to update their `OnRecvPacket` callback logic.

The `OnRecvPacket` callback has been modified to only return the acknowledgement. The acknowledgement returned must implement the `Acknowledgement` interface. The acknowledgement should indicate if it represents a successful processing of a packet by returning true on `Success()` and false in all other cases. A return value of false on `Success()` will result in all state changes which occurred in the callback being discarded. More information can be found in the [documentation](https://github.com/cosmos/ibc-go/blob/main/docs/custom.md#receiving-packets).

## IBC Event changes

The `packet_data` attribute has been deprecated in favor of `packet_data_hex`, in order to provide standardized encoding/decoding of packet data in events. While the `packet_data` event still exists, all relayers and IBC Event consumers are strongly encouraged to switch over to using `packet_data_hex` as soon as possible.
10 changes: 7 additions & 3 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"bytes"
"encoding/hex"
"fmt"
"time"

Expand Down Expand Up @@ -120,7 +121,8 @@ func (k Keeper) SendPacket(
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeSendPacket,
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())), // DEPRECATED
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())),
Expand Down Expand Up @@ -283,7 +285,8 @@ func (k Keeper) RecvPacket(
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeRecvPacket,
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())), // DEPRECATED
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())),
Expand Down Expand Up @@ -367,7 +370,8 @@ func (k Keeper) WriteAcknowledgement(
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeWriteAck,
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())),
sdk.NewAttribute(types.AttributeKeyData, string(packet.GetData())), // DEPRECATED
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())),
Expand Down
5 changes: 4 additions & 1 deletion modules/core/04-channel/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const (
EventTypeAcknowledgePacket = "acknowledge_packet"
EventTypeTimeoutPacket = "timeout_packet"

AttributeKeyData = "packet_data"
// NOTE: DEPRECATED in favor of AttributeKeyDataHex
AttributeKeyData = "packet_data"

AttributeKeyDataHex = "packet_data_hex"
AttributeKeyAck = "packet_ack"
AttributeKeyTimeoutHeight = "packet_timeout_height"
AttributeKeyTimeoutTimestamp = "packet_timeout_timestamp"
Expand Down

0 comments on commit 5b9e3c0

Please sign in to comment.