You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(storage): Add error handling on Store::get_forkchoice_store (lambdaclass#362)
## 🗒️ Description / Motivation
Replace the assert_eq! in Store::get_forkchoice_store with a typed
Result so callers see a descriptive error instead of a panic. The
previous message ("block header doesn't match state's
latest_block_header") gave no insight into which field actually
differed, which made misconfigured anchor state/block pairs hard to
diagnose. PR closeslambdaclass#360.
## What Changed
- `crates/storage/Cargo.toml` — add `thiserror` dependency.
- `crates/storage/src/store.rs` — introduce `pub enum
GetForkchoiceStoreError` with a `HeaderMismatch { state_header,
block_header }` variant; change `Store::get_forkchoice_store` to return
`Result<Self, GetForkchoiceStoreError>`; replace the assertion with an
explicit comparison that returns `Err`; update the doc comment (`#
Panics` → `# Errors`).
- `bin/ethlambda/src/main.rs` — added error handling to
`Store::forkchoice_store` to return
`CheckpointSyncError::AnchorPairingMismatch` if there is a mismatch.
## Correctness / Behavior Guarantees
- The validation rule is unchanged: anchor block header must equal the
state's `latest_block_header` after zeroing `state_root`. Mismatches
that previously aborted via assert_eq! now return `Err(HeaderMismatch {
… })`, surfacing both full headers (boxed to keep the variant small) for
diff-friendly debugging.
- `Store::from_anchor_state` is untouched. Internal panics in
`init_store` (`state_root` mismatch and storage backend operations) are
intentionally left as-is — they represent infrastructure invariants
shared between both constructors and are out of scope for this change.
## Tests Added / Run
- No new tests; the type change is enforced by the compiler and existing
fork-choice / signature spec suites continue to exercise the success
path.
- Ran `make fmt`, `make lint`, `cargo test --workspace --release` (unit
tests pass; spec tests require `make leanSpec/fixtures` for fixture
generation)
- Also ran `make test`
## Related Issues / PRs
- Closeslambdaclass#360
## ✅ Verification Checklist
- [x] Ran `make fmt` — clean
- [x] Ran `make lint` (clippy with `-D warnings`) — clean
- [x] Ran `cargo test --workspace --release` — all passing
---------
Co-authored-by: Pablo Deymonnaz <pdeymon@fi.uba.ar>
0 commit comments