Skip to content

Commit

Permalink
fix(stage_batches): only unwind if the stream block is ahead of the d…
Browse files Browse the repository at this point in the history
…b block
  • Loading branch information
revitteth committed Sep 26, 2024
1 parent f3ae985 commit 91a4bd4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 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 bath 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,12 @@ 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))
}

// 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 +414,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

0 comments on commit 91a4bd4

Please sign in to comment.