-
Notifications
You must be signed in to change notification settings - Fork 94
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
reduce evm wait_for_confirmations calls, fix endless loop in wait_for_htlc_tx_spend #1724
Conversation
tried and maker is still failing the swap although takerpayment was sent fine: https://polygonscan.com/tx/0x0934ae0afd1c1d59cf6e0fadaf12fc992473528183f4cd61764b0b44d3de4790
console on maker during swap failure:
|
Do you use the same RPC node for these swaps? Can you try at least 2 other RPC nodes, it's really strange that this is still failing in Anyways, if it's not the RPC node then it must be something specific to polygon since this only happens with them. |
@cipig was the taker able to automatically refund the payment? I also fixed this part which was unrelated to the payment state bug. |
both maker and taker are using https://polygon-rpc.com we had some of them added to config in the past, separately, but it didn't make a difference, the notifications about 0 MATIC balance were still there in ADEX DEsktop |
i had this one that refunded automatically after 8h |
Then it seems that my guess was correct in that this endpoint fetches the info from a different source everytime and sometimes it gets it from a source that is a bit late, you use 3 confirmations for these swaps and in this list https://chainlist.org/chain/137 some servers sometimes are lagging by 3 or more blocks. I can also guess that this problem doesn't happen with every polygon swap, or does it? I think you would need to use higher confirmations for polygon swaps if you continue using this loadbalanced endpoint (there is also the problem of block reorganizations in polygon that requires high number of confirmations), or you can use 3 confirmations but the source of data would have to be only one server to avoid race conditions.
This is a different issue, but I understand that using one server only will return outdated data sometimes. It seems having higher confirmations is the best solution.
I will look into that, it's because polygon blocktime is very low, so the search for spend events in the logs uses a large block range after sometime which is not accepted. It used to loop without ever returning that's why automatic refunds didn't work but this part is fixed in this PR. This problem shouldn't happen in ETH as far as I can see, but if we will support EVM chains with fast blocktimes or L2 ETH chains this should be fixed. |
No, it doesn't, many swaps are working fine. |
This will decrease the occurrence of this issue a lot. But it can still happen rarely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the problem is with RPC nodes, is calling the eth_getTransactionByHash
and confirming the swap payment state in the wait_for_confirmations
method still useful? It looks like these fixes only shifted the point of failure.
I agree, I wasn't aware of the exact problem at first and I used Artem's suggestions here #1630 (comment) for the fix, but after @cipig testing, I found out the real problem. I moved this to I still think I should leave the refactor of having a struct for |
@caglaryucekaya @laruh @cipig this ready for another review/testing after I applied the changes proposed here #1724 (comment).
I used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I have one minor comment
.await | ||
{ | ||
Ok(conf) => { | ||
if conf == confirmed_at { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add status.append(" Confirmed.")
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for finding this, looks like I missed it in the refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! as i can see you also fixed tbtc test, thanks!
did a bunch of swaps, had only once a problem with a specific mm2 node of mine
happened twice in a row... first swap was already in refund mode: https://dexapi.cipig.net/public/error.php?uuid=cd679db0-0cb1-4cce-8ee1-ccd80b6aa3cd (same reason) |
@cipig Probably related to the below code, let's open another issue for it and I can work on it next week since this is unrelated to this PR. |
Moved this to |
…ecks for overflow
#1724 (comment) I didn't understand the problem with the old confirmation block number, why does it wait for 1 additional confirmation? |
if the let confirmation_block_number = confirmed_at + required_confirms - 1; I didn't subtract 1 before the latest commit, I found the problem because |
Okay thanks, I didn't know that the first block the transaction is mined is also counted as confirmation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🔥
Fixes #1224
also fixes #1224 (comment)