Skip to content

Commit

Permalink
handle memo on provider side
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Sep 19, 2024
1 parent eefeaf9 commit 9d8a4ad
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions x/ccv/provider/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper"
"github.com/cosmos/interchain-security/v6/x/ccv/provider/types"
ccvtypes "github.com/cosmos/interchain-security/v6/x/ccv/types"
)

var _ porttypes.Middleware = &IBCMiddleware{}
Expand Down Expand Up @@ -113,6 +114,8 @@ func (im IBCMiddleware) OnRecvPacket(
packet channeltypes.Packet,
relayer sdk.AccAddress,
) exported.Acknowledgement {
logger := im.keeper.Logger(ctx)

// executes the IBC transfer OnRecv logic
ack := im.app.OnRecvPacket(ctx, packet, relayer)

Expand All @@ -121,12 +124,6 @@ func (im IBCMiddleware) OnRecvPacket(
// that the packet data is valid and can be safely
// deserialized without checking errors.
if ack.Success() {
// execute the middleware logic only if the sender is a consumer chain
consumerId, err := im.keeper.IdentifyConsumerIdFromIBCPacket(ctx, packet)
if err != nil {
return ack
}

// extract the coin info received from the packet data
var data ibctransfertypes.FungibleTokenPacketData
_ = types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data)
Expand All @@ -137,6 +134,29 @@ func (im IBCMiddleware) OnRecvPacket(
return ack
}

consumerId := ""
// check if the transfer has the reward memo
if rewardMemo, err := ccvtypes.GetRewardMemoFromTransferMemo(data.Memo); err != nil {
// check if the transfer is on a channel with the same underlying
// client as the CCV channel
consumerId, err = im.keeper.IdentifyConsumerIdFromIBCPacket(ctx, packet)
if err != nil {
if data.Memo == "consumer chain rewards distribution" {
// log error message
logger.Error(
"received token transfer with ICS reward from unknown consumer",
"packet", packet.String(),
"fungibleTokenPacketData", data.String(),
"error", err.Error(),
)

}
return ack
}
} else {
consumerId = rewardMemo.ConsumerId
}

coinAmt, _ := math.NewIntFromString(data.Amount)
coinDenom := GetProviderDenom(data.Denom, packet)

Expand Down

0 comments on commit 9d8a4ad

Please sign in to comment.