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

Emit an event to indicate a successful acknowledgement in the ICA module #1466

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,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

Expand Down
11 changes: 6 additions & 5 deletions modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions modules/apps/27-interchain-accounts/host/keeper/events.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package keeper

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

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

// 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()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like input on whether or not there are additional fields/attributes that should be included in this event. Please let me know if I've missed anything!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine, maybe we could add a AttributeKeyAckSuccess like for transfer.

But I am also now wondering if we could merge both event functions into one and have something like this:

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()),
                sdk.NewAttribute(icatypes.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
	),
)

with the icatypes.AttributeKeyAckError empty if it was successful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually thinking something very similar with regards to merging the functions.

sdk.NewAttribute(icatypes.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
),
)
}
1 change: 1 addition & 0 deletions modules/apps/27-interchain-accounts/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ const (

AttributeKeyAckError = "error"
AttributeKeyHostChannelID = "host_channel_id"
AttributeKeyAckSuccess = "success"
)