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

fix(stage_batches): only unwind if the stream block is ahead #1250

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions turbo/stages/stageloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ func StageLoop(
if errors.Is(err, libcommon.ErrStopped) || errors.Is(err, context.Canceled) {
return
}

if !errors.Is(err, zk.ErrLimboState) {
log.Error("Staged Sync", "err", err)
}
if recoveryErr := hd.RecoverFromDb(db); recoveryErr != nil {
log.Error("Failed to recover header sentriesClient", "err", recoveryErr)
}
time.Sleep(500 * time.Millisecond) // just to avoid too much similar errors in logs
continue
}
Expand Down
33 changes: 19 additions & 14 deletions zk/stages/stage_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,19 @@ 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.Info(fmt.Sprintf("[%s] Skipping block %d, already processed", logPrefix, entry.L2BlockNumber))
continue
}

// if the block number isn't last + 1 then we've skipped AHEAD (see above logic to continue if we're behind)
if entry.L2BlockNumber != lastBlockHeight+1 {
log.Warn(fmt.Sprintf("[%s] Stream ahead of node, 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)
}
u.UnwindTo(entry.L2BlockNumber, badBlock)
}

// 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)
return nil
}

// batch boundary - record the highest hashable block number (last block in last full batch)
Expand Down Expand Up @@ -424,16 +426,19 @@ LOOP:
return err
}

if err := tx.Commit(); err != nil {
return fmt.Errorf("failed to commit tx, %w", err)
}
if freshTx {
if err := tx.Commit(); err != nil {
return fmt.Errorf("failed to commit tx, %w", err)
}

tx, err = cfg.db.BeginRw(ctx)
if err != nil {
return fmt.Errorf("failed to open tx, %w", err)
tx, err = cfg.db.BeginRw(ctx)
if err != nil {
return fmt.Errorf("failed to open tx, %w", err)
}
hermezDb = hermez_db.NewHermezDb(tx)
eriDb = erigon_db.NewErigonDb(tx)
}
hermezDb = hermez_db.NewHermezDb(tx)
eriDb = erigon_db.NewErigonDb(tx)

prevAmountBlocksWritten = blocksWritten
}

Expand Down