-
Notifications
You must be signed in to change notification settings - Fork 51
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
|
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
@@ -297,7 +306,7 @@ async fn handle_forkchoice( | |||
let forkchoice_response = match forkchoice_error { | |||
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
@@ -573,7 +616,10 @@ impl StoreEngine for Store { | |||
self.write_batch::<Receipts>(key_values).await | |||
} | |||
|
|||
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
@@ -837,7 +890,10 @@ impl StoreEngine for Store { | |||
.map_err(|e| StoreError::Custom(format!("task panicked: {e}")))? | |||
} | |||
|
|||
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
@@ -624,7 +630,7 @@ impl StoreEngine for RedBStore { | |||
.await | |||
} | |||
|
|||
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.
@@ -642,7 +648,7 @@ impl StoreEngine for RedBStore { | |||
.await | |||
} | |||
|
|||
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
|
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 #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 #2424