From 7d7d016a3f944f0eb05dd7f82dc49e98713becf9 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 18 Jan 2022 11:27:23 +0100 Subject: [PATCH 1/5] removing error from channel ack in favour of event emission --- .../apps/27-interchain-accounts/host/ibc_module.go | 11 ++++++++++- modules/apps/27-interchain-accounts/types/events.go | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 modules/apps/27-interchain-accounts/types/events.go diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index bf847349c69..4171c0afc16 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -111,7 +111,16 @@ 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("error occurred handling packet on destination chain") + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + icatypes.EventTypePacket, + sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), + sdk.NewAttribute(icatypes.AttributeKeyControllerPort, packet.GetSourcePort()), + sdk.NewAttribute(icatypes.AttributeKeyAckError, err.Error()), + ), + ) } // NOTE: acknowledgement will be written synchronously during IBC handler execution. diff --git a/modules/apps/27-interchain-accounts/types/events.go b/modules/apps/27-interchain-accounts/types/events.go new file mode 100644 index 00000000000..56f7b1df26f --- /dev/null +++ b/modules/apps/27-interchain-accounts/types/events.go @@ -0,0 +1,9 @@ +package types + +// ICS27 Interchain Accounts events +const ( + EventTypePacket = "ics27_packet" + + AttributeKeyAckError = "error" + AttributeKeyControllerPort = "controller_port" +) From 9baa0c96be8f137c5450bf7f77af250c9502e0f7 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 19 Jan 2022 16:57:14 +0100 Subject: [PATCH 2/5] applying suggestions from PR --- .../27-interchain-accounts/host/ibc_module.go | 14 ++++--------- .../host/keeper/events.go | 20 +++++++++++++++++++ .../27-interchain-accounts/types/errors.go | 6 ++++++ .../27-interchain-accounts/types/events.go | 4 ++-- 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 modules/apps/27-interchain-accounts/host/keeper/events.go diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 4171c0afc16..15606eb9e74 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -111,16 +111,10 @@ func (im IBCModule) OnRecvPacket( ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) if err := im.keeper.OnRecvPacket(ctx, packet); err != nil { - ack = channeltypes.NewErrorAcknowledgement("error occurred handling packet on destination chain") - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - icatypes.EventTypePacket, - sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), - sdk.NewAttribute(icatypes.AttributeKeyControllerPort, packet.GetSourcePort()), - sdk.NewAttribute(icatypes.AttributeKeyAckError, 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. diff --git a/modules/apps/27-interchain-accounts/host/keeper/events.go b/modules/apps/27-interchain-accounts/host/keeper/events.go new file mode 100644 index 00000000000..8dbf234b114 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/events.go @@ -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 acknowledmgent 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()), + ), + ) +} diff --git a/modules/apps/27-interchain-accounts/types/errors.go b/modules/apps/27-interchain-accounts/types/errors.go index e0a5c141de9..c082b52a35a 100644 --- a/modules/apps/27-interchain-accounts/types/errors.go +++ b/modules/apps/27-interchain-accounts/types/errors.go @@ -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 destination chain: see events for details" +) + var ( ErrUnknownDataType = sdkerrors.Register(ModuleName, 2, "unknown data type") ErrAccountAlreadyExist = sdkerrors.Register(ModuleName, 3, "account already exist") diff --git a/modules/apps/27-interchain-accounts/types/events.go b/modules/apps/27-interchain-accounts/types/events.go index 56f7b1df26f..04882a6a644 100644 --- a/modules/apps/27-interchain-accounts/types/events.go +++ b/modules/apps/27-interchain-accounts/types/events.go @@ -4,6 +4,6 @@ package types const ( EventTypePacket = "ics27_packet" - AttributeKeyAckError = "error" - AttributeKeyControllerPort = "controller_port" + AttributeKeyAckError = "error" + AttributeKeyHostChannelID = "host_channel_id" ) From 07503d6512704e505ddbb1a946c8e31eafdd5bb0 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 20 Jan 2022 09:47:52 +0100 Subject: [PATCH 3/5] Update modules/apps/27-interchain-accounts/host/keeper/events.go Co-authored-by: Carlos Rodriguez --- modules/apps/27-interchain-accounts/host/keeper/events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/events.go b/modules/apps/27-interchain-accounts/host/keeper/events.go index 8dbf234b114..148814f0c48 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/events.go +++ b/modules/apps/27-interchain-accounts/host/keeper/events.go @@ -7,7 +7,7 @@ import ( icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" ) -// EmitWriteErrorAcknowledgementEvent emits an event signalling an error acknowledmgent and including the error details +// 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( From ce950a4e8c8dbcfa6d9bed586244abf5cc1ede54 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 20 Jan 2022 09:48:19 +0100 Subject: [PATCH 4/5] Update modules/apps/27-interchain-accounts/types/errors.go Co-authored-by: Carlos Rodriguez --- modules/apps/27-interchain-accounts/types/errors.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/types/errors.go b/modules/apps/27-interchain-accounts/types/errors.go index c082b52a35a..3f2cd77d488 100644 --- a/modules/apps/27-interchain-accounts/types/errors.go +++ b/modules/apps/27-interchain-accounts/types/errors.go @@ -7,7 +7,7 @@ import ( 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 destination chain: see events for details" + AcknowledgementError = "error handling packet on host chain: see events for details" ) var ( From 45203c19ff3dae3d6fd54f8ce73532c77868d9d1 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Thu, 20 Jan 2022 13:30:27 +0100 Subject: [PATCH 5/5] Update modules/apps/27-interchain-accounts/host/keeper/events.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/apps/27-interchain-accounts/host/keeper/events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/events.go b/modules/apps/27-interchain-accounts/host/keeper/events.go index 148814f0c48..5926781d5c2 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/events.go +++ b/modules/apps/27-interchain-accounts/host/keeper/events.go @@ -2,8 +2,8 @@ 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" )