Commit 3ca2d36
authored
feat: skip simulation when enforced simulations container is active (#8431)
## Explanation
When a transaction has the `EnforcedSimulations` container type, the
simulation is redundant since the enforced simulation flow handles
balance change protection separately. This PR skips the standard
simulation in that case to avoid unnecessary network calls and potential
conflicts.
## Changes
- Skip balance change simulation when `containerTypes` includes
`EnforcedSimulations`
- Re-check `containerTypes` in the update callback to handle the race
condition where simulation starts before the container type is set
- Use fresh state from `skipSimulationTransactionIds` in the callback
instead of a stale closure, fixing an issue where toggling enforced
simulations off would not restore balance changes
## References
- Extension PR:
MetaMask/metamask-extension#41126
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes when/if `simulationData` is produced and persisted during
transaction updates, which could affect balance-change protection
behavior and downstream consumers that expect simulation results. Scope
is contained and covered by a new unit test, but it touches core
transaction lifecycle logic.
>
> **Overview**
> Transactions marked with `containerTypes: [EnforcedSimulations]` now
**skip balance-change simulation** (and avoid `getBalanceChanges` calls)
when editable params change and would otherwise trigger re-simulation.
>
> The simulation update path now re-checks the latest
`containerTypes`/skip state inside the state update callback via a new
`#isBalanceChangesSkipped` helper to avoid race conditions and prevent
persisting `simulationData` when simulation is meant to be bypassed.
Changelog updated and a regression test added to assert simulation is
not re-run in this mode.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
b1b0199. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 90d8093 commit 3ca2d36
3 files changed
Lines changed: 47 additions & 3 deletions
File tree
- packages/transaction-controller
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2345 | 2345 | | |
2346 | 2346 | | |
2347 | 2347 | | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
2348 | 2379 | | |
2349 | 2380 | | |
2350 | 2381 | | |
| |||
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
| |||
131 | 130 | | |
132 | 131 | | |
133 | 132 | | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
4241 | 4241 | | |
4242 | 4242 | | |
4243 | 4243 | | |
| 4244 | + | |
| 4245 | + | |
| 4246 | + | |
| 4247 | + | |
| 4248 | + | |
| 4249 | + | |
| 4250 | + | |
| 4251 | + | |
| 4252 | + | |
4244 | 4253 | | |
4245 | 4254 | | |
4246 | 4255 | | |
| |||
4272 | 4281 | | |
4273 | 4282 | | |
4274 | 4283 | | |
4275 | | - | |
| 4284 | + | |
4276 | 4285 | | |
4277 | 4286 | | |
4278 | 4287 | | |
| |||
4336 | 4345 | | |
4337 | 4346 | | |
4338 | 4347 | | |
4339 | | - | |
| 4348 | + | |
4340 | 4349 | | |
4341 | 4350 | | |
4342 | 4351 | | |
| |||
0 commit comments