Skip to content

Commit

Permalink
Fail in processSequenceBatches if we don't have the parent batch
Browse files Browse the repository at this point in the history
This will cause an error if there has been a reorg since we fetched the
batches. In normal mode, this should never happen, since we check for
reorgs and then fetch batches synchronously. But in preconfirmations
mode, the batches are fetched asynchronously wrt to the reorg
detection, and so the L2 head can change under us. In this case the
new check will fail and we will re-fetch preconfirmations after
checking the new L2 head.

Fixes EspressoSystems/espresso-polygon-zkevm-demo#246
  • Loading branch information
jbearer committed Oct 12, 2023
1 parent cc393ab commit a05c779
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,23 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman.
return nil
}

if lastBatch, err := s.state.GetLastBatchNumber(s.ctx, dbTx); err != nil {
log.Errorf("Error fetching previous batch number: %w", err)
rollbackErr := dbTx.Rollback(s.ctx)
if rollbackErr != nil {
log.Fatalf("error rolling back state. rollbackErr: %s, error : %w", rollbackErr.Error(), err)
}
return err
} else if sequencedBatches[0].BatchNumber != lastBatch + 1 {
err = fmt.Errorf("New batch %d is not successor of last synced batch %d, there may have been a reorg", sequencedBatches[0].BatchNumber, lastBatch)
log.Warnf("Possible reorg detected: %w", err)
rollbackErr := dbTx.Rollback(s.ctx)
if rollbackErr != nil {
log.Fatalf("error rolling back state. rollbackErr: %s, error : %w", rollbackErr.Error(), err)
}
return err
}

for _, sbatch := range sequencedBatches {
// Ensure the L1 origin for this batch is in the database. Since the L1 origin assigned by
// HotShot is not necessarily the same as an L1 block which we added to the database as a
Expand Down

0 comments on commit a05c779

Please sign in to comment.