perf(state): avoid full header decode in deprecated state backend#3789
Conversation
fa5458a to
c31cef8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3789 +/- ##
==========================================
- Coverage 75.34% 75.24% -0.10%
==========================================
Files 438 438
Lines 39528 39569 +41
==========================================
- Hits 29781 29773 -8
- Misses 7676 7707 +31
- Partials 2071 2089 +18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Claude finished @ongyimeng's task in 2m 32s —— View job PR Review: perf(state): avoid full header decode in deprecated state backend
I traced the retention semantics end-to-end to confirm the behavior change is safe. The optimization is correct — no blockers. Correctness verificationThe key question is whether dropping the full header decode weakens the state-retention guard. It doesn't:
FindingsBlocker: none. Important: none. Nit (posted inline):
Optional follow-up (out of scope): the non-deprecated |

Extends the partial-header-decode optimization from #3782 to the
production-default
deprecatedStateBackend, avoiding full header decodes(including
EventsBloom) when only one field or an existence check is needed.HeadState: dropped the discardedGetBlockHeaderByNumberfetch;GetChainHeightis now only used as the head-exists guard.StateAtBlockNumber: gated onRequireStateRetainedByBlockNumber,which reads only the block hash + hash→number index.
StateAtBlockHash: resolves the block number via the hash→numberindex without decoding the header.
Why
These paths back latest/head and historical-block state RPCs (
getNonce,getStorageAt,getClass*,call,estimateFee, tracing, etc.). The fullheader decode was pure overhead on the hot read path.
Behavior note
HeadStateandStateAtBlockHashno longer perform a full header decodeas an incidental DB-corruption/header-existence guard. The
GetChainHeightcheck and the hash→number index lookup remain as guards, which is correct
for a consistent DB.
Benchmark
Note: I could not use the recent mainnet data sampled earlier because these state-read benchmarks require contiguous chain data with matching parent hashes. The available fixture-sync path only provides a contiguous mainnet chain through block 2, so this uses shallow fixture data instead.
All
B/opdeltas havep=0.002.Tests