Skip to content

fix: Make DatabaseTrieWitness stateful #15833

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cy00r
Copy link

@cy00r cy00r commented Apr 20, 2025

  • Refactored DatabaseTrieWitness trait to be stateful, removing the associated TX type and lifetime parameters.
  • Simplified methods to use &self instead of taking &'a TX for every method
    Closes Make DatabaseTrieWitness stateful #15481

@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Apr 20, 2025
@cy00r cy00r closed this Apr 20, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Done in Reth Tracker Apr 20, 2025
@cy00r cy00r reopened this Apr 20, 2025
@github-project-automation github-project-automation bot moved this from Done to In Progress in Reth Tracker Apr 20, 2025
Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

hey! I have some comments on how we should change the trait that should simplify things. Let me know if you have questions or run into problems @cy00r

Comment on lines 12 to +13
/// Create a new [`TrieWitness`] from database transaction.
fn from_tx(tx: &'a TX) -> Self;
fn from_tx(&self) -> Self;
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't want this method on the trait any more

Comment on lines +26 to 28
fn from_tx(&self) -> Self {
Self::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone())
}
Copy link
Member

Choose a reason for hiding this comment

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

we should move this to be a method directly on TrieWitness, and we still want the argument to be &'a TX

Comment on lines +30 to +32
pub trie_cursor_factory: T,
/// The factory for hashed cursors.
hashed_cursor_factory: H,
pub hashed_cursor_factory: H,
Copy link
Member

Choose a reason for hiding this comment

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

Do these need to be pub?

Comment on lines 30 to +43
fn overlay_witness(
tx: &'a TX,
&self,
input: TrieInput,
target: HashedPostState,
) -> Result<B256Map<Bytes>, TrieWitnessError> {
let nodes_sorted = input.nodes.into_sorted();
let state_sorted = input.state.into_sorted();
Self::from_tx(tx)
Self::from_tx(&self)
.with_trie_cursor_factory(InMemoryTrieCursorFactory::new(
DatabaseTrieCursorFactory::new(tx),
self.trie_cursor_factory.clone(),
&nodes_sorted,
))
.with_hashed_cursor_factory(HashedPostStateCursorFactory::new(
DatabaseHashedCursorFactory::new(tx),
self.hashed_cursor_factory.clone(),
Copy link
Member

Choose a reason for hiding this comment

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

I think this actually motivates changing the &self, to be self in the trait, that way we could do something like:

self.
// with_trie_cursor_factory call
// with_hashed_cursor_factory call
// ...
.compute(target)

@jenpaff
Copy link
Collaborator

jenpaff commented May 8, 2025

@cy00r are you still working on the PR / will you be able to work on the feedback? let us know if you want to hand it over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Make DatabaseTrieWitness stateful
3 participants