-
Notifications
You must be signed in to change notification settings - Fork 95
[Feature] Relax trait bound EVM::DB = &'db mut State<DB> for BlockExecutor impls
#234
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9cb741a
feat: StateDB trait
0xForerunner 30f447a
feat: replace &mut State<DB> with impl StateDB
0xForerunner ff48609
feat: move StateDB to state.rs
0xForerunner e07e8f4
feat: remove StateDB associated type in favour of supertrait
0xForerunner 6fa6103
feat: StateDB use fully qualified syntax
0xForerunner 5814d79
Apply suggestion from @klkvr
klkvr 6bf217d
Apply suggestion from @klkvr
klkvr 1639c3b
Apply suggestion from @klkvr
klkvr 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
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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //! State database abstraction. | ||
|
|
||
| use alloy_primitives::Address; | ||
| use revm::database::State; | ||
|
|
||
| /// A type which has the state of the blockchain. | ||
| /// | ||
| /// This trait encapsulates some of the functionality found in [`State`] | ||
| pub trait StateDB: revm::Database { | ||
| /// State clear EIP-161 is enabled in Spurious Dragon hardfork. | ||
| fn set_state_clear_flag(&mut self, has_state_clear: bool); | ||
|
|
||
| /// Iterates over received balances and increment all account balances. | ||
| /// | ||
| /// **Note**: If account is not found inside cache state it will be loaded from database. | ||
| /// | ||
| /// Update will create transitions for all accounts that are updated. | ||
| /// | ||
| /// If using this to implement withdrawals, zero balances must be filtered out before calling | ||
| /// this function. | ||
| fn increment_balances( | ||
| &mut self, | ||
| balances: impl IntoIterator<Item = (Address, u128)>, | ||
| ) -> Result<(), Self::Error>; | ||
| } | ||
|
|
||
| /// auto_impl unable to reconcile return associated type from supertrait | ||
|
Member
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. maybe |
||
| impl<T: StateDB> StateDB for &mut T { | ||
| fn set_state_clear_flag(&mut self, has_state_clear: bool) { | ||
| StateDB::set_state_clear_flag(*self, has_state_clear); | ||
| } | ||
|
|
||
| fn increment_balances( | ||
| &mut self, | ||
| balances: impl IntoIterator<Item = (Address, u128)>, | ||
| ) -> Result<(), Self::Error> { | ||
| StateDB::increment_balances(*self, balances) | ||
| } | ||
| } | ||
|
|
||
| impl<DB: revm::Database> StateDB for State<DB> { | ||
| fn set_state_clear_flag(&mut self, has_state_clear: bool) { | ||
| self.cache.set_state_clear_flag(has_state_clear); | ||
| } | ||
|
|
||
| fn increment_balances( | ||
| &mut self, | ||
| balances: impl IntoIterator<Item = (Address, u128)>, | ||
| ) -> Result<(), Self::Error> { | ||
| Self::increment_balances(self, balances) | ||
| } | ||
| } | ||
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
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
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
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.
imo we can keep
StateDBhere, hard to find a good name here -.-