-
Notifications
You must be signed in to change notification settings - Fork 130
feat(l1, l2): make some store getters async #2430
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
Conversation
Lines of code reportTotal lines added: Detailed view |
mpaulucci
left a 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.
LGTM
| InvalidForkChoice::NewHeadAlreadyCanonical => { | ||
| ForkChoiceResponse::from(PayloadStatus::valid_with_hash( | ||
| latest_canonical_block_hash(&context.storage).unwrap(), | ||
| latest_canonical_block_hash(&context.storage).await.unwrap(), |
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.
Since this function returns a result, let's leverage this PR to remove this unwrap
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.
Done!
| let mut bodies = Vec::new(); | ||
| for hash in self.hashes.iter() { | ||
| bodies.push(context.storage.get_block_body_by_hash(*hash).await?) | ||
| } |
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 might make sense to do a single request to the DB for the bulk.
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.
Implemented
| for block_num in self.start..=last { | ||
| bodies.push(context.storage.get_block_body(block_num).await?) | ||
| } |
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.
Ditto.
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.
Implemented!
| }); | ||
| let latest_block_num = storage.get_latest_block_number().await?; | ||
| // Box needed to keep the future Sync | ||
| // https://github.com/rust-lang/rust/issues/128095 |
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's not very clear to me why we need to use box. There is no mention to it in that github issue.
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 doesn't have to be Box (anything that can keep the variable Sync works). The issue explains why we need to keep the variable Sync even though it's dropped before the next await
crates/storage/store_db/libmdbx.rs
Outdated
| } | ||
|
|
||
| fn get_receipts_for_block(&self, block_hash: &BlockHash) -> Result<Vec<Receipt>, StoreError> { | ||
| async fn get_receipts_for_block( |
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.
Why is this async if it doesn't go through the async api?
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.
Fixed
crates/storage/store_db/libmdbx.rs
Outdated
| } | ||
|
|
||
| fn read_account_snapshot(&self, start: H256) -> Result<Vec<(H256, AccountState)>, StoreError> { | ||
| async fn read_account_snapshot( |
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.
Same here, how is this async?
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.
Fixed
| } | ||
|
|
||
| fn get_finalized_block_number(&self) -> Result<Option<BlockNumber>, StoreError> { | ||
| async fn get_finalized_block_number(&self) -> Result<Option<BlockNumber>, StoreError> { |
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.
Is await missing here?
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 wasn't missing but the function was sync. Made it async.
| } | ||
|
|
||
| fn get_safe_block_number(&self) -> Result<Option<BlockNumber>, StoreError> { | ||
| async fn get_safe_block_number(&self) -> Result<Option<BlockNumber>, StoreError> { |
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.
Is await missing here?
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 wasn't missing but the function was sync. Made it async.
Benchmark Block Execution Results Comparison Against Main
|
Arkenan
left a 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.
LGTM
**Motivation** Like with lambdaclass#2336 the goal is to avoid blocking the current task. **Description** Makes store getters not related to tries (and thus the EVM) async, and propagates the changes to users of store. They are made async by using `spawn_blocking ` Many instances of functional code (`and_then`, `map`) had to be replaced due to bad async support. Closes lambdaclass#2424
…5408) **Motivation** When we added RPC metrics for success/error rates in #5335, we found that we were returning "Internal error" in the `engine_getPayloadBodiesByRange` method. This was related to changes done in #2430, which turned missing payloads into a DB error. The spec says we should return `null`s for any missing payloads, so this deviates from the spec. **Description** This PR fixes the spec deviation by changing the batch-GET methods from the Store API to return `None` on missing values instead of failing. Closes #5403 --------- Co-authored-by: Rodrigo Oliveri <[email protected]>
…5408) **Motivation** When we added RPC metrics for success/error rates in #5335, we found that we were returning "Internal error" in the `engine_getPayloadBodiesByRange` method. This was related to changes done in #2430, which turned missing payloads into a DB error. The spec says we should return `null`s for any missing payloads, so this deviates from the spec. **Description** This PR fixes the spec deviation by changing the batch-GET methods from the Store API to return `None` on missing values instead of failing. Closes #5403 --------- Co-authored-by: Rodrigo Oliveri <[email protected]>
Motivation
Like with #2336 the goal is to avoid blocking the current task.
Description
Makes store getters not related to tries (and thus the EVM) async, and propagates the changes to users of store. They are made async by using
spawn_blockingMany instances of functional code (
and_then,map) had to be replaced due to bad async support.Closes #2424