Skip to content

Trie: memory cache #2263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tracked by #2259
Arkenan opened this issue Mar 19, 2025 · 0 comments
Open
Tracked by #2259

Trie: memory cache #2263

Arkenan opened this issue Mar 19, 2025 · 0 comments
Assignees

Comments

@Arkenan
Copy link
Collaborator

Arkenan commented Mar 19, 2025

High level goal

The main goal of this is to avoid writing the trie to db every time we update it. This can be used both to commit to db only at the end of a block, or even at the end of multiple blocks if we're syncing/importing.

Ideally, be it for hashing or just regular updating, we want to use everything in-memory. That is, modify in memory, hash in memory, create nodes in memory, etc. Deletions might be a bit trickier, but they shouldn't really happen for now. We also need a way to apply the changes from the cache to the db.

Low level goal

The technical explanation of the problem lies is the commit function. It does three things:

  • Calculates all hashes.
  • Moves everything to disk.
  • empties the cache

This mans that the cache nowadays is actually a buffer, only used before flushing to disk. We know what's new and what's not by checking the cache.

This coupling prevents us from maintaining the cache between blocks, forces us to write to the db and other problems.

What we need to do

  • Ideally, we need a TrieState.get_root function that only returns the hash and calculates whatever is missing. It shouldn't delete everything from the cache, nor move anything to db.
  • We need the cache to have it's own policy and size. For now, let's use FIFO policy and size big enough to fit 100000 nodes. We can do a better policy or configure it better later.
  • The cache will take care of writing to the db automatically without any request from the outside. It will write every node that is removed from the cache.
@Arkenan Arkenan mentioned this issue Mar 19, 2025
11 tasks
@Arkenan Arkenan moved this to Todo in ethrex_l1 Apr 4, 2025
@Arkenan Arkenan changed the title Trie: memory cache to decouple root calculation from storage writes Trie: memory cache Apr 4, 2025
@Arkenan Arkenan moved this from Todo to In Progress in ethrex_l1 Apr 11, 2025
@mpaulucci mpaulucci removed this from ethrex_l1 Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants