KomodoPlatform / komodo-defi-framework

This is the official Komodo DeFi Framework repository
https://komodoplatform.com/en/docs/komodo-defi-framework/
103 stars 95 forks source link

PLG20 swap fails with `nonce too low` error #1288

Closed cipig closed 2 months ago

cipig commented 2 years ago

when i start >1 parallel swaps with PLG20 involved, chances are high that some of them fail with this error: taker_swap:1184] mm2src/coins/eth.rs:1430] "eth:1434] RPC error: Error { code: ServerError(-32000), message: \"nonce too low\", data: None }"

this is from this swap: https://dexapi.cipig.net/public/error.php?uuid=67ef3047-3388-47c9-9dcf-b8db8eb5aced

can we do something about it or does it only happen when PLG20 RPC nodes are not in sync? we use just one node, https://polygon-rpc.com, but idk how many actual nodes are behind this hostname

EDIT: it looks likje the problem appears when i start 2 swaps with taker coin being PLG20... like selling some PLG20 tokens for KMD... chances are high that takerpayment for both swaps are sent out at the exact same time, since both are waiting for the same number of confirmations on KMD (makercoin)... then mm2 tries to send 2 takerpayments on PLG20, one of them resulting in nonce too low... if this is true, then retrying takerpayment a second time (after waiting couple seconds) will solve the issue

artemii235 commented 2 years ago

Let's see first if it will be solved by using RPC node different from https://polygon-rpc.com/.

shamardy commented 1 year ago

@cipig Is this issue still ongoing?

cipig commented 1 year ago

yes, this issue is still there when you try to do more then one swap in parallel with EVM tokens

https://dexapi.cipig.net/public/error.php?uuid=2d37cfa6-cc54-4dd5-9b38-9261c409a6e3 nonce too low https://dexapi.cipig.net/public/error.php?uuid=f2e3ec54-2e52-49d2-9c7a-190d980d1de7 nonce too low https://dexapi.cipig.net/public/error.php?uuid=cc8686ea-b152-4d27-ad8c-ef51d78636f1 nonce too low

is this actually solvable? the EVM chains are serial, they are not made for parallel processing of txes from same address

shamardy commented 1 year ago

https://dexapi.cipig.net/public/error.php?uuid=2d37cfa6-cc54-4dd5-9b38-9261c409a6e3 nonce too low https://dexapi.cipig.net/public/error.php?uuid=f2e3ec54-2e52-49d2-9c7a-190d980d1de7 nonce too low https://dexapi.cipig.net/public/error.php?uuid=cc8686ea-b152-4d27-ad8c-ef51d78636f1 nonce too low

In the above logs an old mm2 version is used, did you get these logs in a more recent version?

shamardy commented 1 year ago

Sorry, I was checking the taker version, maker version is latest release

shamardy commented 1 year ago

But these are all taker error So we still need to make sure if these logs are found in latest version or not :)

shamardy commented 1 year ago

is this actually solvable? the EVM chains are serial, they are not made for parallel processing of txes from same address

Yes, it should be solved since we wait for nonce to be increased in the RPC before sending the next transaction from the API side even if the users tries to send multiple transactions at the same time.

cipig commented 1 year ago

but these are all taker error So we still need to make sure if these logs are found in latest version or not :)

oh, ok, so you mean this should be fixed when both taker and maker have recent mm2 versions i can do tests with my own taker and my makers so i can start more PLG20 swaps at the same time from same taker? i always tried to avoid this or started them with a slight time difference to avoid this nonce errors

shamardy commented 1 year ago

i always tried to avoid this or started them with a slight time difference to avoid this nonce errors

I guess the time difference can still be needed if there are too much swaps for same EVM tokens at the maker side since there is an added delay for waiting for nonce increase in the RPC.

shamardy commented 1 year ago

i can do tests with my own taker and my makers

One last note, I think this is still happening due to the note here https://github.com/KomodoPlatform/atomicDEX-API/pull/1757#issue-1667403269.

Note: This fix might not work for load balanced nodes since we don't have a way to know which node behind the load balancer returned the latest nonce and the transaction might be sent to another node.

So no need to test it with your own taker and makers since the error will still occurs due to using a load balanced node.

shamardy commented 2 months ago

@cipig do you still get this error for PLG20?

cipig commented 2 months ago

@cipig do you still get this error for PLG20?

No, i didn't had any problems with PLG20 since a long time and i regularly start a couple of PLG20 swaps in parallel. Only saw it once last week, but on ARB20 (Arbitrum), the chain we recently added: https://dexapi.cipig.net/public/error.php?uuid=540dc0b6-3b4c-46fa-8d9b-c269cd5a153c ... and it may have been the RPC server itself that had problems at that time ... i guess we can close this issue

shamardy commented 2 months ago

https://github.com/KomodoPlatform/komodo-defi-framework/issues/1288#issuecomment-2256358406