Skip to content
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

Tracking: Improve reth-trie-db state traits #12216

Open
5 tasks
Rjected opened this issue Oct 30, 2024 · 3 comments
Open
5 tasks

Tracking: Improve reth-trie-db state traits #12216

Rjected opened this issue Oct 30, 2024 · 3 comments
Labels
A-db Related to the database A-sdk Related to reth's use as a library A-trie Related to Merkle Patricia Trie implementation C-enhancement New feature or request C-tracking-issue An issue that collects information about a broad development initiative M-prevent-stale Prevents old inactive issues/PRs from being closed due to inactivity

Comments

@Rjected
Copy link
Member

Rjected commented Oct 30, 2024

Currently we have the following for the DatabaseProof, DatabaseStateRoot, etc. traits:

/// Extends [`Proof`] with operations specific for working with a database transaction.
pub trait DatabaseProof<'a, TX> {
/// Create a new [Proof] from database transaction.
fn from_tx(tx: &'a TX) -> Self;
/// Generates the state proof for target account based on [`TrieInput`].
fn overlay_account_proof(
tx: &'a TX,
input: TrieInput,
address: Address,
slots: &[B256],
) -> Result<AccountProof, StateProofError>;
/// Generates the state [`MultiProof`] for target hashed account and storage keys.
fn overlay_multiproof(
tx: &'a TX,
input: TrieInput,
targets: HashMap<B256, HashSet<B256>>,
) -> Result<MultiProof, StateProofError>;
}

This can likely be rewritten as:

pub trait StatefulProof {
    /// Generates the state proof for target account based on [`TrieInput`].
    fn overlay_account_proof(
        &self,
        input: TrieInput,
        address: Address,
        slots: &[B256],
    ) -> Result<AccountProof, StateProofError>;

    /// Generates the state [`MultiProof`] for target hashed account and storage keys.
    fn overlay_multiproof(
        &self,
        input: TrieInput,
        targets: HashMap<B256, HashSet<B256>>,
    ) -> Result<MultiProof, StateProofError>;
}

Where the caller can have a from_tx method on the struct itself, instead of having one on the trait. The trait implementer is responsible for owning or managing a tx / tx ref.

Tasks

@Rjected Rjected added C-enhancement New feature or request C-tracking-issue An issue that collects information about a broad development initiative A-db Related to the database A-trie Related to Merkle Patricia Trie implementation A-sdk Related to reth's use as a library labels Oct 30, 2024
@frisitano
Copy link
Contributor

One thing to be mindful of here is that the Database* traits may need to be modified / extended as part of our ambitions with #11830 so it would be wise to take that into account when scheduling/planning this work. I think it makes sense to do this refactor after we complete #11830.

@Rjected
Copy link
Member Author

Rjected commented Nov 1, 2024

One thing to be mindful of here is that the Database* traits may need to be modified / extended as part of our ambitions with #11830 so it would be wise to take that into account when scheduling/planning this work. I think it makes sense to do this refactor after we complete #11830.

Yep agreed, just noting this here to make sure we remember to do it after

Copy link
Contributor

This issue is stale because it has been open for 21 days with no activity.

@github-actions github-actions bot added the S-stale This issue/PR is stale and will close with no further activity label Nov 22, 2024
@Rjected Rjected added M-prevent-stale Prevents old inactive issues/PRs from being closed due to inactivity and removed S-stale This issue/PR is stale and will close with no further activity labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-db Related to the database A-sdk Related to reth's use as a library A-trie Related to Merkle Patricia Trie implementation C-enhancement New feature or request C-tracking-issue An issue that collects information about a broad development initiative M-prevent-stale Prevents old inactive issues/PRs from being closed due to inactivity
Projects
Status: Todo
Development

No branches or pull requests

2 participants