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 async support to wasm hooks #5072

Merged
merged 37 commits into from
Aug 7, 2023
Merged

Add async support to wasm hooks #5072

merged 37 commits into from
Aug 7, 2023

Conversation

nicolaslara
Copy link
Contributor

@nicolaslara nicolaslara commented May 3, 2023

What is the purpose of the change

Packet Froward middleware introduced "async" acknowledgements in IBC: when onRecvPacket runs, the ack doesn't need to be written to state right away. Instead, that function can return nil and someone else (ideally the same module that received the packet) will write the acknowledgement later. If this doesn't happen the packet will timeout.

We want to add support for this in ibc wasm hooks so that whitelisted contracts (specifically XCS) can do this and behave similarly to PFM. This will provide a better UX when interacting with contracts that forward tokens.

Brief Changelog

  • Added mechanism for contracts called via wasm hooks to emit acks asynchronously

Testing and Verifying

  • Added test

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? (yes / no)
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? (yes / no)
  • How is the feature or change documented? (not applicable / specification (x/<module>/spec/) / Osmosis docs repo / not documented)

@github-actions github-actions bot added the C:app-wiring Changes to the app folder label May 5, 2023
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label May 20, 2023
@nicolaslara nicolaslara removed the Stale label May 20, 2023
@nicolaslara nicolaslara self-assigned this May 22, 2023
@p0mvn p0mvn self-assigned this May 23, 2023
@github-actions github-actions bot added the C:docs Improvements or additions to documentation label May 26, 2023
@nicolaslara nicolaslara marked this pull request as ready for review May 26, 2023 10:03

---

TODO: I think this is overcomplicated and I can't remember why I wrote it like this.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ValarDragon do you have any opinions on the design alternatives? (more info below this line and in the readme in general)

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'm probably going to leave the implementation as-is right now to avoid increasing the surface area to test, and we can iterate on unifying this into one message later on.

if err == nil {
// If unmarshalling succeeds, the contract is requesting for the ack to be async.
if asyncAckRequest.IsAsyncAck { // in which case IsAsyncAck is expected to be set to true
// TODO: Do we want to check that only whitelisted contracts can do AsyncAcks?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ValarDragon also here. Any thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Asking to learn: why do we want to whitelist this functionality?

Copy link
Member

Choose a reason for hiding this comment

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

Discussed offline, whitelist makes sense to me

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

Only a high-level pass to acquire context with nits. Will do a more detailed pass in a subsequent review

cosmwasm/contracts/crosschain-swaps/src/execute.rs Outdated Show resolved Hide resolved
tests/ibc-hooks/testutils/contracts/echo/src/ibc.rs Outdated Show resolved Hide resolved
Comment on lines +17 to +23
func (m MsgEmitIBCAck) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Sender)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err)
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to do additional validation of packet sequence and channel here?

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 don't think we do. The packet sequence is an uint64, and the channel can be any string (even if they generally are channel-<number>

if err == nil {
// If unmarshalling succeeds, the contract is requesting for the ack to be async.
if asyncAckRequest.IsAsyncAck { // in which case IsAsyncAck is expected to be set to true
// TODO: Do we want to check that only whitelisted contracts can do AsyncAcks?
Copy link
Member

Choose a reason for hiding this comment

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

Asking to learn: why do we want to whitelist this functionality?

x/ibc-hooks/wasm_hook.go Outdated Show resolved Hide resolved
x/ibc-hooks/wasm_hook.go Show resolved Hide resolved
x/ibc-hooks/README.md Show resolved Hide resolved
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

Great work! Was super interesting to learn about this.

I'm feeling pretty good about this change after stepping through the TestWasmHooksAsyncAcks test with a debugger.

However, I think it would be good to have another approval still

nicolaslara and others added 3 commits May 31, 2023 10:15
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
@nicolaslara nicolaslara added the V:state/breaking State machine breaking PR label May 31, 2023
@nicolaslara
Copy link
Contributor Author

This is ready for final review and merge

@p0mvn p0mvn mentioned this pull request Jul 18, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Aug 1, 2023
@github-actions github-actions bot closed this Aug 1, 2023
@czarcas7ic czarcas7ic reopened this Aug 1, 2023
@github-actions github-actions bot removed the Stale label Aug 2, 2023
Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

Great job! Feel terrible for how long this took me to review

@czarcas7ic czarcas7ic merged commit f94e6e1 into main Aug 7, 2023
1 check passed
@czarcas7ic czarcas7ic deleted the nicolas/async-hooks branch August 7, 2023 19:53
p0mvn pushed a commit that referenced this pull request Aug 29, 2023
* added initial async ack support for wasm hooks

* added initial working implementation of async acks

* removed debug prints

* cleanner acks

* Update x/ibc-hooks/README.md

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>

* added use case to readme

* clippy

* clippy

* updated hooks to latest

* added changelog

* updated deps

* added proto fix and todo

* added initial implementation of ack errors

* make protos

* better readme

* cleanup rust structs

* initial params

* fixed test

* updated async acks based on feedback. Safer this way

* add error ack test

* added missing types

* updated ibc-hooks

* tidy

* updated osmoutils

* updated osmoutils and ibc-hooks after merge

* merge main

* regen proto

* update osmoutils

* update ibc hooks

* run go get

* rl bytecode

---------

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
@github-actions github-actions bot mentioned this pull request Feb 1, 2024
@github-actions github-actions bot mentioned this pull request May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder C:docs Improvements or additions to documentation V:state/breaking State machine breaking PR
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants