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

Add a section on encoding IBCReceive errors #885

Merged
merged 9 commits into from
Apr 28, 2021

Conversation

ethanfrey
Copy link
Member

@ethanfrey ethanfrey commented Apr 16, 2021

Builds on #898 (merge that first)

Closes #762

  • Document desired behavior
  • Provide code sample of how to use it

Base automatically changed from document-ibc to main April 19, 2021 15:50
@ethanfrey ethanfrey force-pushed the on-packet-recv-error-handling branch from d4daf80 to 69b259a Compare April 19, 2021 15:51
@ethanfrey ethanfrey marked this pull request as ready for review April 19, 2021 15:51
@ethanfrey
Copy link
Member Author

I'd be happy for a review on this one. Especially from @alpe who has seen the sdk bindings.

I hope this provides a good solution for rollback on receive

@ethanfrey
Copy link
Member Author

Open question: do we want to do something similar with acknowledgement and timeout?

@ethanfrey ethanfrey force-pushed the on-packet-recv-error-handling branch from 69b259a to e8a1635 Compare April 20, 2021 19:54
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated
4. `receiveResult` is `Err(String)` if any of the above errored, or `Ok(Binary)`
with the original acknowledgement bytes if we have the success case.
5. Call `ibc_encode_acknowledgement` with the `receiveResult`. The return value
is the acknowledgement packet to send to the calling chain. This should never
Copy link
Member

Choose a reason for hiding this comment

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

What is the DB transaction scope of this call? Is it the same as ibc_receive_packet so that it would be reverted on the error before or a new one that is independent?
I don't have a concrete use case but it feels useful to persist data with a failure ACK as well. If we want this then an error return value makes sense. Though the process would end without an ACK to the packet sender.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not my invention, I am following the ibc design (which will come out in 0.43 or 0.44). Check the links at the top of https://github.com/CosmWasm/cosmwasm/blob/on-packet-recv-error-handling/IBC.md#acknowledgement-processing

Especially read the issue description here: cosmos/ibc-go#91 (skim the comments if you wish, the description has the intention, the rest is discussing details). And if you want to dig into the code to understand one part, you can see cosmos/ibc-go#107 (but that is not necessary to get the design)

IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated
is the acknowledgement packet to send to the calling chain. This should never
error.
6. If `ReceiveResult` is `Ok`, commit this "storage cache". If it is `Err`,
revert those changes.
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Do I understand this correct that this step let the contract handle the error case on messages and control the TX scope? The process I was assuming would revert the TX on error in 3) but can persist new state in 5).

Copy link
Member Author

Choose a reason for hiding this comment

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

The future IBC design (linked above, here again: cosmos/ibc-go#91) explicitly makes the entire app execution (x/wasm) atomic - to be rolled back when app error. But not touching the IBC part of the transaction and successfully committing a "error acknowledgement" in the IBC Keeper.

I feel it is pointless to design something other than what they are doing, unless you want to re-open that issue in the ibc repo. As in the mid-term, we will just use those semantics in x/wasm and all other modules will use them as well.

@ethanfrey ethanfrey force-pushed the on-packet-recv-error-handling branch from 6b32c6e to e00a340 Compare April 26, 2021 19:02
@ethanfrey ethanfrey changed the base branch from main to document-execution-semantics April 26, 2021 19:03
Base automatically changed from document-execution-semantics to main April 27, 2021 09:25
@ethanfrey ethanfrey force-pushed the on-packet-recv-error-handling branch from e00a340 to cd784cd Compare April 27, 2021 17:18
@ethanfrey
Copy link
Member Author

Okay, this got a complete overhaul since I worked out the new SEMANTICS.ms. Please take a fresh look at this.

I also modified ibc-reflect to use this technique in ibc_packet_receive (as well as submessages in ibc_channel_connect to demo normal "callback" usage).

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Yeah, very helpful!

IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated
attributes: vec![],
})
})
```
Copy link
Member

Choose a reason for hiding this comment

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

We could even enforece this by changing the signature of the entry point to IbcReceiveResponse, i.e. no result around it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice idea. This will push devs to proper usage

IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
IBC.md Outdated Show resolved Hide resolved
contracts/ibc-reflect/src/contract.rs Outdated Show resolved Hide resolved
@ethanfrey
Copy link
Member Author

I addressed all the comments except for changing the return type. If we want to do that, I would like to do that in a different PR (this one is mainly docs and making example code).

Can we merge this?
Shall I start a new PR on top with the return value change?

Copy link
Member

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Thanks for the writeup. This makes sense 👍

Note that it leaves the actual success response as app-specific bytes where you
can place anything, but does provide a standard way for an observer to check
success-or-error. If you are designing a new protocol, I encourage you to use
this struct in either of the encodings as the acknowledgement envelope.
Copy link
Member

Choose a reason for hiding this comment

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

👍 good to have this as recommendation

@webmaster128 webmaster128 merged commit 132519b into main Apr 28, 2021
@webmaster128 webmaster128 deleted the on-packet-recv-error-handling branch April 28, 2021 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Review error handling/rollback when recieve_packet errors (sends ack packet with error)
3 participants