Closed offerm closed 6 years ago
I believe this is related to #478 - the order is being invalidated twice on swap. All the more reason we don't send order invalidation packets to the peer we just swapped the order with. I created a test case for the order book to try to simulate locally and it passes, I'll open a PR for that because canceling a partially filled order is a good test case to have but it's separate from this. I think separate from fixing #478 we'd probably also need to gracefully handle the case where a peer tries to invalidate an order for a greater quantity than what we currently show available, which is what's happening here.
Not sure I understand the reason for the failure here. Can you explain this before we get for a solution?
I also not follow the terminology of invalidated
. Does it mean removed
?
later you mentioned cancel
It is also not clear to me why the order was removed at by the maker when only part of it was executed.
Yeah, an invalidation is the term for the packet to tell peers that one of our orders is no longer available/valid. The cause can be either due to cancellation or to the order being filled, but the peer doesn't have to know that.
I haven't dug very deeply into this yet but I believe what's happening is this:
Exchange A places 0.004 buy order Exchange B places 0.003 matching sell order Swap successful, exchange B reduces the quantity of the buy order to 0.001 Exchange A broadcasts to all its peers (here is the problem, tracked in #478, it should not send packet to the peer it swapped with) an order invalidation packet saying "hey, 0.003 of my 0.004 buy order is no longer available Exchange B receives the packet, and tries to reduce the quantity of the order by 0.003, but that's more than the current quantity of the order which is 0.001, so we get this error
Well, the invalidation message can be "hey, only 0.001 letf". This can work also with the taker.
In our case the message is "hey, undefined of my 0.004 buy order is no longer available"
9/20/2018, 6:16:42 PM [SWAPS] debug: Executing taker code
9/20/2018, 6:16:42 PM [SWAPS] debug: Amount received for preImage ce6e2b054d0e0349bc5b1d25edfa3959500502dae0c4ec54a4f79c7923d48080
9/20/2018, 6:16:42 PM [P2P] verbose: canceled order from 0235584e2ac9a34a13ce6f6dc9fb8aa1e7918d7701f0b4b69dc002887e6b3fbba3: {"orderId":"2c603fe1-bce8-11e8-bbca-2df4bee4f24d","pairId":"LTC/BTC"}
9/20/2018, 6:16:42 PM [ORDERBOOK] info: order.quantity = 0.001
9/20/2018, 6:16:42 PM [ORDERBOOK] info: quantityToDecrease = undefined
{ AssertionError [ERR_ASSERTION]: order quantity must equal quantityToDecrease
at OrderBook.removePeerOrder (/Users/admin/github/xud/dist/orderbook/OrderBook.js:261:33)
at Pool.pool.on.order (/Users/admin/github/xud/dist/orderbook/OrderBook.js:50:72)
at Pool.emit (events.js:182:13)
at Pool.<anonymous> (/Users/admin/github/xud/dist/p2p/Pool.js:275:26)
at Generator.next (<anonymous>)
at /Users/admin/github/xud/dist/p2p/Pool.js:7:71
See what I did and what I got.