Skip to content

Commit 28b8d61

Browse files
authored
chore: use JUSTIFICATION_LOOKBACK_SLOTS (leanEthereum#131)
* refactor: use JUSTIFICATION_LOOKBACK_SLOTS * fix: docs
1 parent c36739a commit 28b8d61

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/lean_spec/subspecs/forkchoice/store.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from lean_spec.subspecs.chain.config import (
1818
INTERVALS_PER_SLOT,
19+
JUSTIFICATION_LOOKBACK_SLOTS,
1920
SECONDS_PER_INTERVAL,
2021
SECONDS_PER_SLOT,
2122
)
@@ -725,7 +726,8 @@ def get_attestation_target(self) -> Checkpoint:
725726
ensuring the target is in a justifiable slot range:
726727
727728
1. **Start at Head**: Begin with the current head block
728-
2. **Walk Toward Safe**: Move backward (up to 3 steps) if safe target is newer
729+
2. **Walk Toward Safe**: Move backward (up to `JUSTIFICATION_LOOKBACK_SLOTS` steps)
730+
if safe target is newer
729731
3. **Ensure Justifiable**: Continue walking back until slot is justifiable
730732
4. **Return Checkpoint**: Create checkpoint from selected block
731733
@@ -745,11 +747,11 @@ def get_attestation_target(self) -> Checkpoint:
745747
# Start from current head
746748
target_block_root = self.head
747749

748-
# Walk back toward safe target (up to 3 steps)
750+
# Walk back toward safe target (up to `JUSTIFICATION_LOOKBACK_SLOTS` steps)
749751
#
750752
# This ensures the target doesn't advance too far ahead of safe target,
751753
# providing a balance between liveness and safety.
752-
for _ in range(3):
754+
for _ in range(JUSTIFICATION_LOOKBACK_SLOTS):
753755
if self.blocks[target_block_root].slot > self.blocks[self.safe_target].slot:
754756
target_block_root = self.blocks[target_block_root].parent_root
755757

tests/consensus/devnet/fc/test_attestation_target_selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def test_attestation_target_justifiable_constraint(
313313
Justifiability Rules (see Slot.is_justifiable_after)
314314
-----------------------------------------------------
315315
316-
The target starts from current head and walks back at most 3 slots towards safe target.
316+
The target starts from current head and looks back at most 3 slots towards safe target.
317317
318318
Then, a slot is deemed justifiable at distance delta from finalization if:
319319
1. delta ≤ 5

0 commit comments

Comments
 (0)