Skip to content

Conversation

@drahnr
Copy link
Contributor

@drahnr drahnr commented Nov 28, 2025

Part 2/4 of #1185 and lays the ground for #1354

⚠️ The PR is rather large, a lot of the changes affect large pieces of code across.

Intent

  • Provide the baseline for cheap querying partial storage maps, but not implement it
  • Prepare for potential deprecation of AccountInfo

core changes

  1. Remove the vault / storage_map BLOB entries from the accounts table.
  2. Add SmtForest and integrate into apply_block and State::load

significant changes in the following files:

  • crates/store/src/db/schema.rs introduces account_storage_headers and removes storage (the full serialized account storage) from accounts table
  • crates/store/src/state.rs / fn State::apply_block now updates the database, but also the lookup table of roots for the SmtForest and the entries in the forest itself, indirect lookup tables

out of scope

how to review

Take the existing TODOs into consideration, if they make sense. This will be the follow up PR.

@drahnr drahnr force-pushed the bernhard-integrate-smtforest branch 2 times, most recently from 7980bed to 771f6d7 Compare December 2, 2025 11:16
@drahnr drahnr force-pushed the bernhard-integrate-smtforest branch from 771f6d7 to b2aa54b Compare December 2, 2025 15:22
@drahnr drahnr force-pushed the bernhard-integrate-smtforest branch from b2aa54b to 2964a93 Compare December 2, 2025 15:54
Copy link
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly questions; no real issues found as yet

@drahnr drahnr changed the title [feat] integrate smtforest, avoid ser/de of full account/vault data in database feat: [1/4] integrate smtforest, avoid ser/de of full account/vault data in database Dec 23, 2025
@drahnr drahnr changed the title feat: [1/4] integrate smtforest, avoid ser/de of full account/vault data in database feat: [1/3] integrate smtforest, avoid ser/de of full account/vault data in database Dec 23, 2025
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I left some comments inline and pushed a few commits to try to organize the code a bit better. Overall, we are still quite far from being able to merge this PR as there are some bugs and logical inconsistencies.

Also, given the amount of remaining issues, I'm a bit concerned about our ability to wrap this PR up in a timely manner. Given the complexity of this PR, deep reviews take quite a bit of time. Maybe there is a way to split this up into smaller incremental PRs that we can review and merge much more quickly.

Comment on lines 1325 to 1330
let public_account_ids: Vec<AccountId> = db
.select_all_account_commitments()
.await?
.iter()
.filter_map(|(id, _commitment)| if id.has_public_state() { Some(*id) } else { None })
.collect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty inefficient because we just need to get a list of accounts with public state, but instead we are loading all account commitments. This is OK for now because we'll replace the initialization code as we migrate to RocksDB-based backends.

Copy link
Contributor Author

@drahnr drahnr Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could filter as part of the query using lt/gt given a certain prefix range if the layout is advantageous, LIKE statements are not supported by diesel after taking a brief look.
EDIT: looking at the layout of the exact bits in AccountId and the prefix, it seems the pub/priv/network types are encoding it at the lower octet of the prefix, range filtering won't work.

Comment on lines +130 to +136
/// Read-write lock used to prevent writing to a structure while it is being used.
///
/// The lock is writer-preferring, meaning the writer won't be starved.
inner: RwLock<InnerState>,

/// Forest-related state `(SmtForest, storage_roots, vault_roots)` with its own lock.
forest: RwLock<InnerForest>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing a good reason to separate InnerForest from InnerState - so, let's combine them. This could look simply as:

struct InnerState<S = MemoryStorage>
where
    S: SmtStorage,
{
    blockchain: Blockchain,
    account_tree: AccountTreeWithHistory<S>,
    nullifier_tree: NullifierTree<LargeSmt<S>>,
    forest: InnerForest,
}

In the future (when moving to a RocksDB backend), we should refactor this to move InnerState into a separate file and clean up the module hierarchy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes care of encapsulating the indices required for lookup and hiding the internals, which will come in handy once LargeSmtForest lands, which has a largely different API.

That's not withstanding a separate module cleanup/InnerState move.

@drahnr drahnr changed the base branch from next to bernhard-db-schema-queries December 29, 2025 23:53
@drahnr drahnr changed the title feat: [1/3] integrate smtforest, avoid ser/de of full account/vault data in database feat: [2/4] integrate smtforest, avoid ser/de of full account/vault data in database Dec 29, 2025
@drahnr drahnr force-pushed the bernhard-integrate-smtforest branch from 3bd5451 to c5a199a Compare December 30, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants