perf(l1): serve account and storage reads from flat maps - #7276
diegokingston wants to merge 1 commit into
Conversation
|
🤖 Kimi Code ReviewI'll review this PR which adds flat read maps ( Overall AssessmentThe PR introduces a performance optimization: flat hash maps for O(1) account and storage reads instead of walking Merkle tries. The core challenge is maintaining consistency between the flat maps and the tries during state updates, while preserving the security property that missing witness data errors rather than returning default values. Issues Found1. Critical: Double trie lookup in
|
| Priority | Issue | Location |
|---|---|---|
| Critical | Double get_valid_storage_trie call |
get_storage_slot, lines 798, 817 |
| High | Flat maps not populated on trie fallback; inconsistent decode paths | get_account_state, get_storage_slot |
| High | Account removal doesn't clear storage_flat |
apply_account_updates, line 604 |
| Medium | H256::from_slice panic risk on hashed_key |
lines 650, 657, 799 |
| Medium | (H256, H256) key efficiency |
storage_flat type |
| Low | Typo in error message; message inconsistency | lines 755, 758, 808, 820 |
| Low | 4-tuple return type complexity | build_tries_from_records |
The core logic is sound but the double-verification and missing cleanup on account removal are genuine bugs that should be fixed before merge.
Automated review by Kimi (Moonshot AI) · kimi-k2.6 · custom prompt
🤖 Codex Code ReviewFindings
I did not see a new EVM-consensus or gas-accounting bug in the read-path logic itself; the main concerns are cache invalidation and the new witness-memory/performance cost.
Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
Lines of code reportTotal lines added: Detailed view |
🤖 Claude Code ReviewReview: PR 7276 — Serve account/storage reads from flat mapsOverall this is a solid, well-reasoned optimization. The critical "proven-absent vs witness-incomplete" invariant (EIP-8025 Findings1. self.storage_flat
.retain(|(addr, _), _| *addr != hashed_address);
2. 3. Pre-existing 4. Doc-comment glitch (
Reads as a leftover edit fragment ("the trie knows [that it's proven-absent or not]"?). Minor, but worth tightening since this comment guards a consensus-critical invariant and should be unambiguous. 5. Memory footprint doubling for leaf data (design-level, not a bug) Minor nits
No issues found with RLP encoding/decoding correctness, gas accounting (not touched), or the account-removal/removed_storage bookkeeping logic itself — the flat-map updates are correctly ordered relative to the trie updates they mirror. Automated review by Claude (Anthropic) · sonnet · custom prompt |
…e (−1.51M cycles)
f7cf56f to
9e03367
Compare
a267691 to
907cbaa
Compare
Benchmark Block Execution Results Comparison Against Main
|
Stacked on #7275 (nibble-stack decode) — review only the last commit.
GuestProgramStatenow builds, during the same anchored DFS decode, flat read maps —accounts_flat: FxHashMap<H256, Vec<u8>>andstorage_flat: FxHashMap<(H256, H256), Vec<u8>>—and serves
get_account_state/get_storage_slotfrom them instead of descending thetrie level by level.
apply_account_updateswrites through to both (trie for roots,maps for reads).
The "proven absent" vs "witness incomplete" distinction is preserved: on a map miss we
fall back to the trie, which errors on accounts/slots the witness does not cover
(EIP-8025
witness_validation_statetests).Measurement
Guest cycles for mainnet block 25368371 (LambdaVM interpreter, same host):
main(89e1602)BranchNode::getdrops from 966k to 416k in the profile. Keccak/ECSM call countsunchanged; the real-block test (native + VM) passes.