Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a fix for a race condition where an in-flight order could be incorrectly marked as invalid. The change involves fetching in-flight orders from the database and filtering them out from the sets of invalid and filtered orders before storing order events. The implementation is correct and effectively addresses the described issue. The error handling for fetching in-flight orders is graceful, falling back to the previous behavior in case of failure. No critical issues were found in this change.
Note: Security Review did not run due to the size of the PR.
jmg-duarte
left a comment
There was a problem hiding this comment.
The code and the idea make sense to me, but the comment makes everything confusing again
| // An in-flight order already won a previous auction and is being | ||
| // submitted on-chain. It may still fail filters here (e.g. expiry, | ||
| // missing native price), but emitting Invalid/Filtered for it would | ||
| // be misleading since it's about to become Traded. |
There was a problem hiding this comment.
This is a bit hard to read. Do you mean "in-flight order that already won"? And what filters do you mean?
If the order is submitted on chain and fails, why would placing an invalid be misleading?
There was a problem hiding this comment.
If the order is submitted on chain and fails, why would placing an invalid be misleading?
Because there is nothing wrong with the order. The solver probably set too low a gas price so the submitted order didn't settle.
Let me tweak the wording a bit though.
squadgazzz
left a comment
There was a problem hiding this comment.
Should we exclude in-flight orders from the cache before we even store any events?
A just question. I don't know; I think we might want to filter them, but I imagine we might want solvers to keep producing solutions in case the settlement doesn't land on chain. |
|
I mean, something seems off to me. I see 2 options:
I am more in favor of the first option, but I haven't dived deeper to understand all the implications. |
Okay, I think we can do this: https://github.com/cowprotocol/services/pull/4241/changes – instead of filtering in-flight orders later when cutting the auction we can just omit them when building the live orders cache. That change feels a bit less safe, but it's the healthier approach for the codebase & performance (we don't look up in-flight orders twice). What say you? |
Description
When I was working on another feature (the debug endpoint) I noticed that there is a race condition where we sometimes insert "invalid" order event to the DB.
From logs
Order is in
executingstate, then settles onchain. If the indexing runs now and we set the order totradedall is well. However if the in cache update runs first it's possible the wallet no longer has the necessary balance as it was traded away in the just executed swap and we consider it invalid and we insert the invalid event for an order that went through perfectly well.Changes
How to test
I had an e2e test to reproduce this which failed 6/10 times. After the fix it fails 0/10.