refactor: parallelize invariants#5676
Conversation
| let Ok(InvariantFuzzTestResult { invariants, cases, reverts, last_run_inputs }) = | ||
| evm.invariant_fuzz(&invariant_contract) | ||
| else { | ||
| return vec![] |
There was a problem hiding this comment.
This error was just completely ignored for some reason. This gets thrown by prepare_fuzzing
There was a problem hiding this comment.
Yeah, I think there's a few more cases of this happening across the test runner. I have a pending refactor of another error being ignored on invariants
Evalir
left a comment
There was a problem hiding this comment.
I love this—there's a ton we can refactor here but this is great to reduce performance bottlenecks 😄
Let's just make sure we test this a ton before merge!
Evalir
left a comment
There was a problem hiding this comment.
I love this—there's a ton we can refactor here but this is great to reduce performance bottlenecks 😄
Let's just make sure we test this a ton before merge!
| // Hacky to provide the full error to the user. | ||
| for invariant in invariant_contract.invariant_functions.iter() { | ||
| failures.failed_invariants.insert( | ||
| invariant.name.clone(), | ||
| (Some(error.clone()), invariant.to_owned().clone()), | ||
| ); | ||
| } |
There was a problem hiding this comment.
Only one invariant is executed at a time now so there can't be multiple fails in one call to this function
There was a problem hiding this comment.
Can you take a look at #5726 pls? I think a bug was introduced but I can't manage to find when or where
* refactor: parallelize invariants * chore: clippy * collect before
Motivation
Most of the invariant code is written as if it handles multiple functions per call (e.g. argument is
&[Function]instead of&Functionetc.).This is fine, except we call these functions with
vec![function]in a loop over the functions...Recommended to review with "Hide whitespace" since this gets rid of a lot of indentation
Solution
Rewrite invariants to run one function at a time, and parallelize the top level loop