Skip to content

refactor: Made DatabaseStorageProof stateful #15829

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 4 commits into
base: main
Choose a base branch
from

Conversation

18aaddy
Copy link
Contributor

@18aaddy 18aaddy commented Apr 20, 2025

Resolves #15477

@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Apr 20, 2025
@18aaddy 18aaddy marked this pull request as draft April 20, 2025 10:41
@18aaddy 18aaddy marked this pull request as ready for review April 20, 2025 20:51
@18aaddy
Copy link
Contributor Author

18aaddy commented Apr 21, 2025

@Rjected @mattsse Can you review pls?

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.

I have some suggestions that should simplify how we use these methods, lmk if you have any questions or are stuck with anything

Comment on lines +191 to +193
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 131 to 138
&StorageProof::new(
DatabaseTrieCursorFactory::new(self.tx()),
DatabaseHashedCursorFactory::new(self.tx()),
address,
),
address,
slots,
hashed_storage,
Copy link
Member

Choose a reason for hiding this comment

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

imo we should implement a method on StorageProof that is identical to the previous from_tx implementation, then we should be able to do something like:

StorageProof::from_tx(self.tx()).overlay_storage_multiproof(address, slots, hashed_storage)

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Apr 22, 2025
@18aaddy 18aaddy force-pushed the refactor/make-database-storage-proof-stateful branch from 29073f2 to 97518b3 Compare April 23, 2025 21:23
@18aaddy
Copy link
Contributor Author

18aaddy commented Apr 23, 2025

@Rjected , I have updated my code with the requested changes. Here is an explainer:

  • I have added a new trait StorageProofFromTx with a function from_tx() that gives a StorageProof instance.

  • The reason for defining a new trait is that StorageProof is used in the trie/db/src/proof.rs file and the DatabaseTrieCursorFactory and DatabaseHashedCursorFactory structs required for implementing from_tx() are also present in trie/db/src. If I were to implement the from_tx() function for StorageProof, it would cause a circular import.

  • The trie_cursor_factory and hashed_cursor_factory fields are still public. The reason behind this is that in the with_hashed_cursor_factory() function below, the StorageProof instance is consumed, therefore we need to make a new instance. The StorageProof struct doesn't implement the Copy trait, and therefore a simple .clone() doesn't work.

Self::new(self.trie_cursor_factory.clone(), self.hashed_cursor_factory.clone(), address)
.with_hashed_cursor_factory(HashedPostStateCursorFactory::new(
self.hashed_cursor_factory.clone(),
&state_sorted,
))
.with_prefix_set_mut(prefix_set)
.storage_proof(slot)

This is the best solution I was able to find, if there was something more obvious possible, my apologies. Would love some feedback.

@18aaddy
Copy link
Contributor Author

18aaddy commented Apr 25, 2025

@Rjected @mattsse Can you pls review?

@jenpaff
Copy link
Collaborator

jenpaff commented May 8, 2025

@Rjected could you ptal?

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 DatabaseStorageProof stateful
3 participants