From 91a4bd4e5855e9e0e6c12c0975fa2bdd5035086c Mon Sep 17 00:00:00 2001 From: Max Revitt Date: Thu, 26 Sep 2024 14:42:21 +0100 Subject: [PATCH] fix(stage_batches): only unwind if the stream block is ahead of the db block --- zk/stages/stage_batches.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/zk/stages/stage_batches.go b/zk/stages/stage_batches.go index 97a0ed739c5..bb19fc01c11 100644 --- a/zk/stages/stage_batches.go +++ b/zk/stages/stage_batches.go @@ -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 { @@ -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) @@ -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