refactor(l1): reuse get_account_state in Store account getters - #7188
refactor(l1): reuse get_account_state in Store account getters#7188ilitteri wants to merge 1 commit into
Conversation
get_code_by_account_address and get_nonce_by_account_address inlined the full account-lookup sequence (canonical hash -> state trie -> hash_address_fixed -> trie.get -> AccountState::decode) that get_account_state already implements, and get_account_info_by_hash inlined the get+decode half that get_account_state_from_trie provides. Delegate the three bodies to those helpers so the tri-state Ok(None) logic is spelled once. Signatures are unchanged (get_account_info_by_hash stays sync) and get_code still routes through get_account_code to keep the code-cache fast path and its Option return.
|
Lines of code reportTotal lines added: Detailed view |
🤖 Kimi Code ReviewThis is a clean refactoring PR that eliminates code duplication in account state retrieval. The changes are functionally equivalent and improve maintainability. crates/storage/store.rs The refactoring correctly extracts common patterns:
Verdict: Approved. The changes reduce duplication while preserving error handling semantics ( No security or consensus issues introduced—this is purely a code structure improvement. Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Claude Code ReviewThis confirms the refactor is a straightforward, behavior-preserving dedup. The delegation matches the original logic exactly (same tri-state ReviewCorrectness: Verified against the current definitions of
No signature changes, no schema/RLP changes, no new error paths introduced. The tri-state Performance: No material change — same number of trie lookups/decodes per call. Security/consensus: Not applicable; this is a pure internal dedup of read-path lookups, no consensus-affecting logic touched. Style: Idiomatic use of No issues found — this is a clean, low-risk refactor that does exactly what it claims. Automated review by Claude (Anthropic) · sonnet · custom prompt |
🤖 Codex Code ReviewNo findings. The changes in crates/storage/store.rs and crates/storage/store.rs appear behavior-preserving: they reuse the existing Residual risk is limited to coverage: the PR does not add tests around these refactored accessors, and I could not run Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
Motivation
Store::get_code_by_account_addressandStore::get_nonce_by_account_addresseach inlined the full account-lookup sequence (canonical block hash → state trie →hash_address_fixed→trie.get→AccountState::decode) that the publicStore::get_account_statealready implements, andStore::get_account_info_by_hashinlined the get+decode half thatget_account_state_from_trieprovides.Three hand-rolled copies of the same walk are a liability: any future change to account lookup (key derivation, decode handling, the missing-trie tri-state) has to be replicated in four places, and a copy that drifts silently diverges in behavior. Deduplicating to the canonical helpers removes 19 net lines of code and leaves the tri-state logic spelled exactly once.
Description
Only the three function bodies in
crates/storage/store.rschange; every signature (async-ness included) is byte-identical, so no caller changes.get_nonce_by_account_addressnow delegates toget_account_state(block_number, address)and maps the nonce out.get_code_by_account_addressnow delegates toget_account_state(block_number, address)and, when the account exists, still resolves the code throughget_account_code(code_hash)— preserving theaccount_code_cachefast path and the account-exists-but-code-missing ⇒Ok(None)(not error) semantics.get_account_info_by_hashstays sync: it keeps its ownstate_trie(block_hash)?call and delegates only to the syncget_account_state_from_trie, mapping theAccountStateintoAccountInfo(its sync callerget_account_infois untouched).Invariants preserved and how: the tri-state
Ok(None)semantics (missing canonical hash, missing state trie, absent account) come from the same let-else guards now living solely inget_account_state/get_account_state_from_trie, while trie/DB/decode errors still propagate via?asStoreError; key derivation remainshash_address_fixedbecause that is whatget_account_state_from_triealready uses;get_account_state_by_acc_hash(pre-hashed key, a different helper) is deliberately untouched.If this change were wrong, one of these would have to be true:
get_account_state's lookup sequence differs from the inlined copies (it is verbatim the same five steps), some caller depended on a signature or sync-ness change (workspace clippy compiles all callers unchanged), missing code for an existing account now errors (theget_account_codecall is preserved verbatim), or aNonecase now errors (all threeNonesources still short-circuit toOk(None)).How to test
cargo fmt— clean (diff is +15/−36 in one file).cargo clippy -p ethrex-storage --all-targets -- -D warnings— clean.cargo clippy --workspace --all-targets -- -D warnings— clean, proving all RPC/l2 callers compile against the unchanged signatures.cargo test -p ethrex-storage— 91 passed, 0 failed (plus doctests).Checklist
Storeschema, on-disk format, or RLP change — pure in-memory dedup of function bodies — soSTORE_SCHEMA_VERSION(crates/storage/lib.rs) is untouched.