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

Streaming Swaps Completed State #7371

Closed
0xean opened this issue Jul 15, 2024 · 10 comments · Fixed by #7573 or #7831
Closed

Streaming Swaps Completed State #7371

0xean opened this issue Jul 15, 2024 · 10 comments · Fixed by #7573 or #7831
Assignees
Labels
bug Something isn't working

Comments

@0xean
Copy link
Contributor

0xean commented Jul 15, 2024

I thought we had a ticket for this but not sure where

A streaming swap shows completed after the initial TX is confirmed even though it is still streaming:

Screenshot 2024-07-15 at 6 57 24 AM

Screenshot 2024-07-15 at 6 57 36 AM

AC

  • show initial tx completed and state of swap correctly until completed.
@0xean 0xean added the bug Something isn't working label Jul 15, 2024
@0xean
Copy link
Contributor Author

0xean commented Jul 15, 2024

regression of a previous fix

@0xApotheosis
Copy link
Contributor

I've made an improvement to streaming here: #7573

But for this ticket specifically I've been unable to replicate. It seems streaming swaps in the order of 6 figures USD complete within one swap and block (even when I override the memo before broadcasting - there is possibly a minimum on the THORChain side?).

For example, I overrode this small swap with 3/6 and it still completed immediately: https://viewblock.io/thorchain/tx/ef485bef45ca5e0cf471b0d7dff8ef8279b0e8e300077d843854d9513a8f8a79

It's possible I need significantly more funds to replicate and fix this issue.

@gomesalexandre ser you might have further thoughts on this guy.

@0xApotheosis 0xApotheosis removed their assignment Aug 20, 2024
@gomesalexandre
Copy link
Contributor

gomesalexandre commented Aug 20, 2024

I've made an improvement to streaming here: #7573

But for this ticket specifically I've been unable to replicate. It seems streaming swaps in the order of 6 figures USD complete within one swap and block (even when I override the memo before broadcasting - there is possibly a minimum on the THORChain side?).

For example, I overrode this small swap with 3/6 and it still completed immediately: viewblock.io/thorchain/tx/ef485bef45ca5e0cf471b0d7dff8ef8279b0e8e300077d843854d9513a8f8a79

It's possible I need significantly more funds to replicate and fix this issue.

@gomesalexandre ser you might have further thoughts on this guy.

@0xApotheosis I noticed this as well with streaming swaps - think the consensus is indeed small streaming swaps usually do not trigger an actual streaming swap (i.e many intermediary swaps) with 0 (auto) quantity, though overriding it should theoretically work.
@0xean do you have the Txid handy for this swap so we can try and replicate the memo here?

@gomesalexandre
Copy link
Contributor

Bad bot GitHub, #7573 didn't close this

@gomesalexandre
Copy link
Contributor

gomesalexandre commented Aug 20, 2024

FYI @0xApotheosis while this is super hard to tackle without being able to repro actual streaming swaps, the root cause here is the same as #7506: we don't have any fancy logic (well, we actually do, see below) to mutate Txids on the fly and use the regular swapper execution architecture to determine completion: when the initiating Txid is confirmed, we assume the swap as complete (ish, we actually do have some kind of fancy logic which is not working here, see getLatestThorTxStatusMessage)

The way this was solved for SAFE Txs was through checkTradeStatus by mutating Txids on the fly: originally mutating the Tx hash (the initiating Tx) to be a pending Tx (vs. confirmed as it would currently be), and then returning a different Txid (the actual on-chain Tx, through SAFE API) once we have it, and then leveraging good ol' evm status detection through checkEvmSwapStatus.

Think the exact same could be done here, though once again, without actual streaming swaps, that would be hard to verify working, but if anything should not make things worse for regular swaps and may at worse make streaming swaps stuck in pending state:

We could introspect both the /thorchain/tx/status and the /thorchain/swap/streaming endpoints and use the intersection of quantity (or lack thereof) and swap_finalised / outbound_signed to determine completion.

Actually rubber ducking myself here while writing this, getLatestThorTxStatusMessage already does something similar for status polling and could potentially be accomodated for that use-case.

@woodenfurniture woodenfurniture self-assigned this Sep 12, 2024
@woodenfurniture
Copy link
Member

Awaiting test funds
https://discord.com/channels/554694662431178782/876953436908822568/1283926867031625859

@woodenfurniture
Copy link
Member

$3000 RUNE -> USDC.AVA will trigger streaming swap

@woodenfurniture
Copy link
Member

Outcomes from testing this issue

  • Streaming swaps initially display 100% progress bar state while the streaming swap metadata is not yet initialized. We should be displaying "indeterminate" state of the progress bar component
  • Most very small streaming swaps are actually treated as normal swaps by thorchain, so testing these isn't useful.
  • Small actual streaming swaps do complete normally without exiting early because the streaming finishes before the transaction is processed by thorchain
  • We will need enough funds to test streaming swaps that stream for longer than the initial transaction

@woodenfurniture
Copy link
Member

TL;DR more testing is needed with bigger funds.


hasOutboundTx is determined by the following line:

const hasOutboundTx = latestOutTx?.chain !== 'THOR'

This is likely either THE bug, or one of multiple. The correct logic should be:

const hasOutboundTx = latestOutTx !== undefined && latestOutTx.chain !== 'THOR'

Due to the issue above, the bug is likely triggered in the following case where hasOutboundTx is false due to the absence of any latestOutTx. We need to determine exactly what the data looks like when the initial tx is completed but streaming is still in progress.

Image

@woodenfurniture
Copy link
Member

Successful reproduction of the issue.

First half
https://jam.dev/c/d1646f1c-15cb-44ee-ab7b-dea0883e66bb

Second half
https://jam.dev/c/7e0ce3f1-dd82-4a94-8fc3-8c01f7fe2aaf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment