chore(storage): Add error handling on Store::get_forkchoice_store#362
chore(storage): Add error handling on Store::get_forkchoice_store#362Aliemeka wants to merge 3 commits into
Store::get_forkchoice_store#362Conversation
Greptile SummaryThis PR converts
Confidence Score: 5/5Safe to merge — the change is a straightforward replacement of a single assert_eq! with a typed Result return; no validation logic is altered. The diff is narrow and mechanical: one assertion becomes an if-guard returning Err, one new error enum is introduced with thiserror, and every call site is updated. The zeroing of state_root before comparison — the only subtlety in the original code — is preserved exactly. The remaining assert! calls inside init_store are explicitly out of scope and untouched. No files require special attention.
|
| Filename | Overview |
|---|---|
| crates/storage/src/store.rs | Introduces GetForkchoiceStoreError::HeaderMismatch and converts get_forkchoice_store from a panicking function to Result<Self, GetForkchoiceStoreError>; logic is unchanged. |
| crates/storage/src/lib.rs | Re-exports the new GetForkchoiceStoreError type so downstream crates can match on the error variant. |
| crates/storage/Cargo.toml | Adds thiserror as a workspace dependency to support the new error derive macro. |
| crates/blockchain/src/store.rs | Updates the internal unit test call site to use .expect(...) on the now-fallible get_forkchoice_store. |
| crates/blockchain/tests/forkchoice_spectests.rs | Updates spec-test harness call site to .expect(...) on the fallible constructor. |
| crates/blockchain/tests/signature_spectests.rs | Updates signature spec-test harness call site to .expect(...) on the fallible constructor. |
Sequence Diagram
sequenceDiagram
participant Caller
participant get_forkchoice_store
participant init_store
Caller->>get_forkchoice_store: (backend, anchor_state, anchor_block)
get_forkchoice_store->>get_forkchoice_store: zero state_root on both headers
alt headers match
get_forkchoice_store->>init_store: (backend, anchor_state, Some(anchor_block.body))
init_store-->>get_forkchoice_store: Store
get_forkchoice_store-->>Caller: Ok(Store)
else headers differ
get_forkchoice_store-->>Caller: "Err(HeaderMismatch { state_header, block_header })"
end
Reviews (1): Last reviewed commit: "chore(storage): Add error handling on `S..." | Re-trigger Greptile
|
Hi @Aliemeka. Thanks for your contribution. You must sign your commits. You can check that in here: |
ff86b5b to
f0743c6
Compare
f0743c6 to
6e362d0
Compare
|
So sorry for force pushing. I just got confused about signing my commit |
🗒️ 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 closes #360.
What Changed
crates/storage/Cargo.toml— addthiserrordependency.crates/storage/src/store.rs— introducepub enum GetForkchoiceStoreErrorwith aHeaderMismatch { state_header, block_header }variant; changeStore::get_forkchoice_storeto returnResult<Self, GetForkchoiceStoreError>; replace the assertion with an explicit comparison that returnsErr; update the doc comment (# Panics→# Errors).Correctness / Behavior Guarantees
latest_block_headerafter zeroingstate_root. Mismatches that previously aborted via assert_eq! now returnErr(HeaderMismatch { … }), surfacing both full headers (boxed to keep the variant small) for diff-friendly debugging.Store::from_anchor_stateis untouched. Internal panics ininit_store(state_rootmismatch 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
make fmt,make lint,cargo test --workspace --release(unit tests pass; spec tests requiremake leanSpec/fixturesfor fixture generation)make testRelated Issues / PRs
Store::get_forkchoice_store#360✅ Verification Checklist
make fmt— cleanmake lint(clippy with-D warnings) — cleancargo test --workspace --release— all passing