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

IBC Callbacks #2025

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open

IBC Callbacks #2025

wants to merge 41 commits into from

Conversation

chipshort
Copy link
Collaborator

@chipshort chipshort commented Feb 9, 2024

closes #1938

Implements the following:

  • ibc-callbacks contract: a new contract that keeps track of the callbacks that were called and provides a query to get the data that was passed to the callbacks. This is used in wasmd for an e2e test.
  • 2 new entrypoints: ibc_source_chain_callback and ibc_destination_chain_callback, as well as the corresponding message types
  • IbcCallbackRequest type (and types it contains): Allows constructing the json format for the memo field with strong typing

@chipshort chipshort force-pushed the ibc-callbacks branch 2 times, most recently from 2aed858 to 3b18e9e Compare February 9, 2024 14:44
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.

Cool stuff! Very incomplete but some first thoughts. Thanks for the nice documentation, very helpful.

contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
@chipshort chipshort force-pushed the ibc-callbacks branch 2 times, most recently from 83c2b6a to ee37d1e Compare February 21, 2024 15:29
@chipshort chipshort force-pushed the ibc-callbacks branch 6 times, most recently from 15eab52 to 5a7f6b6 Compare April 8, 2024 15:02
@chipshort chipshort changed the title [WIP] IBC Callbacks IBC Callbacks Apr 8, 2024
@chipshort chipshort marked this pull request as ready for review April 8, 2024 15:13
Copy link
Member

@aumetra aumetra left a comment

Choose a reason for hiding this comment

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

LGTM! (from my point of view with more limited understanding)

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.

🙌 Great job, clean and straight forward

contracts/ibc-callbacks/README.md Outdated Show resolved Hide resolved
packages/std/src/ibc/callbacks.rs Outdated Show resolved Hide resolved
packages/std/src/ibc/callbacks.rs Show resolved Hide resolved
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct IbcDestinationChainCallbackMsg {
pub packet: IbcPacket,
pub ack: IbcAcknowledgement,
Copy link
Member

Choose a reason for hiding this comment

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

On the destination chain, how do we know if there is an ack or not?

  • What about notifications for timeouts (e.g. someone tried to send you funds but failed)?
  • What about cases where a packet is received but no acknowledgement is written because the protocol never writes them?

Copy link
Collaborator Author

@chipshort chipshort Apr 16, 2024

Choose a reason for hiding this comment

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

In general we don't know that, but I just learned that my understanding of how this works was slightly off. Here's how it actually works:
If the ack is async (using WriteAcknowledgement), then the callback is called both for successful and unsuccessful acknowledgements.
If the ack is not async (by returning from OnRecvPacket), then the callback is only called if it was successful.

I originally thought only successful acks cause a callback, so we need to change the interface here to convey whether it was successful or not.

  • Regarding timeout: The destination chain does not get to know about timeouts because (AFAIK) the IBC protocol has no mechanism for that. It would require the protocol built on top to support it (by sending another packet).
  • Regarding no ack: If no ack is written, no callback is received.

Copy link

Choose a reason for hiding this comment

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

The destination chain doesn't know about timeouts at all (even core ibc), so it is not possible to do a callback anyway.

If OnRecvPacket returns an unsuccessful ack, core ibc reverts the cached context, so there is no reason to make a callback since it'd be reverted anyway. The intuition is that an unsuccessful ack means that the packet couldn't be received. The knowledge that a sender has attempted and failed to make a transfer is only useful to the sender (not the destination).

However, things get more complicated with async acknowledgements. (Note that no application in ibc-go currently supports async acknowledgements.) This is because async acknowledgements are initiated by an application module, not core ibc (unlike RecvPacket). This means that the decision to revert state on unsuccessful acknowledgement is up to the application module, and thus, we perform the callback in this case.

packages/vm/src/calls.rs Show resolved Hide resolved
Copy link

@srdtrk srdtrk left a comment

Choose a reason for hiding this comment

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

Thank you for this amazing work. Left some of my thoughts. Always feel free to ping me.

packages/std/src/ibc/callbacks.rs Outdated Show resolved Hide resolved
packages/std/src/ibc/callbacks.rs Outdated Show resolved Hide resolved
packages/std/src/ibc/callbacks.rs Outdated Show resolved Hide resolved
packages/std/src/ibc/callbacks.rs Outdated Show resolved Hide resolved
packages/std/src/ibc/callbacks.rs Show resolved Hide resolved
packages/std/src/lib.rs Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
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.

🥳🥳🥳

contracts/ibc-callbacks/src/msg.rs Outdated Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Show resolved Hide resolved
contracts/ibc-callbacks/src/contract.rs Outdated Show resolved Hide resolved
packages/std/src/exports.rs Outdated Show resolved Hide resolved
packages/std/src/exports.rs Show resolved Hide resolved
packages/std/src/ibc/callbacks.rs Outdated Show resolved Hide resolved
packages/std/src/ibc/callbacks.rs Outdated Show resolved Hide resolved
packages/std/src/lib.rs Show resolved Hide resolved
packages/vm/README.md Outdated Show resolved Hide resolved
/// Max length (in bytes) of the result data from a ibc_source_chain_callback call.
pub const RESULT_IBC_SOURCE_CHAIN_CALLBACK: usize = 64 * MI;
/// Max length (in bytes) of the result data from a ibc_destination_chain_callback call.
pub const RESULT_IBC_DESTINATION_CHAIN_CALLBACK: usize = 64 * MI;
Copy link
Member

Choose a reason for hiding this comment

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

Independent of this PR: those are generous limits given that the Wasm contract has a memory size limit of 32 MiB. See in wasmd

// contractMemoryLimit is the memory limit of each contract execution (in MiB)
// constant value so all nodes run with the same limit.
const contractMemoryLimit = 32

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.

Implement IBC's ADR-8
4 participants