Skip to content

Commit

Permalink
fix: remove error from ics27 channel ack (#751)
Browse files Browse the repository at this point in the history
* removing error from channel ack in favour of event emission

* applying suggestions from PR

* Update modules/apps/27-interchain-accounts/host/keeper/events.go

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* Update modules/apps/27-interchain-accounts/types/errors.go

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* Update modules/apps/27-interchain-accounts/host/keeper/events.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 20, 2022
1 parent 89ffaaf commit 4fb75e8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ func (im IBCModule) OnRecvPacket(
ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)})

if err := im.keeper.OnRecvPacket(ctx, packet); err != nil {
ack = channeltypes.NewErrorAcknowledgement(err.Error())
ack = channeltypes.NewErrorAcknowledgement(icatypes.AcknowledgementError)

// Emit an event including the error msg
keeper.EmitWriteErrorAcknowledgementEvent(ctx, packet, err)
}

// NOTE: acknowledgement will be written synchronously during IBC handler execution.
Expand Down
20 changes: 20 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v3/modules/core/exported"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
)

// EmitWriteErrorAcknowledgementEvent emits an event signalling an error acknowledgement and including the error details
func EmitWriteErrorAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, err error) {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
icatypes.EventTypePacket,
sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName),
sdk.NewAttribute(icatypes.AttributeKeyAckError, err.Error()),
sdk.NewAttribute(icatypes.AttributeKeyHostChannelID, packet.GetDestChannel()),
),
)
}
6 changes: 6 additions & 0 deletions modules/apps/27-interchain-accounts/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const (
// AcknowledgementError defines a string constant included in error acknowledgements
// NOTE: Changing this const is state machine breaking as acknowledgements are written into state
AcknowledgementError = "error handling packet on host chain: see events for details"
)

var (
ErrUnknownDataType = sdkerrors.Register(ModuleName, 2, "unknown data type")
ErrAccountAlreadyExist = sdkerrors.Register(ModuleName, 3, "account already exist")
Expand Down
9 changes: 9 additions & 0 deletions modules/apps/27-interchain-accounts/types/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package types

// ICS27 Interchain Accounts events
const (
EventTypePacket = "ics27_packet"

AttributeKeyAckError = "error"
AttributeKeyHostChannelID = "host_channel_id"
)

0 comments on commit 4fb75e8

Please sign in to comment.