Skip to content

feat: create world state trie from engine DB#399

Merged
fmoletta merged 25 commits into
mainfrom
create_world_state_trie
Sep 16, 2024
Merged

feat: create world state trie from engine DB#399
fmoletta merged 25 commits into
mainfrom
create_world_state_trie

Conversation

@fmoletta

@fmoletta fmoletta commented Sep 13, 2024

Copy link
Copy Markdown
Contributor

Motivation

Being able to create a Trie struct representing the world state based on the engine's internal value store (reading from a specific table in the case of libmdbx or map in the case of in_memory). The created trie would also use the given block's state root as its root in order to query historical data build new blocks based on the previous block's state, and easily process re-orgs

Description
Added features:

  • Add world_state method to StoreEngine api, which builds a Trie from a block number and the engine's internal database (or value store)

Code refactors:

  • Remove DB generic from Trie and instead store Box<dyn TrieDB> (This is because the generic wouldn't allow us to return a single generic Trie<DB> from different StoreEngine implementations)
  • Store Arc<Database> instead of &'a Database in libmdbx impl of TrieDB (This is so we can box it)
  • Store Arc<Database> instead of Database in engine::libmdbx::Store (Complies with above change)

Misc:

  • Add Trie::new_temp test-feature gated method to simplify trie creation in tests

Closes None, but is needed for #391

@fmoletta fmoletta changed the base branch from main to world-state-trie-db September 13, 2024 21:03
@fmoletta fmoletta changed the base branch from world-state-trie-db to libdbmx-trie-db-tables September 13, 2024 21:04
@fmoletta fmoletta changed the title [WIP] Create world state trie from engine DB feat: create world state trie from engine DB Sep 16, 2024
Base automatically changed from libdbmx-trie-db-tables to main September 16, 2024 17:25
@fmoletta fmoletta marked this pull request as ready for review September 16, 2024 17:35
@fmoletta fmoletta requested a review from a team as a code owner September 16, 2024 17:35
Comment thread crates/storage/engines/libmdbx.rs Outdated
}
}

fn world_state(&self, block_number: BlockNumber) -> Result<Option<Trie>, StoreError> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would rename to state_trie. I haven't seen references to "world" in other client implementations, just state

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is referred to as World State in the yellow paper, but I agree, we can just name it state trie

@mpaulucci mpaulucci left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 after rename

@fmoletta fmoletta enabled auto-merge September 16, 2024 19:24
@fmoletta fmoletta added this pull request to the merge queue Sep 16, 2024
Merged via the queue into main with commit 9c46a07 Sep 16, 2024
@fmoletta fmoletta deleted the create_world_state_trie branch September 16, 2024 19:31
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.

3 participants