Skip to content

Return error on order replacement when it's not safe #3315

@MartinquaXD

Description

@MartinquaXD

Background

One nice QoL feature in the frontend would be to allow users to "edit" orders. In reality orders can not be edited and what we do instead is to allow users to tell us which order they would like to cancel when creating a new order. This effectively replaces the original version with the "edited" version.

One concern the frontend team has is that this could lead to double spending under some race conditions.
Specifically when your original order is part of the current auction and the winning solver intends to settle it. If you were to send a replacement while the auction is running the original order could still get settled AND you submit another order which also might get settled leading you to spend twice as many sell tokens as intended.

Details

The goal of this issue is to eliminate this issue as much as possible. I believe the simplest way would be to just check in the replacement API call that no solver bid on the original order in the last few auctions. That can be done by scanning the last few entries of the solver_competitions table for solutions containing the original order uid.
If that is not the case it's very unlikely that the solver would suddenly settle the original order in the current auction.

Acceptance criteria

If the backend detects that replacing an order could lead to double spending because solvers are already bidding on the original order it should return a helpful error briefly message explaining the issue.

Additionally this logic could be applied to the cancellation endpoint. IMO for cancellations we should not reject the cancellation entirely but should return a message indicating that we received the cancellation but it might not go through if solvers have been bidding on the order.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions