-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perform a no-op on redundant relay messages (#268)
* create initial changes for delivertx handling * handle closed channel no-ops, fix tests * self review nits * add changelog * add events for no op messages * add back comment
- Loading branch information
1 parent
76ad03e
commit 4a83b05
Showing
11 changed files
with
307 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package keeper | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/modules/core/04-channel/types" | ||
"github.com/cosmos/ibc-go/modules/core/exported" | ||
) | ||
|
||
// 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 sdk.Context, packet exported.PacketI, channel types.Channel) { | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeRecvPacket, | ||
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())), | ||
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]), | ||
), | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
), | ||
}) | ||
} | ||
|
||
// 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 sdk.Context, packet exported.PacketI, channel types.Channel) { | ||
ctx.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]), | ||
), | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
), | ||
}) | ||
} | ||
|
||
// 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 sdk.Context, packet exported.PacketI, channel types.Channel) { | ||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeTimeoutPacket, | ||
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()), | ||
), | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.