From 02f480532be91306c7db934dcf7becc417b143cb Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 7 Jun 2022 10:12:17 +0100 Subject: [PATCH] Emit an event to indicate a successful acknowledgement in the ICA module (#1466) (cherry picked from commit b2ca1932849cc3f05fe9e6ec30049aa4d08e6fc6) # Conflicts: # modules/apps/27-interchain-accounts/host/keeper/events.go --- CHANGELOG.md | 1 + .../27-interchain-accounts/host/ibc_module.go | 11 ++++++----- .../host/keeper/events.go | 18 +++++++++++++++--- .../27-interchain-accounts/types/events.go | 1 + 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 138c037a573..cba2a555d65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (channel) [\#644](https://github.com/cosmos/ibc-go/pull/644) Adds `GetChannelConnection` to the ChannelKeeper. This function returns the connectionID and connection state associated with a channel. * (channel) [\647](https://github.com/cosmos/ibc-go/pull/647) Reorganizes channel handshake handling to set channel state after IBC application callbacks. * (client) [\#724](https://github.com/cosmos/ibc-go/pull/724) `IsRevisionFormat` and `IsClientIDFormat` have been updated to disallow newlines before the dash used to separate the chainID and revision number, and the client type and client sequence. +* (interchain-accounts) [\#1466](https://github.com/cosmos/ibc-go/pull/1466) Emit event when there is an acknowledgement during `OnRecvPacket`. ### Features diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index fb403c71937..d750ea0a211 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -110,15 +110,16 @@ func (im IBCModule) OnRecvPacket( } txResponse, err := im.keeper.OnRecvPacket(ctx, packet) + ack := channeltypes.NewResultAcknowledgement(txResponse) if err != nil { - // Emit an event including the error msg - keeper.EmitWriteErrorAcknowledgementEvent(ctx, packet, err) - - return types.NewErrorAcknowledgement(err) + ack = types.NewErrorAcknowledgement(err) } + // Emit an event indicating a successful or failed acknowledgement. + keeper.EmitAcknowledgementEvent(ctx, packet, ack, err) + // NOTE: acknowledgement will be written synchronously during IBC handler execution. - return channeltypes.NewResultAcknowledgement(txResponse) + return ack } // OnAcknowledgementPacket implements the IBCModule interface diff --git a/modules/apps/27-interchain-accounts/host/keeper/events.go b/modules/apps/27-interchain-accounts/host/keeper/events.go index 5926781d5c2..1cce9c37088 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/events.go +++ b/modules/apps/27-interchain-accounts/host/keeper/events.go @@ -1,20 +1,32 @@ package keeper import ( + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" +<<<<<<< HEAD +======= + icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types" +>>>>>>> b2ca193 (Emit an event to indicate a successful acknowledgement in the ICA module (#1466)) "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) { +// EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error +// details if any. +func EmitAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, ack exported.Acknowledgement, err error) { + var errorMsg string + if err != nil { + errorMsg = err.Error() + } + ctx.EventManager().EmitEvent( sdk.NewEvent( icatypes.EventTypePacket, sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName), - sdk.NewAttribute(icatypes.AttributeKeyAckError, err.Error()), + sdk.NewAttribute(icatypes.AttributeKeyAckError, errorMsg), sdk.NewAttribute(icatypes.AttributeKeyHostChannelID, packet.GetDestChannel()), + sdk.NewAttribute(icatypes.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())), ), ) } diff --git a/modules/apps/27-interchain-accounts/types/events.go b/modules/apps/27-interchain-accounts/types/events.go index 04882a6a644..9bfd1df3049 100644 --- a/modules/apps/27-interchain-accounts/types/events.go +++ b/modules/apps/27-interchain-accounts/types/events.go @@ -6,4 +6,5 @@ const ( AttributeKeyAckError = "error" AttributeKeyHostChannelID = "host_channel_id" + AttributeKeyAckSuccess = "success" )