Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
refactor(vm-runner): simplify last processed batch query (matter-labs…
Browse files Browse the repository at this point in the history
…#2373)

## What ❔

Refactors query to not use default param and return `Option` instead

## Why ❔

Transparent flow

## Checklist

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

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
itegulov authored and irnb committed Jul 12, 2024
1 parent bca7ee7 commit 8f2d1c9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.

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

This file was deleted.

10 changes: 4 additions & 6 deletions core/lib/dal/src/vm_runner_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ pub struct VmRunnerDal<'c, 'a> {
impl VmRunnerDal<'_, '_> {
pub async fn get_protective_reads_latest_processed_batch(
&mut self,
default_batch: L1BatchNumber,
) -> DalResult<L1BatchNumber> {
) -> DalResult<Option<L1BatchNumber>> {
let row = sqlx::query!(
r#"
SELECT
COALESCE(MAX(l1_batch_number), $1) AS "last_processed_l1_batch!"
MAX(l1_batch_number) AS "last_processed_l1_batch"
FROM
vm_runner_protective_reads
"#,
default_batch.0 as i32
"#
)
.instrument("get_protective_reads_latest_processed_batch")
.report_latency()
.fetch_one(self.storage)
.await?;
Ok(L1BatchNumber(row.last_processed_l1_batch as u32))
Ok(row.last_processed_l1_batch.map(|n| L1BatchNumber(n as u32)))
}

pub async fn get_protective_reads_last_ready_batch(
Expand Down
3 changes: 2 additions & 1 deletion core/node/metadata_calculator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ async fn expected_tree_hash(pool: &ConnectionPool<Core>, sealed_protective_reads
} else {
storage
.vm_runner_dal()
.get_protective_reads_latest_processed_batch(L1BatchNumber(0))
.get_protective_reads_latest_processed_batch()
.await
.unwrap()
.unwrap_or_default()
};
let mut all_logs = vec![];
for i in 0..=processed_l1_batch_number.0 {
Expand Down
8 changes: 5 additions & 3 deletions core/node/metadata_calculator/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ impl TreeUpdater {
} else {
storage
.vm_runner_dal()
.get_protective_reads_latest_processed_batch(L1BatchNumber(0))
.get_protective_reads_latest_processed_batch()
.await
.context("failed loading latest L1 batch number with protective reads")?
.unwrap_or_default()
};
drop(storage);

Expand Down Expand Up @@ -423,8 +424,9 @@ impl AsyncTree {

let current_db_batch = storage
.vm_runner_dal()
.get_protective_reads_latest_processed_batch(L1BatchNumber(0))
.await?;
.get_protective_reads_latest_processed_batch()
.await?
.unwrap_or_default();
let last_l1_batch_with_tree_data = storage
.blocks_dal()
.get_last_l1_batch_number_with_tree_data()
Expand Down
5 changes: 3 additions & 2 deletions core/node/vm_runner/src/impls/protective_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ impl VmRunnerIo for ProtectiveReadsIo {
) -> anyhow::Result<L1BatchNumber> {
Ok(conn
.vm_runner_dal()
.get_protective_reads_latest_processed_batch(self.first_processed_batch)
.await?)
.get_protective_reads_latest_processed_batch()
.await?
.unwrap_or(self.first_processed_batch))
}

async fn last_ready_to_be_loaded_batch(
Expand Down

0 comments on commit 8f2d1c9

Please sign in to comment.