Commit 04f4e63
Make metrics based bad order detection order specific (#4021)
# Description
Currently the bad token detection assumes that we are perfectly able to
detect "broken" orders and only orders that trade specific tokens that a
particular solver is not able to handle cause problems. However this
assumption does not work well with the increasing complexity of new
order types that can suddenly start failing for any number of reasons.
The most prominent recent example were flashloan orders where the EIP
1271 signature verified correctly but transferring the tokens into the
settlement contract failed because the user's Aave debt position was not
healthy enough.
Our current logic caused a lot of collateral damage because such orders
could cause many reasonable tokens to be flagged as unsupported although
the tokens themselves were perfectly fine and only that particular order
was problematic.
# Changes
To address this this PR change the metrics based detection mechanism to
only flag on an order by order basis instead flagging all orders trading
specific tokens. The change itself is relatively simple (collect metrics
keyed by `Uid` instead of token`) but came with a few related changes:
* the name `bad_token_detection` is now incorrect in most (but not all!)
cases so many things were renamed
* this includes a few config parameters so they must be updated in the
infra repo as well!
* caching uids has a lot more potential to bloat the cache so a cache
eviction task was introduced, this required 2 new config parameters
(max_age, gc_interval)
## How to test
- adjusted existing unit to make sure the metrics logic still works
correctly with `Uid`
- added a new unit test for the cache eviction
## Related issues
Fixes #4019
---------
Co-authored-by: Marcin Szymczak <mail@marszy.com>
Co-authored-by: ilya <ilya@cow.fi>1 parent 1cb027a commit 04f4e63
File tree
18 files changed
+456
-287
lines changed- crates
- driver/src
- domain/competition
- bad_tokens
- order
- risk_detector
- bad_orders
- bad_tokens
- solution
- infra
- api
- config/file
- observe
- simulator
- solver
- e2e/src/setup
18 files changed
+456
-287
lines changedLines changed: 0 additions & 175 deletions
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | 40 | | |
42 | 41 | | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| |||
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
236 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
237 | 241 | | |
238 | 242 | | |
239 | 243 | | |
| |||
243 | 247 | | |
244 | 248 | | |
245 | 249 | | |
246 | | - | |
| 250 | + | |
247 | 251 | | |
248 | 252 | | |
249 | | - | |
| 253 | + | |
250 | 254 | | |
251 | 255 | | |
252 | | - | |
| 256 | + | |
253 | 257 | | |
254 | 258 | | |
255 | 259 | | |
256 | 260 | | |
257 | 261 | | |
258 | | - | |
| 262 | + | |
259 | 263 | | |
260 | 264 | | |
261 | 265 | | |
| |||
741 | 745 | | |
742 | 746 | | |
743 | 747 | | |
744 | | - | |
| 748 | + | |
745 | 749 | | |
746 | 750 | | |
747 | 751 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
211 | 221 | | |
212 | 222 | | |
213 | 223 | | |
214 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
215 | 231 | | |
216 | 232 | | |
217 | 233 | | |
218 | 234 | | |
219 | 235 | | |
220 | | - | |
| 236 | + | |
221 | 237 | | |
222 | 238 | | |
223 | 239 | | |
| |||
0 commit comments