project-serum/serum-dex

Redundant cancel order event

xjcaa opened this issue · 2 comments

xjcaa commented

I noticed that when you call process_cancel_order_v2, it'll release the funds in the open orders account and push an Out event onto the event queue.

When consuming the Out event, it doesn't do anything past remove the order from open orders account if native_qty_still_locked == 0 which it always is on the new event.

Is there a benefit of having this event or can it be handled entirely in the cancel transaction?

When the cancel instruction runs, there may be partial fills in the event queue for the same order. The order needs to be present in the open orders account when those fills are consumed, to avoid use-after-free bugs. The benefit of waiting until the Out event is processed is that it ensures those conditions are met.

xjcaa commented

Thanks @sconybeare, appreciate it.