Skip to content

Commit

Permalink
Add codespace to error acknowledgement
Browse files Browse the repository at this point in the history
This adds the codespace to error acknowledgements by switching from
NewErrorAcknowledgement to NewErrorAcknowledgementWithCodespace.

Also creates the initial infrastrucrture to further customize error
acknowledgement creation.
  • Loading branch information
webmaster128 committed Jun 27, 2024
1 parent 14161f8 commit 29ba3e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 10 additions & 1 deletion x/wasm/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (i IBCHandler) OnRecvPacket(
msg := wasmvmtypes.IBCPacketReceiveMsg{Packet: newIBCPacket(packet), Relayer: relayer.String()}
ack, err := i.keeper.OnRecvPacket(ctx.WithEventManager(em), contractAddr, msg)
if err != nil {
ack = channeltypes.NewErrorAcknowledgement(err)
ack = CreateErrorAcknowledgement(err)
// the state gets reverted, so we drop all captured events
} else if ack == nil || ack.Success() {
// emit all contract and submessage events on success
Expand Down Expand Up @@ -358,3 +358,12 @@ func ValidateChannelParams(channelID string) error {
}
return nil
}

// CreateErrorAcknowledgement turns an error into an error acknowledgement.
//
// This function is x/wasm specific and might include the full error text in the future
// as we gain confidence that it is deterministic. Don't use it in other contexts.
// See also https://github.com/CosmWasm/wasmd/issues/1740.
func CreateErrorAcknowledgement(err error) ibcexported.Acknowledgement {
return channeltypes.NewErrorAcknowledgementWithCodespace(err)
}
3 changes: 2 additions & 1 deletion x/wasm/ibc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ func TestOnIBCPacketReceive(t *testing.T) {
expAck: []byte(`{"error":"invalid packet: Generic error: my error"}`),
},
"with returned msg fails": {
// ErrInvalidAddress (https://github.com/cosmos/cosmos-sdk/blob/v0.50.7/types/errors/errors.go#L28-L29)
packetData: []byte(`{"return_msgs": {"msgs": [{"bank":{"send":{"to_address": "invalid-address", "amount": [{"denom": "ALX", "amount": "1"}]}}}]}}`),
expAck: []byte(`{"error":"ABCI code: 7: error handling packet: see events for details"}`),
expAck: []byte(`{"error":"ABCI error: wasm/7: error handling packet: see events for details"}`),
},
"with contract panic": {
packetData: []byte(`{"panic":{}}`),
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestOnRecvPacket(t *testing.T) {
},
"contract returns err response": {
ibcPkg: anyContractIBCPkg,
contractRsp: channeltypes.NewErrorAcknowledgement(types.ErrInvalid.Wrap("testing")),
expAck: channeltypes.NewErrorAcknowledgement(types.ErrInvalid.Wrap("testing")),
contractRsp: CreateErrorAcknowledgement(types.ErrInvalid.Wrap("testing")),
expAck: CreateErrorAcknowledgement(types.ErrInvalid.Wrap("testing")),
expEvents: sdk.Events{
{
Type: "ibc_packet_received",
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestOnRecvPacket(t *testing.T) {
"returned messages executed with error": {
ibcPkg: anyContractIBCPkg,
contractOkMsgExecErr: types.ErrInvalid.Wrap("testing"),
expAck: channeltypes.NewErrorAcknowledgement(types.ErrInvalid.Wrap("testing")),
expAck: CreateErrorAcknowledgement(types.ErrInvalid.Wrap("testing")),
expEvents: sdk.Events{{
Type: "ibc_packet_received",
Attributes: []abci.EventAttribute{
Expand Down

0 comments on commit 29ba3e1

Please sign in to comment.