-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
/// Create a new [`TrieWitness`] from database transaction. | ||
fn from_tx(tx: &'a TX) -> Self; | ||
fn from_tx(&self) -> Self; |
There was a problem hiding this comment.
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
fn from_tx(&self) -> Self { | ||
Self::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone()) | ||
} |
There was a problem hiding this comment.
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
pub trie_cursor_factory: T, | ||
/// The factory for hashed cursors. | ||
hashed_cursor_factory: H, | ||
pub hashed_cursor_factory: H, |
There was a problem hiding this comment.
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
?
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(), |
There was a problem hiding this comment.
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)
@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 |
Closes Make DatabaseTrieWitness stateful #15481