Skip to content

Conversation

@BrianBland
Copy link
Collaborator

Improve usability of TrieDB as a crate by making the following external-facing changes:

  • Remove lifetimes from Transactions, by instead holding an Arc of a database handle
  • Allow error types to be clonable

This re-introduces DatabaseInner, with Database simply holding an Arc of the inner struct.

Replaces #108

@BrianBland BrianBland requested a review from and-cb July 1, 2025 20:45
@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Jul 1, 2025

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@BrianBland BrianBland requested a review from jjtny1 July 1, 2025 21:36

#[derive(Debug)]
#[derive(Clone, Debug)]
pub enum Error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's very rare for errors to implement Clone, which is why most errors (in the std lib too) don't implement it. Is there a specific reason why we want them here? The PR description mentions "usability reasons", but I struggle to find places where errors are cloned instead of being simply propagated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was introduced for seamless compatibility with Reth, as they appear to clone errors. I'll double check whether or not this is truly necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Upon further review this mostly stems from Reth cloning Results (example) including the ProviderError

We don't really need to embed the raw TrieDB Error inside of the ProviderError, and can instead just stringify this to remove the need for error cloning.

}
}

impl Database {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of rewriting all the code to use self.inner. instead of self., I would suggest simply changing impl Database to impl DatabaseInner. The only methods that need to stay inside impl Database are the constructors (create and new). Everything else can be transparently delegated by Deref

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe this would require making DatabaseInner public, which we probably want to avoid

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another option might be to make Transaction accept a generic DB which implements Deref<Database>, so that we can use &Database or Arc<Database> as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants