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

ask is removed from orderbook when balance increases #1254

Closed
cipig opened this issue Apr 13, 2022 · 4 comments
Closed

ask is removed from orderbook when balance increases #1254

cipig opened this issue Apr 13, 2022 · 4 comments
Assignees

Comments

@cipig
Copy link
Member

cipig commented Apr 13, 2022

I posted couple asks (and bids) for COIN in different orderbook (COIN/KMD, COIN/LTC...) then sent more COIN to the address. Result: all COIN asks are gone from orderbook, bids are still there. Nothing on console/logs.

@artemii235 artemii235 added the bug label Apr 14, 2022
@onur-ozkan onur-ozkan self-assigned this Apr 14, 2022
@onur-ozkan
Copy link
Member

onur-ozkan commented Apr 16, 2022

I have written couple of scripts to dig into this bug and found out that this bug is not directly related with mm2. The problem comes from the Electrum, blockchain.scripthash.get_balance function doesn't work consistently.

When you send y amount of coin to your wallet, and right after that if you send a rpc call to blockchain.scripthash.get_balance, you will get a result something like

    "confirmed": "x",
    "unconfirmed": y (which you sent)

This will stay as it is for a while. There is no problem with that. After a while, it will become into something like

    "confirmed": "x + y",
    "unconfirmed": 0

And there is no problem with that either. BUT(sorry for caps, need to get attention here), sometimes, electrum will response you with something like this

    "confirmed": "x + y",
    "unconfirmed": y (which must be 0 since it's confirmed and summed with confirmed balance)

This happens rarely and takes approximately 3-4 seconds to be fixed.

screenshots from my script which calls and prints the result of blockchain.scripthash.get_balance rpc function every 0.5 seconds

WhatsApp Image 2022-04-16 at 6 24 50 PM
WhatsApp Image 2022-04-16 at 6 36 36 PM

How does this effect us?

When balance is updated, our balance_updated function triggers, and this line returns 0 to new_volume which takes us to the this line which removes the order of the COIN.

If you track it all the way to the bottom line, it's all about this line. result.confirmed + result.unconfirmed, as I mentioned above, sometimes unconfirmed balance stucks for 2-3 seconds. In this case, this line will calculate your balance as double of your coin which you gain from another address. And when that happens, this line will calculate your sum_outputs_value more than what you actually have, and this line will calculate your sum_inputs as what you actually have. That means, this line will throw an Error and that error will become NotSufficientBalance. And if you log that error, you will see something like Not enough COIN for swap: available x+y, required at least x+(y*2).

We will find a way to overcome this problem manually in our project until they fix it. Thank you for sharing the problem with us!

@tonymorony
Copy link

Oh, thats a great research

This one KomodoPlatform/komodo-wallet#591 might be caused by it

@artemii235
Copy link
Member

@ozkanonur Thanks for the comprehensive research! I even doubt that we should try finding a workaround on the API side - it's worth digging into Electrum code and applying the fix there instead. Let's discuss it in our call today 🙂

@artemii235
Copy link
Member

As we are currently considering alternatives to Electrum, it doesn't worth the effort to find a workaround in the API code.

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

No branches or pull requests

4 participants