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
7 changes: 7 additions & 0 deletions modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package host

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -105,14 +107,19 @@ 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)
logger.Error(fmt.Sprintf("%s sequence %d", err.Error(), packet.Sequence))
} else {
logger.Info("successfully handled packet sequence: %d", packet.Sequence)
}

// Emit an event indicating a successful or failed acknowledgement.
Expand Down
7 changes: 3 additions & 4 deletions modules/apps/27-interchain-accounts/host/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) ([]byt
case icatypes.EXECUTE_TX:
msgs, err := icatypes.DeserializeCosmosTx(k.cdc, data.Data)
if err != nil {
return nil, err
return nil, sdkerrors.Wrapf(err, "cannot deserialize cosmos Tx")
GNaD13 marked this conversation as resolved.
Show resolved Hide resolved
}

txResponse, err := k.executeTx(ctx, packet.SourcePort, packet.DestinationPort, packet.DestinationChannel, msgs)
if err != nil {
return nil, err
return nil, sdkerrors.Wrapf(err, "error executing Tx")
GNaD13 marked this conversation as resolved.
Show resolved Hide resolved
}

return txResponse, nil
default:
return nil, icatypes.ErrUnknownDataType
return nil, sdkerrors.Wrapf(icatypes.ErrUnknownDataType, "unknown data type")
GNaD13 marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
5 changes: 5 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,9 @@ func (im IBCModule) OnRecvPacket(
if err != nil {
ack = channeltypes.NewErrorAcknowledgement(err)
ackErr = err
logger.Error(fmt.Sprintf("%s sequence %d", ackErr.Error(), packet.Sequence))
} else {
logger.Info("successfully handled ICS-20 packet sequence: %d", packet.Sequence)
}
}

Expand Down
12 changes: 6 additions & 6 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,23 @@ func (k Keeper) sendTransfer(
func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData) error {
// validate packet data upon receiving
if err := data.ValidateBasic(); err != nil {
return err
return sdkerrors.Wrapf(err, "error validating ICS-20 transfer packet data")
}

if !k.GetReceiveEnabled(ctx) {
return types.ErrReceiveDisabled
return sdkerrors.Wrapf(types.ErrReceiveDisabled, "receive is disabled")
GNaD13 marked this conversation as resolved.
Show resolved Hide resolved
}

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

// 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)
return sdkerrors.Wrapf(types.ErrInvalidAmount, "unable to parse transfer amount: %s", data.Amount)
}

labels := []metrics.Label{
Expand Down Expand Up @@ -279,14 +279,14 @@ 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 {
return err
return sdkerrors.Wrapf(err, "cannot mint coins")
GNaD13 marked this conversation as resolved.
Show resolved Hide resolved
}

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

defer func() {
Expand Down