refactor(store): pull storage map entries from account state forest#2012
Merged
refactor(store): pull storage map entries from account state forest#2012
Conversation
Use the account state forest to pull storage map entries instead of the database. The issue with storage state in account state forest is that storage keys are _hashed_ before being stored in the forest, so querying _all_ entries for a storage map requires an ability to reverse the hash. This is not generally possible, but we can maintain an LRU cache of `hashed_key` -> `key` mappings. If _all_ hashed keys for a storage map are present in the cache we don't need to query the database at all and can just use the cache to reverse the hashes. If some hashes are missing from the cache, we fall back to querying the database and then make sure to update the LRU cache with the missing mappings.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors GetAccount storage-map loading to prefer AccountStateForest (when raw keys can be reconstructed from a reverse-key cache) and expands the stress-test tool to seed/benchmark realistic account detail queries.
Changes:
- Add an LRU reverse-key cache (
hashed_key -> raw_key) to enable enumerating storage map entries from the forest without hitting SQLite when possible. - Update
GetAccountall-entries storage map requests to use the forest when the cache is complete, otherwise fall back to DB reconstruction and backfill the cache. - Extend
miden-node-stress-testwith configurable seeding (vault assets + storage map entries + update blocks) and a newget-accountbenchmark.
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/store/src/state/mod.rs | Adds forest-first + DB-fallback path for AllEntries storage map details; backfills reverse-key cache after DB reconstruction. |
| crates/store/src/account_state_forest/mod.rs | Introduces LRU cache and new API to fetch all storage map entries from forest when keys can be reversed. |
| crates/store/src/account_state_forest/tests.rs | Adds a unit test asserting all-entries returns raw keys after an update. |
| crates/store/Cargo.toml | Adds lru dependency. |
| bin/stress-test/src/store/mod.rs | Adds get-account benchmark implementation and request builder. |
| bin/stress-test/src/seeding/mod.rs | Adds configurable seeding for vault/storage-map sizing and optional post-init update blocks. |
| bin/stress-test/src/seeding/tests.rs | Adds tests for new seeding behaviors (storage map sizing, vault assets, update logic). |
| bin/stress-test/src/main.rs | Wires new seed/benchmark CLI options and new get-account endpoint. |
| bin/stress-test/README.md | Documents new seeding knobs and the get-account benchmark usage/results. |
| Cargo.lock | Records lru dependency resolution. |
| CHANGELOG.md | Notes the GetAccount optimization for all-entries requests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Mirko-von-Leipzig
approved these changes
Apr 28, 2026
…RN_ENTRIES consistently
The `.get()` operation of the cache requires a mutable reference to update the internal LRU state. We avoided that using `.peek()`, but that meant we don't keep track of usage and the cache was not effective.
…-account-storage-maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As outlined in #1978 in some cases we can use the account state forest to pull storage map entries instead of the database.
The issue with storage state in account state forest is that storage keys are hashed before being stored in the forest, so querying all entries for a storage map requires an ability to reverse the hash.
This is not generally possible, but we can maintain an LRU cache of
hashed_key->keymappings. If all hashed keys for a storage map are present in the cache we don't need to query the database at all and can just use the cache to reverse the hashes.If some hashes are missing from the cache, we fall back to querying the database and then make sure to update the LRU cache with the missing mappings.
This PR also adds some improvements to the
stress-testtool:seed-storecan now generate a configurable number of vault assets and storage map entries for the accounts it is creating.seed-storenow optionally generates blocks with transactions that update the storage map entries for the accounts it has previously generated.get-accountbenchmark that is querying account state, including vault assets and generated storage map values.Using the new
get-accountbenchmark we get the following results (on a DB with ~50k public accounts, each with 2 vault assets and 64 storage map entries).Before:
After:
Note that there's also a change on how many storage map entries we're returning for
all_entriesslots. Previously, the code was usingQueryParamStorageMapKeyTotalLimitas the limit, but that limit is supposed to be the maximum number of individual keys for any map in the request. The current value for that limit is 64, which makes sense for the case where we're returning proofs butall_entriesquery responses are just a list of (key, value) pairs. This PR changes the limit the maximum number of entries returned toAccountStorageMapDetails::MAX_RETURN_ENTRIES(1000 currently) so that the limit is consistent across the code base.