Skip to content

Trie: memory cache #2263

@Arkenan

Description

@Arkenan

High level goal

The main goal of this is to avoid writing the trie to db every every block, specially for cases like imports.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    merkleizationSection of performance which requires updating the trie to get the new state rootperformance

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions