Commit 8e3f82a
committed
ethereum: fix non-transitive trigger ordering causing sort panics
EthereumTrigger::cmp compared Call triggers (and Call/Log pairs) by
transaction_index, but compared Log/Log pairs by log_index alone,
ignoring transaction_index entirely. Those two comparisons only agree
when log_index happens to increase in lockstep with transaction_index
across the whole set being sorted, which isn't guaranteed for every
trigger source. When it doesn't hold, the combined ordering is not
transitive: a Log in an earlier transaction can end up compared as
greater than a Log in a later transaction if the earlier one has a
higher log_index within its own transaction.
This crashes graph-node in production with a panic from Rust's stable
sort ("user-provided comparison function does not correctly implement
a total order") inside BlockWithTriggers::new_with_triggers, which
calls trigger_data.sort() on a freshly-built Vec<Trigger>.
Fix the Log/Log comparison to key on transaction_index first, with
log_index only as a tie-breaker within the same transaction, matching
how Call/Call and Call/Log comparisons already work. Also rewrite the
Call/Log and Log/Call arms with Ordering::then to remove the duplicate
guarded/unguarded match arm pairs, now that both arms share the same
primary-then-secondary-key logic.
Added a regression test (test_trigger_ordering_is_transitive) that
constructs the minimal counter-example and asserts both the pairwise
comparisons and that sorting the resulting Vec doesn't panic.1 parent 6838f4e commit 8e3f82a
2 files changed
Lines changed: 56 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
| |||
0 commit comments