From fd31079520fde539f50f75703c1a70b3989bac61 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 11 Feb 2022 18:46:20 +0100 Subject: [PATCH 1/5] feat: emit EventTypeSendIncentivizedPacket event on EscrowPacket --- modules/apps/29-fee/keeper/escrow.go | 12 ++++++++++++ modules/apps/29-fee/types/events.go | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 1eb24cedc86..470866293f4 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -7,6 +7,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ) // EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow @@ -38,6 +39,17 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee types.IdentifiedP // Store fee in state for reference later k.SetFeeInEscrow(ctx, identifiedFee) + + // Emit event so that relayers know a packet is ready to be relayed + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeSendIncentivizedPacket, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, identifiedFee.PacketId.PortId), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, identifiedFee.PacketId.ChannelId), + sdk.NewAttribute(channeltypes.AttributeKeySequence, string(identifiedFee.PacketId.Sequence)), + ), + ) + return nil } diff --git a/modules/apps/29-fee/types/events.go b/modules/apps/29-fee/types/events.go index 4b8d5ee8c95..e3d010c4a93 100644 --- a/modules/apps/29-fee/types/events.go +++ b/modules/apps/29-fee/types/events.go @@ -1,4 +1,6 @@ package types // 29-fee events -const () +const ( + EventTypeSendIncentivizedPacket = "send_incentivized_packet" +) From 1c5e749eb18b116aba94fa769663715159a25c2c Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 11 Feb 2022 18:55:20 +0100 Subject: [PATCH 2/5] fix: string conversion --- modules/apps/29-fee/keeper/escrow.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 470866293f4..12dacb035a6 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -40,13 +40,13 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee types.IdentifiedP // Store fee in state for reference later k.SetFeeInEscrow(ctx, identifiedFee) - // Emit event so that relayers know a packet is ready to be relayed + // Emit event so that relayers know an incentivized packet is ready to be relayed ctx.EventManager().EmitEvent( sdk.NewEvent( types.EventTypeSendIncentivizedPacket, sdk.NewAttribute(channeltypes.AttributeKeyPortID, identifiedFee.PacketId.PortId), sdk.NewAttribute(channeltypes.AttributeKeyChannelID, identifiedFee.PacketId.ChannelId), - sdk.NewAttribute(channeltypes.AttributeKeySequence, string(identifiedFee.PacketId.Sequence)), + sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(identifiedFee.PacketId.Sequence)), ), ) From 0f5ffe5b132cbd6e15ab22c19debfe94ffb7b899 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 15 Feb 2022 17:09:13 +0100 Subject: [PATCH 3/5] refactor: add helper fn for emit event --- modules/apps/29-fee/keeper/escrow.go | 11 +---------- modules/apps/29-fee/keeper/events.go | 24 ++++++++++++++++++++++++ modules/apps/29-fee/types/events.go | 2 +- modules/apps/29-fee/types/keys.go | 4 ++++ 4 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 modules/apps/29-fee/keeper/events.go diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index 12dacb035a6..a462b395ef9 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -7,7 +7,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ) // EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow @@ -40,15 +39,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee types.IdentifiedP // Store fee in state for reference later k.SetFeeInEscrow(ctx, identifiedFee) - // Emit event so that relayers know an incentivized packet is ready to be relayed - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeSendIncentivizedPacket, - sdk.NewAttribute(channeltypes.AttributeKeyPortID, identifiedFee.PacketId.PortId), - sdk.NewAttribute(channeltypes.AttributeKeyChannelID, identifiedFee.PacketId.ChannelId), - sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(identifiedFee.PacketId.Sequence)), - ), - ) + EmitIncentivizedPacket(ctx, identifiedFee) return nil } diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go new file mode 100644 index 00000000000..a8d8e264942 --- /dev/null +++ b/modules/apps/29-fee/keeper/events.go @@ -0,0 +1,24 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" +) + +// Emit event so that relayers know an incentivized packet is ready to be relayed +func EmitIncentivizedPacket(ctx sdk.Context, identifiedFee types.IdentifiedPacketFee) { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeIncentivizedPacket, + sdk.NewAttribute(channeltypes.AttributeKeyPortID, identifiedFee.PacketId.PortId), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, identifiedFee.PacketId.ChannelId), + sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(identifiedFee.PacketId.Sequence)), + sdk.NewAttribute(types.AttributeKeyRecvFee, fmt.Sprint(identifiedFee.Fee.RecvFee)), + sdk.NewAttribute(types.AttributeKeyAckFee, fmt.Sprint(identifiedFee.Fee.AckFee)), + sdk.NewAttribute(types.AttributeKeyTimeoutFee, fmt.Sprint(identifiedFee.Fee.TimeoutFee)), + ), + ) +} diff --git a/modules/apps/29-fee/types/events.go b/modules/apps/29-fee/types/events.go index e3d010c4a93..2c63bc0dcc8 100644 --- a/modules/apps/29-fee/types/events.go +++ b/modules/apps/29-fee/types/events.go @@ -2,5 +2,5 @@ package types // 29-fee events const ( - EventTypeSendIncentivizedPacket = "send_incentivized_packet" + EventTypeIncentivizedPacket = "incentivized_ibc_packet" ) diff --git a/modules/apps/29-fee/types/keys.go b/modules/apps/29-fee/types/keys.go index 2f26b859afc..a390a6ece33 100644 --- a/modules/apps/29-fee/types/keys.go +++ b/modules/apps/29-fee/types/keys.go @@ -32,6 +32,10 @@ const ( // ForwardRelayerPrefix is the key prefix for forward relayer addresses stored in state for async acknowledgements ForwardRelayerPrefix = "forwardRelayer" + + AttributeKeyRecvFee = "recv_fee" + AttributeKeyAckFee = "ack_fee" + AttributeKeyTimeoutFee = "timeout_fee" ) // FeeEnabledKey returns the key that stores a flag to determine if fee logic should From d41c83f901a25edb1b1b54c1f65103f5d9774996 Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 17 Feb 2022 15:23:31 +0100 Subject: [PATCH 4/5] chore: godoc --- modules/apps/29-fee/keeper/events.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go index a8d8e264942..9b9380e0afe 100644 --- a/modules/apps/29-fee/keeper/events.go +++ b/modules/apps/29-fee/keeper/events.go @@ -4,11 +4,12 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ) -// Emit event so that relayers know an incentivized packet is ready to be relayed +// EmitIncentivizedPacket emits an event so that relayers know an incentivized packet is ready to be relayed func EmitIncentivizedPacket(ctx sdk.Context, identifiedFee types.IdentifiedPacketFee) { ctx.EventManager().EmitEvent( sdk.NewEvent( From d3944067b5b838193995452afaed539b8496ef7e Mon Sep 17 00:00:00 2001 From: Sean King Date: Thu, 17 Feb 2022 15:26:17 +0100 Subject: [PATCH 5/5] nit: use .String()) --- modules/apps/29-fee/keeper/events.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/apps/29-fee/keeper/events.go b/modules/apps/29-fee/keeper/events.go index 9b9380e0afe..64c44a34ea0 100644 --- a/modules/apps/29-fee/keeper/events.go +++ b/modules/apps/29-fee/keeper/events.go @@ -17,9 +17,9 @@ func EmitIncentivizedPacket(ctx sdk.Context, identifiedFee types.IdentifiedPacke sdk.NewAttribute(channeltypes.AttributeKeyPortID, identifiedFee.PacketId.PortId), sdk.NewAttribute(channeltypes.AttributeKeyChannelID, identifiedFee.PacketId.ChannelId), sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(identifiedFee.PacketId.Sequence)), - sdk.NewAttribute(types.AttributeKeyRecvFee, fmt.Sprint(identifiedFee.Fee.RecvFee)), - sdk.NewAttribute(types.AttributeKeyAckFee, fmt.Sprint(identifiedFee.Fee.AckFee)), - sdk.NewAttribute(types.AttributeKeyTimeoutFee, fmt.Sprint(identifiedFee.Fee.TimeoutFee)), + sdk.NewAttribute(types.AttributeKeyRecvFee, identifiedFee.Fee.RecvFee.String()), + sdk.NewAttribute(types.AttributeKeyAckFee, identifiedFee.Fee.AckFee.String()), + sdk.NewAttribute(types.AttributeKeyTimeoutFee, identifiedFee.Fee.TimeoutFee.String()), ), ) }