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

ICS20v2 path forwarding: simplify revert in-flight changes #1110

Merged

Conversation

crodriguezvega
Copy link
Contributor

@crodriguezvega crodriguezvega commented Jun 10, 2024

Following up on the discussion from the walkthrough, it does seem like we can simplify the logic of revertInflightChanges (I actually had also hinted that to Aditya when I first reviewed the spec...)

To make it easier for everyone to reason about this (although please double check that I haven't made any mistake), the following outlines what happens with the escrow accounts and forwarding account assuming that there is a timeout or error ack and changes on the middle hop need to be reverted. The receivedPacket is the received packet on the middle hop and the sentPacket is the packet sent from the middle hop as a result of forwarding.

Scenario 1 (source when receiving, source when sending)

  • receive packet as source of tokens:
    transfer tokens escrow[receivedPacket.destinationChannel] -> forwarding[receivedPacket.destinationChannel]
  • send packet as source of tokens:
    transfer tokens forwarding[receivedPacket.destinationChannel] -> escrow[sentPacket.sourceChannel]
  • refund packet tokens:
    transfer tokens escrow[sentPacket.sourceChannel] -> forwarding[receivedPacket.destinationChannel]
  • revert in-flight changes:
    transfer tokens forwarding[receivedPacket.destinationChannel] -> escrow[receivedPacket.destinationChannel]

Scenario 2 (source when receiving, not source when sending)

  • receive packet as source of tokens:
    transfer tokens escrow[receivedPacket.destinationChannel] -> forwarding[receivedPacket.destinationChannel]
  • send packet as not source of tokens:
    burn tokens forwarding[receivedPacket.destinationChannel]
  • refund packet tokens;
    mint tokens forwarding[receivedPacket.destinationChannel]
  • revert in-flight changes;
    transfer tokens forwarding[receivedPacket.destinationChannel] -> escrow[receivedPacket.destinationChannel]

Scenario 3 (not source when receiving, source when sending)

  • receive packet as not source of tokens:
    mint vouchers forwarding[receivedPacket.destinationChannel]
  • send packet as source of tokens:
    transfer vouchers forwarding[receivedPacket.destinationChannel] -> escrow[sentPacket.sourceChannel]
  • refund packet tokens:
    transfer vouchers escrow[sentPacket.sourceChannel] -> forwarding[receivedPacket.destinationChannel]
  • revert in-flight changes:
    burn vouchers forwarding[receivedpacket.destinationChannel]

Scenario 4 (not source when receiving, not source when sending)

  • receive packet as not source of tokens:
    mint vouchers forwarding[receivedPacket.destinationChannel]
  • send packet as not source of tokens:
    burn vouchers forwarding[receivedPacket.destinationChannel]
  • refund packet tokens:
    mint vouchers forwarding[receivedPacket.destinationChannel]
  • revert in-flight changes:
    burn vouchers forwarding[receivedpacket.destinationChannel]

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

Yes this is much cleaner. Thanks for the clarification @crodriguezvega !!

@crodriguezvega crodriguezvega merged commit eb6bd36 into aditya/forwarding Jun 19, 2024
2 checks passed
@crodriguezvega crodriguezvega deleted the carlos/simplify-revert-inflight-changes branch June 19, 2024 18:36
AdityaSripal added a commit that referenced this pull request Jun 24, 2024
* add recv logic and revert logic on error ack/timeout

* multiple denoms but still support forwarding

* lint

* Apply suggestions from code review

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* address reviews

* Apply suggestions from code review

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* small fixes

* generate forwarding address if it doesn't exist

* blank memo for now

* only do revertInFlightChanges or refund packets on error ack, not both

* make same changes for timeout

* forwarding info struct, individual memos

* fail early since forwarding must be atomic

* address some small review comments

* only set memo on last hop

* address Stefano's and my review comments

* missing bracket

* destinationChannel -> destChannel

* ICS20v2 path forwarding: simplify revert in-flight changes (#1110)

* simplify revert in-flight changes

* typo

* nit: rename ForwardingInfo to Forwarding (#1112)

* ICS20v2: use protobuf encoding for packet data of v2 (#1118)

* ics20: use protobuf encoding for packet data of v2

* Update README.md

* delete previously forwarded packet (#1119)

* Update spec/app/ics-020-fungible-token-transfer/README.md

Co-authored-by: Damian Nolan <damiannolan@gmail.com>

* Apply suggestions from code review

Co-authored-by: Cian Hatton <github.qpeyb@simplelogin.fr>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* ICS20v2: use `Denom` and `Trace` types (#1115)

* nit: rename ForwardingInfo to Forwarding

* use Denom and Trace types

* Apply suggestions from code review

Co-authored-by: Aditya <14364734+AdityaSripal@users.noreply.github.com>

* comments

---------

Co-authored-by: Aditya <14364734+AdityaSripal@users.noreply.github.com>

* review comment

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
Co-authored-by: Cian Hatton <github.qpeyb@simplelogin.fr>
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.

2 participants