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

Batches: Only unwind if stream ahead of db #1236

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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
17 changes: 9 additions & 8 deletions zk/stages/stage_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ LOOP:
return err
}

if entry.BatchNumber != dbBatchNum {
// if the bath number mismatches, it means that we need to trigger an unwinding of blocks
if entry.BatchNumber > dbBatchNum {
// if the batch number is higher than the one we know about, it means that we need to trigger an unwinding of blocks
log.Warn(fmt.Sprintf("[%s] Batch number mismatch detected. Triggering unwind...", logPrefix),
"block", entry.L2BlockNumber, "ds batch", entry.BatchNumber, "db batch", dbBatchNum)
if err := rollback(logPrefix, eriDb, hermezDb, dsQueryClient, entry.L2BlockNumber, tx, u); err != nil {
Expand Down Expand Up @@ -400,7 +400,13 @@ LOOP:

// skip if we already have this block
if entry.L2BlockNumber < lastBlockHeight+1 {
log.Warn(fmt.Sprintf("[%s] Unwinding to block %d", logPrefix, entry.L2BlockNumber))
log.Warn(fmt.Sprintf("[%s] Skipping block %d, already processed", logPrefix, entry.L2BlockNumber))
continue
}

// check for sequential block numbers
if entry.L2BlockNumber > lastBlockHeight+1 {
log.Warn(fmt.Sprintf("[%s] Stream skipped ahead, unwinding to block %d", logPrefix, entry.L2BlockNumber))
badBlock, err := eriDb.ReadCanonicalHash(entry.L2BlockNumber)
if err != nil {
return fmt.Errorf("failed to get bad block: %v", err)
Expand All @@ -409,11 +415,6 @@ LOOP:
return nil
}

// check for sequential block numbers
if entry.L2BlockNumber != lastBlockHeight+1 {
return fmt.Errorf("block number is not sequential, expected %d, got %d", lastBlockHeight+1, entry.L2BlockNumber)
}

// batch boundary - record the highest hashable block number (last block in last full batch)
if entry.BatchNumber > highestSeenBatchNo {
highestHashableL2BlockNo = entry.L2BlockNumber - 1
Expand Down
Loading