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]
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 thesentPacket
is the packet sent from the middle hop as a result of forwarding.Scenario 1 (source when receiving, source when sending)
escrow[receivedPacket.destinationChannel]
->forwarding[receivedPacket.destinationChannel]
forwarding[receivedPacket.destinationChannel]
->escrow[sentPacket.sourceChannel]
escrow[sentPacket.sourceChannel]
->forwarding[receivedPacket.destinationChannel]
forwarding[receivedPacket.destinationChannel]
->escrow[receivedPacket.destinationChannel]
Scenario 2 (source when receiving, not source when sending)
escrow[receivedPacket.destinationChannel]
->forwarding[receivedPacket.destinationChannel]
forwarding[receivedPacket.destinationChannel]
forwarding[receivedPacket.destinationChannel]
forwarding[receivedPacket.destinationChannel]
->escrow[receivedPacket.destinationChannel]
Scenario 3 (not source when receiving, source when sending)
forwarding[receivedPacket.destinationChannel]
forwarding[receivedPacket.destinationChannel]
->escrow[sentPacket.sourceChannel]
escrow[sentPacket.sourceChannel]
->forwarding[receivedPacket.destinationChannel]
forwarding[receivedpacket.destinationChannel]
Scenario 4 (not source when receiving, not source when sending)
forwarding[receivedPacket.destinationChannel]
forwarding[receivedPacket.destinationChannel]
forwarding[receivedPacket.destinationChannel]
forwarding[receivedpacket.destinationChannel]