-
Notifications
You must be signed in to change notification settings - Fork 93
feat: Clean up StateDB methods, bump revm #238
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
0xForerunner
wants to merge
3
commits into
alloy-rs:main
Choose a base branch
from
0xForerunner:state-db-methods
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+48
−4
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,53 @@ | ||
| //! State database abstraction. | ||
|
|
||
| use core::fmt::Debug; | ||
| use revm::{ | ||
| database::{states::bundle_state::BundleRetention, BundleState, State}, | ||
| DatabaseCommit, | ||
| }; | ||
|
|
||
| use crate::Database; | ||
| use revm::DatabaseCommit; | ||
|
|
||
| /// Alias trait for [`Database`] and [`DatabaseCommit`]. | ||
| pub trait StateDB: Database + DatabaseCommit {} | ||
| /// A type which has the state of the blockchain. | ||
| /// | ||
| /// This trait encapsulates some of the functionality found in [`State`] | ||
| #[auto_impl::auto_impl(&mut, Box)] | ||
| pub trait StateDB: Database + DatabaseCommit { | ||
| /// Gets a reference to the internal [`BundleState`] | ||
| fn bundle_state(&self) -> &BundleState; | ||
|
|
||
| /// Gets a mutable reference to the internal [`BundleState`] | ||
| fn bundle_state_mut(&mut self) -> &mut BundleState; | ||
|
|
||
| /// This will not apply any pending [`revm::database::TransitionState`]. | ||
| /// | ||
| /// It is recommended to call [`StateDB::merge_transitions`] before taking the bundle. | ||
| /// | ||
| /// If the `State` has been built with the | ||
| /// [`revm::database::StateBuilder::with_bundle_prestate`] option, the pre-state will be | ||
| /// taken along with any changes made by [`StateDB::merge_transitions`]. | ||
| fn take_bundle(&mut self) -> BundleState { | ||
| core::mem::take(self.bundle_state_mut()) | ||
| } | ||
|
|
||
| /// Take all transitions and merge them inside [`BundleState`]. | ||
| /// | ||
| /// This action will create final post state and all reverts so that | ||
| /// we at any time revert state of bundle to the state before transition | ||
| /// is applied. | ||
| fn merge_transitions(&mut self, retention: BundleRetention); | ||
| } | ||
|
|
||
| impl<DB: revm::Database + Debug> StateDB for State<DB> { | ||
| fn bundle_state(&self) -> &BundleState { | ||
| &self.bundle_state | ||
| } | ||
|
|
||
| fn bundle_state_mut(&mut self) -> &mut BundleState { | ||
| &mut self.bundle_state | ||
| } | ||
|
|
||
| impl<T> StateDB for T where T: Database + DatabaseCommit {} | ||
| fn merge_transitions(&mut self, retention: BundleRetention) { | ||
| Self::merge_transitions(self, retention); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
it is not entirely clear to me why this abstraction is needed, what is your usecase? right now basic block executors are already agnostic of concrete db
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.
@klkvr did you miss this comment?
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 need this abstraction because our access list block builder needs to be able to wrap
revm::StateUh oh!
There was an error while loading. Please reload this page.
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.
ah yep sorry missed it, just to confirm — you need this so that your custom block builder can use
BasicBlockBuilder::finishAPI directly instead of duplicating the logic?i'm quite happy with the way current abstraction works in a sense that it allows any database to be used for a
BlockExecutor. if we need an additional abstraction forStatedb specific methods i'd prefer it to not affectBlockExecutorFactorytrait at all but instead only be used for the reth's block builder construction methodsi'd be open to moving
StateDBtrait entirely into reth for thisThere 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'm not entirely sure what you're suggesting. We already have StateDB used in the BlockExecutor impls. What is your reasoning for not wanting this? The previous implementation relied directly on revm::State, which is strictly less flexible.
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.
yep and current implementation works with any database which is very flexible which is why I'm a bit hesitant on making it stricter