Skip to content
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

perf(logs-bloom): do not run heavy query if migration was completed #2680

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,25 @@ impl BlocksDal<'_, '_> {
Ok(results.into_iter().map(L::from).collect())
}

pub async fn has_l2_block_bloom(&mut self, l2_block_number: L2BlockNumber) -> DalResult<bool> {
let row = sqlx::query!(
r#"
SELECT
(logs_bloom IS NOT NULL) AS "logs_bloom_not_null!"
FROM
miniblocks
WHERE
number = $1
"#,
i64::from(l2_block_number.0),
)
.instrument("has_l2_block_bloom")
.fetch_optional(self.storage)
.await?;

Ok(row.map(|row| row.logs_bloom_not_null).unwrap_or(false))
}

pub async fn has_last_l2_block_bloom(&mut self) -> DalResult<bool> {
let row = sqlx::query!(
r#"
Expand Down
8 changes: 8 additions & 0 deletions core/node/logs_bloom_backfill/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ impl LogsBloomBackfill {
return Ok(()); // Stop signal received
}

let genesis_block_has_bloom = connection
.blocks_dal()
.has_l2_block_bloom(L2BlockNumber(0))
.await?;
if genesis_block_has_bloom {
return Ok(()); // Migration has already been completed.
}

let max_block_without_bloom = connection
.blocks_dal()
.get_max_l2_block_without_bloom()
Expand Down
Loading