refactor(blockchain): use Store::head_state in update_safe_target - #571
Conversation
The accessor already exists and does exactly this get_state(&head()) chain, so the open-coded version was carrying a redundant unwrap for no reason.
Greptile SummaryThis PR simplifies safe-target calculation by using the existing
Confidence Score: 5/5The PR appears safe to merge because the refactor preserves the existing head-state lookup and validator-threshold calculation. The changed expression delegates the same head-state retrieval to the existing accessor without altering safe-target inputs, control flow, or state mutation.
|
| Filename | Overview |
|---|---|
| crates/blockchain/src/store.rs | Refactors update_safe_target to retrieve the current head state through the equivalent storage accessor; no behavioral issue identified. |
Reviews (1): Last reviewed commit: "refactor(blockchain): use Store::head_st..." | Re-trigger Greptile
🤖 Kimi Code ReviewReview of PR #571 crates/blockchain/src/store.rs This is a straightforward refactoring that improves readability by replacing manual head state lookup with a helper method. No consensus logic changes. Observations:
Verdict: LGTM. The change reduces unwrap nesting and improves maintainability. No security issues introduced. Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Codex Code ReviewNo findings.
The only observable effect is readability: the helper centralizes the invariant that the head state must exist. Performance is unchanged in practice because both paths still clone/load the full Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
🤖 Claude Code ReviewThis is a clean, minimal, low-risk refactor. No functional changes, no correctness concerns. ReviewSummary: This PR replaces a 4-line open-coded Correctness: Verified. Style/idioms: Matches the codebase's stated preference for reusing existing accessors over re-deriving them, and removes a redundant Scope: Tight and well-justified — this is the only site in the codebase that had open-coded this chain, so there's no remaining duplication to clean up elsewhere. No issues found. This is a good, safe cleanup — approve as-is. Automated review by Claude (Anthropic) · sonnet · custom prompt |
🗒️ Description / Motivation
Extracted from #561. Independent of the heartbeat work, so it lands on its own.
update_safe_targetopen-coded theget_state(&head())chain thatStore::head_state()already encapsulates, carrying an extraunwrapfor no reason.What Changed
crates/blockchain/src/store.rs—update_safe_targetreads the validator count throughstore.head_state().Correctness / Behavior Guarantees
Equivalent, checked rather than assumed:
Store::head_state()(crates/storage/src/store.rs:1696) is exactlyself.get_state(&self.head().expect(..)).expect(..).unwrap()— the same Result→panic, Result→panic, Option→panic chain the inline version had. Only theexpectmessages differ.This is the only site in the codebase that open-coded the chain.
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