Commit aa5bd30
authored
perf(l1): move per-tx BAL validation into the par_iter closure (#6677)
## Summary
`execute_block_parallel` previously returned `(current_state, codes,
shadow_touched, shadow_reads)` per tx and validated them in a serial
post-`par_iter` loop across all txs. Validation is per-tx pure work;
only the marking of `unread_storage_reads` / `unaccessed_pure_accounts`
mutates cross-tx state.
This PR moves `validate_tx_execution` + shadow-touched / shadow-reads
checks into the rayon closure (parallel). The closure also precomputes
the small `(Vec<(Address, H256)>, Vec<Address>)` inputs the serial pass
uses to update the shared sets, so `current_state` + `codes` no longer
cross the rayon boundary.
BAL validation errors are deferred via `Option<EvmError>` in the result
tuple so the post-`par_iter` gas-limit check still takes priority
(preserves `GAS_USED_OVERFLOW` > BAL mismatch on blocks exceeding the
gas limit; the BAL is built assuming rejected txs, so miner balance in
the BAL won't match execution that ran all txs).
## Changes
- `TxExecResult` tuple shrinks from 8 fields (with two heavy
`FxHashMap`s) to 7 fields with `Vec`s only.
- Inside the closure, after `execute_tx_in_block`:
- Compute `reads_satisfied: Vec<(Address, H256)>` (touched storage keys
per non-destroyed account) and `destroyed: Vec<Address>` (selfdestructed
accounts whose remaining BAL storage_reads are wiped) from
`current_state`.
- Run `validate_tx_execution` + shadow-touched + shadow-reads checks;
capture the first error as `Option<EvmError>` (deferred).
- Drop `current_state` and `codes` before returning.
- After `par_iter`:
- Existing 2D gas allowance / breakdowns / block-overflow loop
unchanged.
- **New step**: surface the first deferred BAL error in tx order (only
reached if the gas-limit check passes).
- Apply `reads_satisfied` / `destroyed` to `unread_storage_reads` and
`tracked_accounts` to `unaccessed_pure_accounts` (cheap hash-set ops).
## Invariants
1. **Gas-limit error priority preserved**: the serial pass runs gas / 2D
allowance / block-overflow before surfacing any deferred BAL error.
2. **Tx-order error reporting preserved**: errors are surfaced in sorted
`tx_idx` order; the first failing tx still wins.
3. **Destroyed-account semantics preserved**: the `Destroyed |
DestroyedModified` branch in the unread-reads marking is now an explicit
`Vec<Address>` from the closure; the serial pass does the same
`retain(|&(a, _)| a != addr)` it did before.
4. **No semantic change to validation**: same checks, same error
strings, only the location moves.
## Benchmark
Fixture: `bal-devnet-7-mainnet-mix-460` (460 blocks, ~30 Ggas,
transfer/EVM mix). `release-with-debug`, `import-bench --with-bal`.
Baseline = `feat/import-bench-bal-tooling` (bench tooling only, no perf
change).
| metric | baseline | this PR | delta |
|------------------|---------:|--------:|--------------------|
| wall time | 8.575 s | 7.871 s | **-704 ms (-8.2%)** |
| agg Ggas/s | 3.901 | 4.291 | **+10.0%** |
| avg ms / block | 16.884 | 15.349 | **-1.54 ms (-9.1%)** |
| p95 ms / block | 17.730 | 16.050 | -1.68 ms (-9.5%) |
| max ms / block | 90.060 | 85.000 | -5.06 ms |
| **exec avg** | **15.574 ms** | **14.172 ms** | **-1.40 ms (-9.0%)** |
| merkle | 0.479 ms | 0.412 ms | flat (run variance) |
| store | 0.667 ms | 0.610 ms | flat (run variance) |
| warmer | 1.365 ms | 1.315 ms | flat |
The win is concentrated in `exec` (-9%), which is exactly where the
serial post-`par_iter` validation pass used to live. The merkle / store
/ warmer deltas are within run-to-run variance; this PR doesn't touch
those phases.
Compare dashboard:
<https://edgl.dev/share/compare-feat-import-bench-bal-tooling@02a5663c-vs-perf-bal-validation-into-par-iter@cc8ba27c.html>
## Test plan
- [x] `cargo check --bin ethrex` (default features)
- [x] `cargo fmt --all --check`
- [x] `cargo clippy --workspace --no-deps -- -D warnings`
- [ ] EF blockchain tests (Amsterdam; two-pass parallel runner)
- [ ] Hive `bal` group1 parent d1f8733 commit aa5bd30
2 files changed
Lines changed: 134 additions & 96 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1097 | 1097 | | |
1098 | 1098 | | |
1099 | 1099 | | |
1100 | | - | |
1101 | | - | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
1102 | 1112 | | |
1103 | 1113 | | |
1104 | 1114 | | |
1105 | 1115 | | |
1106 | | - | |
1107 | | - | |
1108 | 1116 | | |
1109 | | - | |
1110 | | - | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
1111 | 1120 | | |
1112 | 1121 | | |
1113 | 1122 | | |
| |||
1173 | 1182 | | |
1174 | 1183 | | |
1175 | 1184 | | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
1176 | 1269 | | |
1177 | 1270 | | |
1178 | 1271 | | |
1179 | 1272 | | |
1180 | | - | |
1181 | | - | |
1182 | 1273 | | |
1183 | | - | |
1184 | | - | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
1185 | 1277 | | |
1186 | 1278 | | |
1187 | 1279 | | |
1188 | 1280 | | |
1189 | 1281 | | |
1190 | 1282 | | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
1200 | | - | |
1201 | | - | |
1202 | | - | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
1203 | 1295 | | |
1204 | 1296 | | |
1205 | 1297 | | |
1206 | | - | |
| 1298 | + | |
1207 | 1299 | | |
1208 | 1300 | | |
1209 | 1301 | | |
| |||
1234 | 1326 | | |
1235 | 1327 | | |
1236 | 1328 | | |
1237 | | - | |
1238 | | - | |
1239 | | - | |
1240 | | - | |
1241 | | - | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
1257 | | - | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
1263 | 1340 | | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
1275 | 1346 | | |
1276 | 1347 | | |
1277 | | - | |
1278 | | - | |
1279 | 1348 | | |
1280 | 1349 | | |
1281 | 1350 | | |
| |||
1285 | 1354 | | |
1286 | 1355 | | |
1287 | 1356 | | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
1308 | | - | |
1309 | | - | |
1310 | | - | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
1315 | | - | |
1316 | | - | |
1317 | | - | |
1318 | | - | |
1319 | | - | |
1320 | 1357 | | |
1321 | 1358 | | |
1322 | | - | |
| 1359 | + | |
1323 | 1360 | | |
1324 | 1361 | | |
1325 | | - | |
| 1362 | + | |
1326 | 1363 | | |
1327 | 1364 | | |
1328 | 1365 | | |
| |||
0 commit comments