-
Notifications
You must be signed in to change notification settings - Fork 77
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
chore: check order cancellations before picking a winner #2532
Comments
Currently, cancelling an order (and thus voiding the current auction) costs some gas and is thus something that doesn't make sense to do at scale. This, plus the fact that we cannot fully prevent the race condition as you describe make this solution in my opinion inferior to simply not including a replacement order in the auction if the original order has been traded already. |
To implement your suggestion we could add a new column to the orders table like I think this scheme would also work for partially executed cancelled orders. Although there is an argument to be made that the user might need to be informed that the remaining unfilled amount will not be filled anymore because of this scheme. |
For the recursive case I think we should ask the frontend to send us a list of all order uids which should be mutually exclusive (for this order to make it into the batch). This way wo don't have weird edge cases with expired orders but only include an order if none of the "replaced" orders are either still part of the auction or have a trade. |
Thanks @MartinquaXD for putting this together. I also did a writeup explaining the issue, and the potential mitigation that in our opinion would be good enough: https://www.notion.so/cownation/Canceling-Replace-Orders-Edge-Case-5f1d0d38e3f541e7b454f8e7faa7fee1?pvs=4 Basically, agree with most of the comments above:
|
This issue has been marked as stale because it has been inactive a while. Please update this issue or it will be automatically closed. |
No need to fix this now, but let's not close it Mr. Stale bot |
You need to remove the stale label on the issue in that case... |
This issue has been marked as stale because it has been inactive a while. Please update this issue or it will be automatically closed. |
This issue has been marked as stale because it has been inactive a while. Please update this issue or it will be automatically closed. |
Background
Using off-chain mechanisms to cancel an order is inherently racy. If an order gets off-chain cancelled while a solver already tries to bring a solution for it on-chain it will get solved although it will be marked as cancelled in our DB.
This is a known and even documented issue but has not been causing too many problems because the order cancellation / replacement endpoints have not been used a lot.
However, with the initiative to make the frontend "feel" faster we will make more liberal use of these features which will probably result in more people run into these cancellation race conditions.
Details
To limit the time where the race condition can happen to a minimum we should probably check if all orders that a solver tries to settle are in fact still open and not cancelled. That way the race condition windows shrinks from the order being put into the next auction until the order being settled on chain to just the time where a solver tries to bring the solution on chain.
That means we reduce the race limit window by at least 15 seconds but on average longer than that.
Acceptance criteria
Before picking a winner we make sure that all orders the solver intends to settle have not been cancelled in the mean time.
Considerations
This is slightly unfortunate because currently solvers assume all orders in the auction are fair game so it could happen that they play fairly, compute an excellent solution but still don't win the auction.
But since it can be expected that these cancellation events are on average distributed fairly across all solvers none of them should have an advantage over the others.
The text was updated successfully, but these errors were encountered: