Skip to content

Commit b2ca193

Browse files
authored
Emit an event to indicate a successful acknowledgement in the ICA module (cosmos#1466)
1 parent ba83e70 commit b2ca193

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
125125
* (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.
126126
* (channel) [\#647](https://github.com/cosmos/ibc-go/pull/647) Reorganizes channel handshake handling to set channel state after IBC application callbacks.
127127
* (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.
128+
* (interchain-accounts) [\#1466](https://github.com/cosmos/ibc-go/pull/1466) Emit event when there is an acknowledgement during `OnRecvPacket`.
128129

129130
### Features
130131

modules/apps/27-interchain-accounts/host/ibc_module.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,16 @@ func (im IBCModule) OnRecvPacket(
110110
}
111111

112112
txResponse, err := im.keeper.OnRecvPacket(ctx, packet)
113+
ack := channeltypes.NewResultAcknowledgement(txResponse)
113114
if err != nil {
114-
// Emit an event including the error msg
115-
keeper.EmitWriteErrorAcknowledgementEvent(ctx, packet, err)
116-
117-
return types.NewErrorAcknowledgement(err)
115+
ack = types.NewErrorAcknowledgement(err)
118116
}
119117

118+
// Emit an event indicating a successful or failed acknowledgement.
119+
keeper.EmitAcknowledgementEvent(ctx, packet, ack, err)
120+
120121
// NOTE: acknowledgement will be written synchronously during IBC handler execution.
121-
return channeltypes.NewResultAcknowledgement(txResponse)
122+
return ack
122123
}
123124

124125
// OnAcknowledgementPacket implements the IBCModule interface
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
package keeper
22

33
import (
4+
"fmt"
45
sdk "github.com/cosmos/cosmos-sdk/types"
5-
66
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
77
"github.com/cosmos/ibc-go/v3/modules/core/exported"
88
)
99

10-
// EmitWriteErrorAcknowledgementEvent emits an event signalling an error acknowledgement and including the error details
11-
func EmitWriteErrorAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, err error) {
10+
// EmitAcknowledgementEvent emits an event signalling a successful or failed acknowledgement and including the error
11+
// details if any.
12+
func EmitAcknowledgementEvent(ctx sdk.Context, packet exported.PacketI, ack exported.Acknowledgement, err error) {
13+
var errorMsg string
14+
if err != nil {
15+
errorMsg = err.Error()
16+
}
17+
1218
ctx.EventManager().EmitEvent(
1319
sdk.NewEvent(
1420
icatypes.EventTypePacket,
1521
sdk.NewAttribute(sdk.AttributeKeyModule, icatypes.ModuleName),
16-
sdk.NewAttribute(icatypes.AttributeKeyAckError, err.Error()),
22+
sdk.NewAttribute(icatypes.AttributeKeyAckError, errorMsg),
1723
sdk.NewAttribute(icatypes.AttributeKeyHostChannelID, packet.GetDestChannel()),
24+
sdk.NewAttribute(icatypes.AttributeKeyAckSuccess, fmt.Sprintf("%t", ack.Success())),
1825
),
1926
)
2027
}

modules/apps/27-interchain-accounts/types/events.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ const (
66

77
AttributeKeyAckError = "error"
88
AttributeKeyHostChannelID = "host_channel_id"
9+
AttributeKeyAckSuccess = "success"
910
)

0 commit comments

Comments
 (0)