-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,39 +8,39 @@ use reth_trie::{ | |
}; | ||
|
||
/// Extends [`TrieWitness`] with operations specific for working with a database transaction. | ||
pub trait DatabaseTrieWitness<'a, TX> { | ||
pub trait DatabaseTrieWitness { | ||
/// Create a new [`TrieWitness`] from database transaction. | ||
fn from_tx(tx: &'a TX) -> Self; | ||
fn from_tx(&self) -> Self; | ||
|
||
/// Generates trie witness for target state based on [`TrieInput`]. | ||
fn overlay_witness( | ||
tx: &'a TX, | ||
&self, | ||
input: TrieInput, | ||
target: HashedPostState, | ||
) -> Result<B256Map<Bytes>, TrieWitnessError>; | ||
} | ||
|
||
impl<'a, TX: DbTx> DatabaseTrieWitness<'a, TX> | ||
impl<'a, TX: DbTx> DatabaseTrieWitness | ||
for TrieWitness<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>> | ||
{ | ||
fn from_tx(tx: &'a TX) -> Self { | ||
Self::new(DatabaseTrieCursorFactory::new(tx), DatabaseHashedCursorFactory::new(tx)) | ||
fn from_tx(&self) -> Self { | ||
Self::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone()) | ||
} | ||
Comment on lines
+26
to
28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should move this to be a method directly on |
||
|
||
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(), | ||
Comment on lines
30
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this actually motivates changing the
|
||
&state_sorted, | ||
)) | ||
.with_prefix_sets_mut(input.prefix_sets) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,9 @@ use std::sync::{mpsc, Arc}; | |
#[derive(Debug)] | ||
pub struct TrieWitness<T, H> { | ||
/// The cursor factory for traversing trie nodes. | ||
trie_cursor_factory: T, | ||
pub trie_cursor_factory: T, | ||
/// The factory for hashed cursors. | ||
hashed_cursor_factory: H, | ||
pub hashed_cursor_factory: H, | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these need to be |
||
/// A set of prefix sets that have changes. | ||
prefix_sets: TriePrefixSetsMut, | ||
/// Recorded witness. | ||
|
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