refactor(storage): add Store::current_slot - #570
Conversation
ethlambda-storage derives slot and interval from `store.time()` but cannot depend on ethlambda-blockchain, so it could only document the formula in a comment rather than use the constants. Housing MILLISECONDS_PER_INTERVAL, INTERVALS_PER_SLOT and MILLISECONDS_PER_SLOT in ethlambda-types — which both crates already depend on — removes that asymmetry and keeps a second copy of a consensus-critical constant from appearing in storage. Values are unchanged; blockchain re-exports all three so existing imports keep resolving.
Deriving the slot from the store clock was open-coded at three call sites in the blockchain crate, each repeating the division and its own expect message. Now that the interval grid lives in ethlambda-types, storage can own the accessor.
🤖 Kimi Code ReviewThis is a clean refactoring that properly centralizes slot calculation logic. The changes are correct and improve maintainability. Approval with minor observations:
Verdict: LGTM. The refactoring reduces duplication without changing consensus-critical behavior. Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Claude Code ReviewThis is a clean, correctly scoped refactor. Verified the behavior claim holds — FindingsStale doc comment now duplicates the formula The doc comment directly above Everything else is solid:
Automated review by Claude (Anthropic) · sonnet · custom prompt |

🗒️ Description / Motivation
Extracted from #561. Stacked on #569, which is what makes it possible: with the interval grid in
ethlambda-types,ethlambda-storagecan own the accessor.Deriving the slot from the store clock was open-coded at three call sites in the blockchain crate, each repeating
store.time() / INTERVALS_PER_SLOTalong with its ownexpectmessage.Note
Targets
refactor/interval-constants-in-types. Merge #569 first and this rebases ontomainon its own.What Changed
crates/storage/src/store.rs— newStore::current_slot(); theStore::time()doc comment now points at it for the slot case rather than spelling out the division.crates/blockchain/src/store.rs— two call sites (on_tick,on_block_core).crates/blockchain/src/lib.rs— one call site (theNewAttestationhandler).Correctness / Behavior Guarantees
Identical behavior. All three sites already panicked on a failed
time()read (unwrap/expect), socurrent_slot()'sexpect("store time exists")preserves the failure mode; only the panic message differs at two of them.Uses of
INTERVALS_PER_SLOTthat are not "derive the current slot from the clock" are deliberately untouched: the% INTERVALS_PER_SLOTinterval derivation,data.slot.saturating_mul(INTERVALS_PER_SLOT), the tick skip-check, and theset_time(n * INTERVALS_PER_SLOT)calls in tests.Tests Added / Run
No new tests — no behavior change to cover.
Related Issues / PRs
✅ Verification Checklist
make fmt— cleanmake lint(clippy with-D warnings) — cleanmake test(cargo test --workspace --profile release-fast) — all passing