Repository navigation
feat: make store begin_write callers return Result and update callers - #468
MegaRedHand merged 4 commits into
Conversation
Greptile SummaryThis PR updates 7 public/private
Confidence Score: 4/5The changes are mechanical and the runtime behavior is unchanged — storage failures still terminate via panic, as before. Safe to merge as an intermediate refactor step. The actual runtime behavior is identical to before: all storage write failures cause a panic through the still-present internal
|
| Filename | Overview |
|---|---|
| crates/storage/src/store.rs | Core change: 7 public/private methods updated to return Result<T, Error>, but all still use .expect() internally — errors panic rather than propagate. Includes an empty .expect("") message in a test and asymmetric treatment of set_time/set_safe_target. |
| bin/ethlambda/src/main.rs | Uses .expect() on the new insert_signed_block Result inside fetch_initial_state, which already returns Result and handles other errors via map_err — missed opportunity for consistent error propagation. |
| crates/blockchain/src/lib.rs | Updated insert_pending_block call to handle new Result return type with .expect(), consistent with the stepping-stone approach of the PR. |
| crates/blockchain/src/store.rs | Updated six call sites (update_checkpoints, insert_signed_block, insert_state) in production and test code to handle new Result return types with .expect(); changes are mechanical and correct. |
| crates/blockchain/src/reaggregate.rs | Test-only change: update_checkpoints call in a unit test now handles the Result return type with a descriptive .expect(). |
| crates/net/p2p/src/req_resp/handlers.rs | Test-only change: five insert_signed_block / update_checkpoints call sites updated with .expect() to handle new Result return types. |
| crates/net/rpc/src/lib.rs | Test-only change: insert_signed_block and update_checkpoints calls updated with .expect() to handle new Result return types. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Caller as Caller (blockchain, rpc, main)
participant PubFn as Store public fn (insert_signed_block etc.)
participant Backend as DB Backend (begin_write / commit)
Caller->>PubFn: call (now returns Result)
PubFn->>Backend: begin_write().expect("write batch")
alt Backend error
Backend-->>PubFn: Err — .expect() panics
PubFn--xCaller: (never reached)
else Success
Backend-->>PubFn: Ok(batch)
PubFn->>Backend: batch.commit().expect("commit")
Backend-->>PubFn: Ok(())
PubFn-->>Caller: Ok(())
Caller->>Caller: .expect("...") on Ok — no-op
end
Note over PubFn,Backend: Err variant currently unreachable. Follow-up PRs will replace .expect() with ? to enable true propagation.
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Caller as Caller (blockchain, rpc, main)
participant PubFn as Store public fn (insert_signed_block etc.)
participant Backend as DB Backend (begin_write / commit)
Caller->>PubFn: call (now returns Result)
PubFn->>Backend: begin_write().expect("write batch")
alt Backend error
Backend-->>PubFn: Err — .expect() panics
PubFn--xCaller: (never reached)
else Success
Backend-->>PubFn: Ok(batch)
PubFn->>Backend: batch.commit().expect("commit")
Backend-->>PubFn: Ok(())
PubFn-->>Caller: Ok(())
Caller->>Caller: .expect("...") on Ok — no-op
end
Note over PubFn,Backend: Err variant currently unreachable. Follow-up PRs will replace .expect() with ? to enable true propagation.
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
crates/storage/src/store.rs:1779-1781
Empty `.expect` message — when this panics in a test, the output gives no hint about what failed. All other `.expect` calls in this PR include a descriptive string.
```suggestion
store
.update_checkpoints(ForkCheckpoints::head_only(head_root))
.expect("update_checkpoints should succeed");
```
### Issue 2 of 3
crates/storage/src/store.rs:708-731
**`set_time` / `set_safe_target` left with void return types**
`set_metadata` is updated to `-> Result<(), Error>` in this PR, which means `set_time` and `set_safe_target` now absorb that `Result` with `.expect()` while keeping a `-> ()` signature — yet sibling methods that also call `begin_write` (`insert_signed_block`, `update_checkpoints`, `insert_state`) are updated to return `Result`. This asymmetry in the public `Store` API means callers of `set_time`/`set_safe_target` have no way to observe or propagate storage failures, while callers of the other methods do. If the intent is to update all public write methods uniformly, `set_time` and `set_safe_target` should also be updated to `-> Result<(), Error>` in this PR.
### Issue 3 of 3
bin/ethlambda/src/main.rs:739-742
**Missed error propagation in a function that already returns `Result`**
`fetch_initial_state` already returns `Result<Store, CheckpointSyncError>` and properly propagates the `get_forkchoice_store` error via `map_err`. The new `insert_signed_block` call, however, uses `.expect()` instead of mapping the storage error into `CheckpointSyncError` and returning it. A storage write failure during checkpoint sync will now panic the task rather than surfacing a recoverable `Err` to the caller, which is inconsistent with the surrounding error handling style.
Reviews (1): Last reviewed commit: "feat: make store begin_write callers ret..." | Re-trigger Greptile
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
🗒️ Description / Motivation
This PR updates all
begin_write()callers incrates/storage/src/store.rsto returnResult<T, Error>. Other backend methods (begin_read, etc) callers will be updated and come in follow-up PRs.What Changed
Related Issues / PRs
.expect(), propagate Result through storage layer #306✅ Verification Checklist
make fmt— cleanmake lint(clippy with-D warnings) — cleancargo test --workspace --release— all passing