perf(rpc): avoid IndexedBatch allocation in read-only state views - #3941
perf(rpc): avoid IndexedBatch allocation in read-only state views#3941thiagodeev wants to merge 8 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3941 +/- ##
==========================================
- Coverage 79.28% 79.18% -0.10%
==========================================
Files 464 464
Lines 35793 35811 +18
==========================================
- Hits 28377 28358 -19
- Misses 7407 7444 +37
Partials 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
0d237a9 to
f44b004
Compare
|
Claude finished @thiagodeev's task in 7m 59s —— View job Review:
|
94ed8a6 to
2f09bcc
Compare
|
Claude finished @thiagodeev's task in 6m 42s —— View job Re-review after the
|
|
Claude finished @thiagodeev's task in 6m 21s —— View job Re-review after
|
c28e1d2 to
8bd2d85
Compare
|
I'll analyze this and get back to you. |
8bd2d85 to
c28e1d2
Compare
|
Claude finished @thiagodeev's task in 3m 55s —— View job Re-review check — no new commits since last pass
This Re-checked the files directly rather than trusting the prior summary: Still open — important
Still open — nits (unaddressed, all low-risk to defer)
Resolved in earlier rounds of this PR (no regression on re-check): the Verification: could not get a clean Nothing new to act on beyond the one still-open important item (type-switch ordering) and the four low-risk nits carried over from prior rounds. |
c28e1d2 to
6fc818e
Compare
|
Claude finished @thiagodeev's task in 4m 16s —— View job Re-review — three new commits address prior nits; one important finding remains open
Three new commits landed since my last pass, and they clean up all four previously-open nits:
FindingsBlocker — none. Important
Nit
Verification
Only the type-switch ordering item remains outstanding from prior rounds; everything else previously flagged is now addressed. |
6fc818e to
ad038b1
Compare
|
Claude finished @thiagodeev's task in 3m 50s —— View job Re-review check — no functional changes since the last full pass
Still open — important
Resolved (confirmed unchanged on this pass)
Verification
Only the type-switch ordering item remains outstanding; everything else previously flagged is addressed. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Claude finished @thiagodeev's task in 3m 32s —— View job Re-review check — merge-from-main only, no PR content changes
Still open — important
Resolved (confirmed unchanged on this pass)
Verification
Only the type-switch ordering item remains outstanding after six review passes; it's a cheap, low-risk fix (reorder two case arms in three files) whenever it's convenient to take. |
…hods - Updated storage functions to return a read-only view of the storage trie. - Refactored proof methods to utilize TrieReader instead of Trie for consistency. - Adjusted related tests to accommodate the new changes
- Moved the Prove method back to the Trie struct
- Added Prover interface for generating Merkle proofs. - Updated storage methods to use Prover instead of TrieReader, supporting both Trie and TrieReader. - Adjusted related tests to reflect changes in trie handling.
8d6c3ab to
156f3a3
Compare
|
Claude finished @thiagodeev's task in 1m 17s —— View job Re-review check — rebase only, no PR content changes
This push rewrote history (linear rebase onto current Still open — important
Resolved (confirmed unchanged on this pass)
Verification
Only the type-switch ordering item remains outstanding after seven review passes; it's a cheap, low-risk fix (reorder two case arms in three files) whenever it's convenient to take. |

User description
Read-only state views (
HeadState,StateAtBlockNumber,StateAtBlockHash) indeprecatedStateBackendpreviously allocated a PebbleIndexedBatchper call, paying the batch setup cost and the batch-overlay merge on every subsequentGet- despite never writing. They now read the database directly through areadOnlyTxnadapter that satisfies thedb.IndexedBatchinterfacedeprecatedstate.Newrequires but rejects writes.Also adds
BenchmarkNonce, benchmarkingHandler.Nonceagainst a real Pebble-backed state with 50k contracts under pseudorandom addresses.Making the deprecated trie read path actually read-only
With writes rejected, another change was required:
trie.Trie.Hash()is not read-only (updateValueIfDirtycanPutthrough the txn on the proof-node branch, and a dirty root key is flushed viaPutRootKey), andstarknet_getStorageProofreaches it throughState.ClassTrie()/ContractTrie()/ContractStorageTrie(). Those accessors previously built a full*trie.Trieand wrapped it incore.TrieReaderinterface; with the newreadOnlyTxntype, a stray write would now surface as a user-visibleErrInternalinstead of being silently discarded with the throwaway batch.They now return an actual
*trie.TrieReaderstruct type, which needs only adb.KeyValueReaderand has no write capability at all:Provemoved toTrieReader(it only reads);Triekeeps a thinProvewrapper that preserves the "cannot prove a trie with unhashed writes" guard.trie.Provercapability interface instead of the concrete*trie.Trietype, so both*trie.Trie(guarded) and*trie.TrieReaderare accepted and future producers can't silently fall through to "unknown trie type".*trie2.Triecannot match it (differentProofNodeSettype) and keeps its own branch.TrieReader.Hash()nil-pointer panic on empty tries (nil root key): it now returnsfelt.ZerolikeTrie.Hash(). Reachable viaStateAtBlockHash(&felt.Zero)and storage proofs for non-deployed contracts. Also returns the root node tonodePoolafter hashing.Numbers
BenchmarkNonce, benchstat over 6 runs each (-benchtime=2s):Every read-only RPC that goes through these state views benefits, not just
starknet_getNonce.PR Type
Enhancement, Tests
Description
Avoid
IndexedBatchallocation in read-only state views via newreadOnlyTxnMake deprecated trie read paths truly read-only using
*trie.TrieReaderIntroduce
trie.Proverinterface for proof generation across RPC v8/v9/v10Add
BenchmarkNonceand unit tests for read-only state backendFile Walkthrough
7 files
Introduce readOnlyTxn adapter to avoid IndexedBatch allocationChange deployed and ContractStorage to accept KeyValueReaderUse TrieReader for ClassTrie, ContractTrie, and ContractStorageTrieAdd Prover interface and move Prove logic to TrieReaderDispatch proof generation on trie.Prover interfaceDispatch proof generation on trie.Prover interfaceDispatch proof generation on trie.Prover interface2 files
Add tests for readOnlyTxn and read-only state backend viewsAdd BenchmarkNonce with synthetic Pebble-backed state1 files
Guard TrieReader.Hash against nil root key and reuse node pool