Skip to content

Commit

Permalink
perf(logs-bloom): do not run heavy query if migration was completed (m…
Browse files Browse the repository at this point in the history
…atter-labs#2680)

## What ❔

Do not run heavy query if logs bloom migration was completed


## Why ❔

Do not put additional load on DB

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
perekopskiy committed Aug 19, 2024
1 parent 232a817 commit f9ef00e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.

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

0 comments on commit f9ef00e

Please sign in to comment.