KomodoPlatform / komodo-defi-framework

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

Maker order doesn't disappear from orderbook after fullfill #1187

Open tonymorony opened 2 years ago

tonymorony commented 2 years ago

API version (latest published release), OS Ubuntu:

curl --url "http://127.0.0.1:7783" --data "{
>   \"method\":\"version\",
>   \"userpass\":\"$userpass\"
> }"
{"result":"2.1.5182_mm2.1_0fea16d6b_Linux_Release","datetime":"2021-12-29T19:27:20+07:00"}

1) I've placed an order:

curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"setprice\",\"base\":\"KMD\",\"rel\":\"TKL\",\"price\":\"12.4\",\"max\":true}"
{"result":{"base":"KMD","rel":"TKL","price":"12.4","price_rat":[[1,[62]],[1,[5]]],"max_base_vol":"217.40887888","max_base_vol_rat":[[1,[1358805493]],[1,[6250000]]],"min_base_vol":"0.0001","min_base_vol_rat":[[1,[1]],[1,[10000]]],"created_at":1641316167871,"updated_at":1641316167871,"matches":{},"started_swaps":[],"uuid":"3f3f4394-374a-40e7-978a-bac0360fb31f","conf_settings":{"base_confs":2,"base_nota":true,"rel_confs":2,"rel_nota":true},"base_orderbook_ticker":null,"rel_orderbook_ticker":null}}

2) It was fully filled and the trade successfully finished. swap status on my node: https://0bin.net/paste/TxrOHXso#nULc2l0yudaW2WCwbN1Q6rrob8yCMC2JvoW+xTGQdXm

3) At the moment of writing order has not disappeared from order books globally and volume remained the same (added screenshot for simplicity and since it's 3rd party node, also checked order book call on my and other nodes and it's here)

Screenshot 2022-01-05 at 02 13 28

orderbook call output: https://transfer.sh/MdfpJS/tkl_orderbook.json

there is nothing in my orders

curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"my_orders\"}"
{"result":{"maker_orders":{},"taker_orders":{}}}

but order detecting as is_mine in orderbook call output (full output can be found by transfer.sh link above)

      "uuid": "3f3f4394-374a-40e7-978a-bac0360fb31f",
      "is_mine": true,
      "base_max_volume": "217.40887888"

my balance after the swap is almost 0:

image

according to stdout swap started/finished just fine:

| (63:43) [swap uuid=12aafd7e-c0e7-481e-a01c-522f1e0e8292] Taker payment send wait confirm started...
04 18:56:17, coins:rpc_clients:150] INFO Waiting for tx 3b0ced01167fe0c5d010940c2dd4780c0a8b43004b9b9fe3e4bcad6bbbbd0be6
 confirmations, now 0, required 1, requires_notarization false
04 18:56:32, coins:rpc_clients:150] INFO Waiting for tx 3b0ced01167fe0c5d010940c2dd4780c0a8b43004b9b9fe3e4bcad6bbbbd0be6
 confirmations, now 0, required 1, requires_notarization false
+--- 04 18:56:38 -------
| (64:07) [swap uuid=12aafd7e-c0e7-481e-a01c-522f1e0e8292] Taker payment send wait confirm started...
04 18:56:47, coins:rpc_clients:150] INFO Waiting for tx 3b0ced01167fe0c5d010940c2dd4780c0a8b43004b9b9fe3e4bcad6bbbbd0be6
 confirmations, now 0, required 1, requires_notarization false
· 2022-01-04 19:57:02 +0100 [swap uuid=12aafd7e-c0e7-481e-a01c-522f1e0e8292] Finished

I'll try to isolate tomorrow:

a) if it happens with max true flag only or not b) maybe it's related to the fact that I had opened GUI with the same pubkey (but without any orders placed on another PC)?

@cipig @smk762 could you please also have a look?

CC [ @sergeyboyko0791 @shamardy ]

tonymorony commented 2 years ago

upd: now (after ~15 minutes after matching) this order disappeared from orderbook 🤔 upd2: appeared back 🤔

cipig commented 2 years ago

would be interesting to know if it happens with mm2 from dev branch too i am running dev branch on all my mm2-API nodes (mm2.1 branch deadlocks here) and haven't seen the error i don't use max:true in my mm-script b) sounds likely order still visible on all my nodes:

  "bids": [
    {
      "coin": "KMD",
      "address": "RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT",
      "price": "0.08064516129032258064516129032258064516129032258064516129032258064516129032258064516129032258064516129",
      "maxvolume": "217.40887888",
      "min_volume": "0.0001",
      "pubkey": "03aa464529c190398d44017c3d7a71a854ad195a9d396bf84182679c242bb60085",
      "age": 1641325048,
      "zcredits": 0,
      "uuid": "3f3f4394-374a-40e7-978a-bac0360fb31f",
      "is_mine": false,
      "base_max_volume": "2695.870098112",
      "base_min_volume": "0.00124",
      "rel_max_volume": "217.40887888",
      "rel_min_volume": "0.0001",
      "base_max_volume_aggr": "2695.870098112",
      "rel_max_volume_aggr": "217.40887888"
    },
cipig commented 2 years ago

this worked fine https://github.com/KomodoPlatform/atomicDEX-API/issues/1012#issuecomment-1003489233 on ADEX Desktop, with same mm2 version as yours... not the same scenario, but similar (balance was not enough any more and order was cancelled)

tonymorony commented 2 years ago

b) sounds likely

yeah, looks like the most probable reason so far. just excluded factor b and placed/fulfilled the order with max vol flag and no "ghost" order created this time

after I stopped the maker node, KMD/TKL order disappeared from orderbook so the problem looks not critical on this point - sorry for tagging everyone, when noticed at first thought it's something really bad 😊

artemii235 commented 2 years ago

b) maybe it's related to the fact that I had opened GUI with the same pubkey (but without any orders placed on another PC)?

In this case, the second GUI can import the orderbook and start broadcasting keep alive (and maybe other orderbook syncing messages) to the network causing synchronization problems. That is one of the "Undefined behavior" cases caused by running several nodes with the same privkey. It seems that we need to somehow deny it in the beginning until we figure out how to handle this gracefully (which looks like a quite complicated task).

tonymorony commented 2 years ago

In this case, the second GUI can import the orderbook and start broadcasting keep alive (and maybe other orderbook syncing messages) to the network causing synchronization problems.

the clue is that the order stayed in the order book even after I shut down the GUI, it disappeared only after I shutdown CLI maker where I originally placed the order

artemii235 commented 2 years ago

I think I have some ideas on how to fix it, will provide more details when we will have resources to work on this task.