Commit ea08e26
fix: skip finalization advance for stale finalized sources (#405)
## Summary
Ports [leanSpec #802](leanEthereum/leanSpec#802)
to ethlambda.
A supermajority attestation whose source checkpoint sits **at or behind
the finalized boundary** is a valid justification anchor
(`is_slot_justified` treats slots `<= finalized.slot` as already
justified), so it may justify a newer target. But once it crosses the
supermajority threshold, the finalization logic scanned `source.slot + 1
.. target.slot` and could try to advance (rewind/re-finalize) below the
finalized boundary.
The fix gates finalization advancement on `source.slot >
finalized_slot`. Stale or boundary sources may still justify newer
targets; they no longer try to rewind or scan below the finalized
boundary.
## Relationship to #402
This supersedes
[#402](#402) (`fix(stf):
reject blocks justifying a target whose source is below finalized`),
which was the pre-#802 attempt that fixed the issue by *rejecting* such
blocks. The spec instead **accepts** the justification and only skips
the finalization advance, so this PR follows the merged spec approach.
#402 can be closed in favor of this.
## Changes
Two mirrored spots get the `source.slot > finalized_slot` guard:
| Location | Role |
|----------|------|
| `try_finalize` (state transition) | The actual finalization advance |
| `score_entry` (block builder) | Projects/scores finalization while
packing blocks |
## Tests
- `state_transition`:
`stale_finalized_source_justifies_without_rewinding_finalization` —
supermajority from a stale source justifies the target while
finalization stays pinned.
- `block_builder`: `score_entry_does_not_finalize_source_at_boundary` —
a boundary source is scored `Justify`, not `Finalize`.
```
cargo test -p ethlambda-state-transition --lib # 2 passed
cargo test -p ethlambda-blockchain --lib block_builder # 8 passed
```
fmt + clippy (`-D warnings`) clean on both crates.
Co-authored-by: Pablo Deymonnaz <pdeymon@fi.uba.ar>1 parent 8e1fadb commit ea08e26
2 files changed
Lines changed: 133 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | | - | |
368 | | - | |
369 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
370 | 373 | | |
| 374 | + | |
371 | 375 | | |
372 | 376 | | |
373 | 377 | | |
| |||
688 | 692 | | |
689 | 693 | | |
690 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
691 | 741 | | |
692 | 742 | | |
693 | 743 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
390 | | - | |
391 | | - | |
392 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
393 | 396 | | |
394 | 397 | | |
395 | 398 | | |
396 | 399 | | |
397 | 400 | | |
398 | 401 | | |
399 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
400 | 409 | | |
401 | 410 | | |
402 | 411 | | |
| |||
683 | 692 | | |
684 | 693 | | |
685 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
686 | 763 | | |
0 commit comments