Skip to content

Commit

Permalink
emit cumulative fees
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed May 16, 2022
1 parent 2709c24 commit acda4e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/apps/29-fee/keeper/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (k Keeper) escrowPacketFee(ctx sdk.Context, packetID channeltypes.PacketId,
packetFees := types.NewPacketFees(fees)
k.SetFeesInEscrow(ctx, packetID, packetFees)

EmitIncentivizedPacket(ctx, packetID, packetFee)
EmitIncentivizedPacketEvent(ctx, packetID, packetFees)

return nil
}
Expand Down
23 changes: 18 additions & 5 deletions modules/apps/29-fee/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,30 @@ import (
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
)

// EmitIncentivizedPacket emits an event so that relayers know an incentivized packet is ready to be relayed
func EmitIncentivizedPacket(ctx sdk.Context, packetID channeltypes.PacketId, packetFee types.PacketFee) {
// EmitIncentivizedPacketEvent emits an event containing information on the total amount of fees incentivizing
// a specific packet. It should be emitted on every fee escrowed for the given packetID.
func EmitIncentivizedPacketEvent(ctx sdk.Context, packetID channeltypes.PacketId, packetFees types.PacketFees) {
var (
totalRecvFees sdk.Coins
totalAckFees sdk.Coins
totalTimeoutFees sdk.Coins
)

for _, fee := range packetFees.PacketFees {
totalRecvFees.Add(fee.Fee.RecvFee...)
totalAckFees.Add(fee.Fee.AckFee...)
totalTimeoutFees.Add(fee.Fee.TimeoutFee...)
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeIncentivizedPacket,
sdk.NewAttribute(channeltypes.AttributeKeyPortID, packetID.PortId),
sdk.NewAttribute(channeltypes.AttributeKeyChannelID, packetID.ChannelId),
sdk.NewAttribute(channeltypes.AttributeKeySequence, fmt.Sprint(packetID.Sequence)),
sdk.NewAttribute(types.AttributeKeyRecvFee, packetFee.Fee.RecvFee.String()),
sdk.NewAttribute(types.AttributeKeyAckFee, packetFee.Fee.AckFee.String()),
sdk.NewAttribute(types.AttributeKeyTimeoutFee, packetFee.Fee.TimeoutFee.String()),
sdk.NewAttribute(types.AttributeKeyRecvFee, totalRecvFees.String()),
sdk.NewAttribute(types.AttributeKeyAckFee, totalAckFees.String()),
sdk.NewAttribute(types.AttributeKeyTimeoutFee, totalTimeoutFees.String()),
),
)
}

0 comments on commit acda4e9

Please sign in to comment.