Commit 193a1fb
authored
AckSn loop after de/commit is finalized on leader node (#2510)
## Fix: Prevent Infinite AckSn Loop After De/commit
### Problem
After an incremental decommit, snapshot confirmation could get stuck in
an infinite loop where `AckSn` messages were requeued repeatedly,
preventing the snapshot from ever reaching `SnapshotConfirmed` state and
blocking all subsequent snapshots.
**Root Cause:** Race condition on the leader node when
`DecommitFinalized` arrives before `AckSn` messages:
1. Leader requests snapshot N with decommit → state becomes
`RequestedSnapshot{lastSeen=N-1, requested=N}`
2. `DecrementTx` is observed on-chain before `AckSn` messages arrive
3. `DecommitFinalized` aggregate incorrectly used `seenSnapshotNumber()`
which returned `lastSeen` (N-1) instead of `requested` (N)
4. When `AckSn(N)` messages arrived, they failed the guard check `N <=
N-1` and were requeued infinitely
Same scenarion goes also for incremental commits.
### Solution
Modified the `De/commitFinalized` aggregate in `HeadLogic.hs` to use
explicit pattern matching instead of `seenSnapshotNumber()`:
- `NoSeenSnapshot` → `LastSeenSnapshot{lastSeen = 0}`
- `LastSeenSnapshot{lastSeen}` → `LastSeenSnapshot{lastSeen}`
(unchanged)
- `RequestedSnapshot{requested}` → `LastSeenSnapshot{lastSeen =
requested}` ✅ **The fix**
- `SeenSnapshot{snapshot}` → `LastSeenSnapshot{lastSeen = number}`
The key insight: when the leader is in `RequestedSnapshot` state and
`DecommitFinalized` arrives, the decommit belongs to the **requested**
snapshot (N), not the previously confirmed snapshot (N-1).
---
<!-- Consider each and tick it off one way or the other -->
* [x] CHANGELOG updated or not needed
* [x] Documentation updated or not needed
* [x] Haddocks updated or not needed
* [x] No new TODOs introduced or explained herafterFile tree
3 files changed
+154
-9
lines changed- hydra-node
- src/Hydra
- test/Hydra
3 files changed
+154
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1787 | 1787 | | |
1788 | 1788 | | |
1789 | 1789 | | |
1790 | | - | |
1791 | | - | |
1792 | | - | |
1793 | | - | |
| 1790 | + | |
1794 | 1791 | | |
1795 | 1792 | | |
1796 | 1793 | | |
| |||
1815 | 1812 | | |
1816 | 1813 | | |
1817 | 1814 | | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
1818 | 1834 | | |
1819 | 1835 | | |
1820 | 1836 | | |
| |||
2034 | 2050 | | |
2035 | 2051 | | |
2036 | 2052 | | |
2037 | | - | |
2038 | | - | |
2039 | | - | |
2040 | | - | |
| 2053 | + | |
2041 | 2054 | | |
2042 | 2055 | | |
2043 | 2056 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
382 | 385 | | |
383 | 386 | | |
384 | 387 | | |
385 | | - | |
| 388 | + | |
386 | 389 | | |
387 | 390 | | |
388 | 391 | | |
| |||
403 | 406 | | |
404 | 407 | | |
405 | 408 | | |
| 409 | + | |
406 | 410 | | |
407 | 411 | | |
408 | 412 | | |
409 | 413 | | |
410 | 414 | | |
411 | 415 | | |
412 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
413 | 544 | | |
414 | 545 | | |
415 | 546 | | |
| |||
0 commit comments