You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A major issue that is unique to `ibc_packet_receive` is that it is expected to
322
+
often reject an incoming packet, yet it cannot abort the transaction. We
323
+
actually expect all state changes from the contract (as well as dispatched
324
+
messages) to be reverted when the packet is rejected, but the transaction to
325
+
properly commit an acknowledgement with encoded error. In other words, this "IBC
326
+
Handler" will error and revert, but the "IBC Router" must succeed and commit an
327
+
acknowledgement message (that can be parsed by the sending chain as an error).
328
+
329
+
The atomicity issue was first
330
+
[analyzed in the Cosmos SDK implementation](https://github.com/cosmos/ibc-go/issues/68)
331
+
and refined into
332
+
[changing semantics of the OnRecvPacket SDK method](https://github.com/cosmos/ibc-go/issues/91),
333
+
which was
334
+
[implemented in April 2021](https://github.com/cosmos/ibc-go/pull/107), likely
335
+
to be released with Cosmos SDK 0.43 or 0.44. Since we want the best,
336
+
future-proof interface for contracts, we will use an approach inspired by that
337
+
work, and add an adapter in `wasmd` until we can upgrade to a Cosmos SDK version
338
+
that implements this.
339
+
340
+
After quite some
341
+
[discussion on how to encode the errors](https://github.com/CosmWasm/cosmwasm/issues/762),
342
+
we struggled to map this idea to the CosmWasm model. However, we also discovered
343
+
a deep similarity between these requirements and the
344
+
[submessage semantics](./SEMANTICS.md#submessages). It just requires some
345
+
careful coding on the contract developer's side to not throw errors. This
346
+
produced 3 suggestions on how to handle errors and rollbacks _inside
347
+
`ibc_packet_receive`_
348
+
349
+
1. If the message doesn't modify any state directly, you can simply put the
350
+
logic in a closure, and capture errors, converting them into error
351
+
acknowledgements. This would look something like the
352
+
[main dispatch loop in `ibc-reflect`](https://github.com/CosmWasm/cosmwasm/blob/cd784cd1148ee395574f3e564f102d0d7b5adcc3/contracts/ibc-reflect/src/contract.rs#L217-L248):
Although the ICS spec leave the actual acknowledgement as opaque bytes, it does
314
472
provide a recommendation for the format you can use, allowing contracts to
@@ -330,12 +488,18 @@ message Acknowledgement {
330
488
331
489
Although it suggests this is a Protobuf object, the ICS spec doesn't define
332
490
whether to encode it as JSON or Protobuf. In the ICS20 implementation, this is
333
-
JSON encoded when returned from a contract. Given that, we will consider this
334
-
structure, JSON-encoded, to be the "standard" acknowledgement format.
491
+
JSON encoded when returned from a contract. In ICS27, the authors are discussing
492
+
using a Protobuf-encoded form of this structure.
493
+
494
+
Note that it leaves the actual success response as app-specific bytes where you
495
+
can place anything, but does provide a standard way for an observer to check
496
+
success-or-error. If you are designing a new protocol, I encourage you to use
497
+
this struct in either of the encodings as the acknowledgement envelope.
335
498
336
499
You can find a
337
500
[CosmWasm-compatible definition of this format](https://github.com/CosmWasm/cosmwasm-plus/blob/v0.6.0-beta1/contracts/cw20-ics20/src/ibc.rs#L52-L72)
338
-
as part of the `cw20-ics20` contract.
501
+
as part of the `cw20-ics20` contract, along with JSON-encoding. Protobuf
0 commit comments