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 2 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
14 changes: 10 additions & 4 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,21 @@ 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)
ack = types.NewErrorAcknowledgement(err)
}

return types.NewErrorAcknowledgement(err)
if err == nil {
// Emit an event indicating a successful acknowledgement.
keeper.EmitSuccessfulAcknowledgementEvent(ctx, packet)
} else {
// Emit an event including the error msg.
keeper.EmitWriteErrorAcknowledgementEvent(ctx, packet, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not saying that you should change it, but just leaving here for your consideration an alternative way of doing this to avoid checking for err twice:

var ack channeltypes.Acknowledgement
if err == nil {
 	// Emit an event indicating a successful acknowledgement.
 	keeper.EmitSuccessfulAcknowledgementEvent(ctx, packet)
        ack = types.NewErrorAcknowledgement(err)
} else {
 	// Emit an event including the error msg.
 	keeper.EmitWriteErrorAcknowledgementEvent(ctx, packet, err)
 	ack = channeltypes.NewResultAcknowledgement(txResponse)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention was to keep the style similar to what we have here

}

// NOTE: acknowledgement will be written synchronously during IBC handler execution.
return channeltypes.NewResultAcknowledgement(txResponse)
return ack
}

// OnAcknowledgementPacket implements the IBCModule interface
Expand Down
11 changes: 11 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ func EmitWriteErrorAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI
),
)
}

// EmitSuccessfulAcknowledgementEvent emits an event signalling a successful acknowledgement
func EmitSuccessfulAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI) {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
icatypes.EventTypePacket,
sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName),
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.

),
)
}