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

zombie orders #1148

Closed cipig closed 2 years ago

cipig commented 2 years ago

I ran into the same issue that was reported by some users on Discord. I have once placed an order in EFL/LTC orderbook with ADEX Desktop and i can't cancel it anymore. It's the one with the green dot: image

The order is visible in the orderbook on other nodes:

  "base": "EFL",
  "biddepth": 0,
  "bids": [
    {
      "coin": "LTC",
      "address": "LP656iEKoagvqmLiTzAooRSRsLq7RYVEKQ",
      "price": "0.001083828802783928628224529597200696471180611948507897229025549409941374770999367554115715080020643607",
      "price_fraction": {
        "numer": "25000000",
        "denom": "23066373523"
      },
      "maxvolume": "0.0135169",
      "max_volume_fraction": {
        "numer": "135169",
        "denom": "10000000"
      },
      "min_volume": "0.000546",
      "min_volume_fraction": {
        "numer": "273",
        "denom": "500000"
      },
      "pubkey": "039ef1b42c635c32440099910bbe1c5e8b0c9373274c3f21cf1003750fc88d3499",
      "age": 1637356268,
      "zcredits": 0,
      "uuid": "5530f43b-c5f4-40ee-9df3-22d5516b35a6",
      "is_mine": false,
      "base_max_volume": "12.471434570921548",
      "base_min_volume": "0.50376959774232",
      "rel_max_volume": "0.0135169",
      "rel_min_volume": "0.000546",
      "base_max_volume_aggr": "12.471434570921548",
      "rel_max_volume_aggr": "0.0135169"
    },

when querying orderbook from the node the created the order it even shows "is_mine": true, but there is no file on the node that created the order in mm2/DB/2a62e1cabacba3760ac65ee712834423a8eadd83/ORDERS/MY/MAKER/

looking in the logs i could find this entry: 2021-11-19-15-25-57.mm2.log:19 15:26:00, lp_ordermatch:2807] INFO Error maker_swap:1635] utxo_common:2279] utxo_common:534] Not enough LTC for swap: available 0.01351947, required at least 0.08089976, locked by swaps None on balance check to kickstart order 5530f43b-c5f4-40ee-9df3-22d5516b35a6, cancelling

so my LTC balance is lower then needed (or at least mm2 thinks that) and mm2 tried to cancel it during last restart, but the order is still there (in orderbook). but why required at least 0.08089976 for an order that actually only needs 0.0135169? EDIT: the required at least 0.08089976 is from the ask that i initially tried to match with my buy... it didn't match and that order was converted to maker order, but with rel_volume 0.0135169, not 0.08089976

cipig commented 2 years ago

btw, what happens to orders that were created with a much older version of mm2? what if something changes in the rules that apply when you post an order? are those rules rechecked every time or is the order simply taken 1:1 as is? all in all i think it would be best to not save nor restore any orders between mm2 restarts... the clients using mm2 should handle this, if even needed (eg trading bots don't need it)

i guess a possible hotfix would be to make mm2 issue a cancel request for all ismine:true orders that don't have a file in DB/ORDERS/MY... but i fear only a hardfork (changing netid/ports) will make those orders go away

artemii235 commented 2 years ago

when querying orderbook from the node the created the order it even shows "is_mine": true,

is_mine is detected by the order creator's pubkey, it might not exist on a specific node in this case. Do you see it in the my_orders response? Could you please also recheck that there's no other node running with the same passphrase, which has this order in its DB?

cipig commented 2 years ago

there is no other node running with that passphrase the order 5530f43b-c5f4-40ee-9df3-22d5516b35a6 is gone in the meantime, will need to recreate the situation manually again to see what my_orders shows one thing is sure: the file was gone from DB/MY/ORDERS while order was still visible in orderbook i guess the problem is a timing thing... but i also neet to check when and how the order disappeared, i actually expected it to stay in orderbook forever as long as the node with that passphrase is online

cipig commented 2 years ago

i reprocuced the situation:

and orderbook still shows the old order (the one with 23), but it is gone from my_orders

      "coin": "BTX",
      "address": "2GsvnppMrTqW3G4pN7BTynC2YeEfSid3YF",
      "price": "1",
      "maxvolume": "23.00674979",
      "min_volume": "0.000105",
      "pubkey": "039ef1b42c635c32440099910bbe1c5e8b0c9373274c3f21cf1003750fc88d3499",
      "age": 1640096375,
      "zcredits": 0,
      "uuid": "6fb30f23-79d7-414b-83be-156d21dfe3cd",
      "is_mine": false,
      "base_max_volume": "23.00674979",
      "base_min_volume": "0.000105",
      "rel_max_volume": "23.00674979",
      "rel_min_volume": "0.000105",
      "base_max_volume_aggr": "326.863337406",
      "rel_max_volume_aggr": "107.1209414598444745376"
    },

situation can be seen in GUI too image the order is in orderbook and is_mine, but it is gone from my_orders and i can't cancel it, it is a zombie order

cipig commented 2 years ago

the order with uuid 6fb30f23-79d7-414b-83be-156d21dfe3cd is still in orderbook... i restarted ADEX Desktop some hours ago, but it didn't help... the error on order kickstart was not shown, since file of order was already removed on last restart

artemii235 commented 2 years ago

@cipig Could you please check that it is fixed in the https://github.com/KomodoPlatform/atomicDEX-API/tree/zombie_orders_fix branch?

cipig commented 2 years ago

built ADEX Desktop with mm2 from this branch and recreated the above situation created a sell order with the entire amount, withdrew some BTX, result: orderbook updated with new balance, my_orders showing old value after restart of ADEX Desktop the order is updated in my_orders too showing new value, order uuid same, order in orderbook still fine order showing up in my_orders, so it can be cancelled, disappearing from orderbook too no more zombie orders, problem fixed, thanks a lot

artemii235 commented 2 years ago

@cipig Great, thanks! Could you please retest the https://github.com/KomodoPlatform/atomicDEX-API/pull/1179? I made one more important change to properly set the new max_base_vol.

cipig commented 2 years ago

image nice, my_orders is now also updated right after withdraw (initial sell was for 6 BTX, then i withdrew some) all good after restart too, order is recreated and visible in my_orders and orderbook with updated volume