Skip to content

Commit

Permalink
fix(vm-runner): make last_ready_batch account for `first_processed_…
Browse files Browse the repository at this point in the history
…batch` (#2238)

## What ❔

Fixes a bug that is currently being observed on testnet

## Why ❔

Previously, on a fresh start, `last_ready_batch` could report incorrect
batch meaning no progress would be made as `last_ready_batch` would be
far less than `first_processed_batch`.

## 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).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
itegulov committed Jun 14, 2024
1 parent 5696564 commit 3889794
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.

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

4 changes: 3 additions & 1 deletion core/lib/dal/src/vm_runner_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl VmRunnerDal<'_, '_> {

pub async fn get_protective_reads_last_ready_batch(
&mut self,
default_batch: L1BatchNumber,
window_size: u32,
) -> DalResult<L1BatchNumber> {
let row = sqlx::query!(
Expand All @@ -44,7 +45,7 @@ impl VmRunnerDal<'_, '_> {
),
processed_batches AS (
SELECT
COALESCE(MAX(l1_batch_number), 0) + $1 AS "last_ready_batch"
COALESCE(MAX(l1_batch_number), $1) + $2 AS "last_ready_batch"
FROM
vm_runner_protective_reads
)
Expand All @@ -54,6 +55,7 @@ impl VmRunnerDal<'_, '_> {
available_batches
FULL JOIN processed_batches ON TRUE
"#,
default_batch.0 as i32,
window_size as i32
)
.instrument("get_protective_reads_last_ready_batch")
Expand Down
2 changes: 1 addition & 1 deletion core/node/vm_runner/src/impls/protective_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl VmRunnerIo for ProtectiveReadsIo {
) -> anyhow::Result<L1BatchNumber> {
Ok(conn
.vm_runner_dal()
.get_protective_reads_last_ready_batch(self.window_size)
.get_protective_reads_last_ready_batch(self.first_processed_batch, self.window_size)
.await?)
}

Expand Down

0 comments on commit 3889794

Please sign in to comment.