Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log message for debug error failed acknowledgement errors #3077

Merged
merged 13 commits into from
Feb 22, 2023
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ go 1.19
module github.com/cosmos/ibc-go/v7

require (
cosmossdk.io/api v0.2.6
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.6
cosmossdk.io/simapp v0.0.0-20221216140705-ee8890cf30e7
Expand Down Expand Up @@ -34,7 +35,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.8.0 // indirect
cloud.google.com/go/storage v1.27.0 // indirect
cosmossdk.io/api v0.2.6 // indirect
cosmossdk.io/core v0.3.2 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,18 @@ func (im IBCModule) OnRecvPacket(
packet channeltypes.Packet,
_ sdk.AccAddress,
) ibcexported.Acknowledgement {
logger := im.keeper.Logger(ctx)
if !im.keeper.IsHostEnabled(ctx) {
logger.Info("host submodule is disabled")
return channeltypes.NewErrorAcknowledgement(types.ErrHostSubModuleDisabled)
}

txResponse, err := im.keeper.OnRecvPacket(ctx, packet)
ack := channeltypes.NewResultAcknowledgement(txResponse)
if err != nil {
ack = channeltypes.NewErrorAcknowledgement(err)
} else {
logger.Info("successfully handled packet sequence: %d", packet.Sequence)
}

// Emit an event indicating a successful or failed acknowledgement.
Expand Down
10 changes: 9 additions & 1 deletion modules/apps/27-interchain-accounts/host/keeper/relay.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"fmt"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -14,27 +16,33 @@ import (
// OnRecvPacket handles a given interchain accounts packet on a destination host chain.
// If the transaction is successfully executed, the transaction response bytes will be returned.
func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) ([]byte, error) {
logger := k.Logger(ctx)
var data icatypes.InterchainAccountPacketData

if err := icatypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
// UnmarshalJSON errors are indeterminate and therefore are not wrapped and included in failed acks
return nil, sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data")
err := sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data")
logger.Error(err.Error())
return nil, err
}

switch data.Type {
case icatypes.EXECUTE_TX:
msgs, err := icatypes.DeserializeCosmosTx(k.cdc, data.Data)
if err != nil {
logger.Error(fmt.Sprintf("cannot deserialize cosmos Tx: %s", err.Error()))
return nil, err
}

txResponse, err := k.executeTx(ctx, packet.SourcePort, packet.DestinationPort, packet.DestinationChannel, msgs)
if err != nil {
logger.Error(fmt.Sprintf("error executing Tx: %s", err.Error()))
return nil, err
}

return txResponse, nil
default:
logger.Error("unknown data type")
return nil, icatypes.ErrUnknownDataType
}
}
Expand Down
2 changes: 2 additions & 0 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ func (im IBCMiddleware) OnRecvPacket(
packet channeltypes.Packet,
relayer sdk.AccAddress,
) exported.Acknowledgement {
logger := im.keeper.Logger(ctx)
if !im.keeper.IsFeeEnabled(ctx, packet.DestinationPort, packet.DestinationChannel) {
logger.Info("fee middleware module is disabled")
GNaD13 marked this conversation as resolved.
Show resolved Hide resolved
return im.app.OnRecvPacket(ctx, packet, relayer)
}

Expand Down
4 changes: 4 additions & 0 deletions modules/apps/transfer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ func (im IBCModule) OnRecvPacket(
packet channeltypes.Packet,
relayer sdk.AccAddress,
) ibcexported.Acknowledgement {
logger := im.keeper.Logger(ctx)
ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)})

var data types.FungibleTokenPacketData
var ackErr error
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
ackErr = sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot unmarshal ICS-20 transfer packet data")
logger.Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), packet.Sequence))
ack = channeltypes.NewErrorAcknowledgement(ackErr)
}

Expand All @@ -185,6 +187,8 @@ func (im IBCModule) OnRecvPacket(
if err != nil {
ack = channeltypes.NewErrorAcknowledgement(err)
ackErr = err
} else {
logger.Info("successfully handled ICS-20 packet sequence: %d", packet.Sequence)
}
}

Expand Down
15 changes: 13 additions & 2 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,25 +163,31 @@ func (k Keeper) sendTransfer(
// back tokens this chain originally transferred to it, the tokens are
// unescrowed and sent to the receiving address.
func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData) error {
logger := k.Logger(ctx)
// validate packet data upon receiving
if err := data.ValidateBasic(); err != nil {
logger.Error(fmt.Sprintf("error validating ICS-20 transfer packet data: %s", err.Error()))
return err
}

if !k.GetReceiveEnabled(ctx) {
logger.Error("receive is disabled")
return types.ErrReceiveDisabled
}

// decode the receiver address
receiver, err := sdk.AccAddressFromBech32(data.Receiver)
if err != nil {
logger.Error(fmt.Sprintf("cannot decode receiver address: %s", data.Receiver))
return err
}

// parse the transfer amount
transferAmount, ok := sdk.NewIntFromString(data.Amount)
if !ok {
return sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount (%s) into math.Int", data.Amount)
err := sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount: %s", data.Amount)
logger.Error(err.Error())
return err
}

labels := []metrics.Label{
Expand Down Expand Up @@ -216,7 +222,9 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
token := sdk.NewCoin(denom, transferAmount)

if k.bankKeeper.BlockedAddr(receiver) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver)
err := sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", receiver)
logger.Error(err.Error())
return err
}

// unescrow tokens
Expand All @@ -226,6 +234,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
// counterparty module. The bug may occur in bank or any part of the code that allows
// the escrow address to be drained. A malicious counterparty module could drain the
// escrow address by allowing more tokens to be sent back then were escrowed.
logger.Error(fmt.Sprintf("unable to unescrow tokens: %s", err.Error()))
return sdkerrors.Wrap(err, "unable to unescrow tokens, this may be caused by a malicious counterparty module or a bug: please open an issue on counterparty module")
}

Expand Down Expand Up @@ -279,13 +288,15 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
if err := k.bankKeeper.MintCoins(
ctx, types.ModuleName, sdk.NewCoins(voucher),
); err != nil {
logger.Error(fmt.Sprintf("cannot mint coins: %s", err.Error()))
return err
}

// send to receiver
if err := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, types.ModuleName, receiver, sdk.NewCoins(voucher),
); err != nil {
logger.Error(fmt.Sprintf("cannot send coins to receiver %s: %s", receiver.String(), err.Error()))
return err
}

Expand Down