-
Notifications
You must be signed in to change notification settings - Fork 3
fix: use async db in sim_round #206
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
4 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
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
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,53 +1,64 @@ | ||
| use alloy::primitives::{Address, U256}; | ||
| use core::future::Future; | ||
| use trevm::revm::database_interface::async_db::DatabaseAsyncRef; | ||
|
|
||
| /// Account information including nonce and balance. This is partially modeled | ||
| /// after [`revm::AccountInfo`], but only includes the fields we care about. | ||
| /// | ||
| /// [`revm::AccountInfo`]: trevm::revm::state::AccountInfo | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct AcctInfo { | ||
| /// The account nonce. | ||
| pub nonce: u64, | ||
| /// The account balance. | ||
| pub balance: U256, | ||
| /// Whether the account has deployed code. | ||
| pub has_code: bool, | ||
| } | ||
|
|
||
| /// A source for nonce and balance information. Exists to simplify type bounds | ||
| /// in various places. | ||
| pub trait StateSource { | ||
| /// The error type for state lookups, usually a database error. | ||
| type Error: core::error::Error + 'static; | ||
| pub trait StateSource: Send + Sync { | ||
| /// The error type for state lookups. | ||
| type Error: core::error::Error + Send + 'static; | ||
|
|
||
| /// Get account details for an address. | ||
| fn account_details(&self, address: &Address) -> Result<AcctInfo, Self::Error>; | ||
| fn account_details( | ||
| &self, | ||
| address: &Address, | ||
| ) -> impl Future<Output = Result<AcctInfo, Self::Error>> + Send; | ||
|
|
||
| /// Get the nonce for an address. This should return the NEXT EXPECTED | ||
| /// nonce. I.e. `0` for an address that has never sent a transaction, 1 for an address that has sent exactly one transaction, etc. | ||
| fn nonce(&self, address: &Address) -> Result<u64, Self::Error> { | ||
| self.account_details(address).map(|info| info.nonce) | ||
| /// Get the nonce for an address. Returns the NEXT EXPECTED nonce, i.e. `0` for an address that | ||
| /// has never sent a transaction, 1 for an address that has sent exactly one transaction, etc. | ||
| fn nonce(&self, address: &Address) -> impl Future<Output = Result<u64, Self::Error>> + Send { | ||
| async { self.account_details(address).await.map(|info| info.nonce) } | ||
| } | ||
|
|
||
| /// Get the balance for an address. | ||
| fn balance(&self, address: &Address) -> Result<U256, Self::Error> { | ||
| self.account_details(address).map(|info| info.balance) | ||
| fn balance(&self, address: &Address) -> impl Future<Output = Result<U256, Self::Error>> + Send { | ||
| async { self.account_details(address).await.map(|info| info.balance) } | ||
| } | ||
|
|
||
| /// Run an arbitrary check on the account details for an address. | ||
| fn map<T, F: FnOnce(&AcctInfo) -> T>(&self, address: &Address, f: F) -> Result<T, Self::Error> { | ||
| self.account_details(address).map(|info| f(&info)) | ||
| fn map<T: Send, F: FnOnce(&AcctInfo) -> T + Send>( | ||
| &self, | ||
| address: &Address, | ||
| f: F, | ||
| ) -> impl Future<Output = Result<T, Self::Error>> + Send { | ||
| async { self.account_details(address).await.map(|info| f(&info)) } | ||
| } | ||
| } | ||
|
|
||
| impl<Db> StateSource for Db | ||
| where | ||
| Db: trevm::revm::DatabaseRef<Error: 'static>, | ||
| Db: DatabaseAsyncRef + Send + Sync, | ||
| Db::Error: Send + 'static, | ||
| { | ||
| type Error = Db::Error; | ||
|
|
||
| fn account_details(&self, address: &Address) -> Result<AcctInfo, Self::Error> { | ||
| let info = self.basic_ref(*address)?.unwrap_or_default(); | ||
|
|
||
| async fn account_details(&self, address: &Address) -> Result<AcctInfo, Self::Error> { | ||
| let info = self.basic_async_ref(*address).await?.unwrap_or_default(); | ||
| let has_code = info.code_hash() != trevm::revm::primitives::KECCAK_EMPTY; | ||
|
|
||
| Ok(AcctInfo { nonce: info.nonce, balance: info.balance, has_code }) | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
this new bound is significant, as it prevents implementation for the signet-storage MDBX revm accessors
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.
Hmm - that's unfortunate indeed. I don't see a way round adding these bounds for now, since the crux of the fix here is to use async DBs for the preflight work.
I guess it's something we might need to revisit when we come to using signet-storage here?