Skip to content

Commit

Permalink
do not unwind/prune l1 sync data
Browse files Browse the repository at this point in the history
As we unwind now on sequencer restart this process can take a long time on each sequencer restart.  As we only sync finalised data from the L1 this will not change anyway so no point unwinding it
  • Loading branch information
hexoscott committed Aug 29, 2024
1 parent 64e52cf commit 30d3369
Showing 1 changed file with 3 additions and 70 deletions.
73 changes: 3 additions & 70 deletions zk/stages/stage_l1syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,80 +280,13 @@ func parseLogType(l1RollupId uint64, log *ethTypes.Log) (l1BatchInfo types.L1Bat
}

func UnwindL1SyncerStage(u *stagedsync.UnwindState, tx kv.RwTx, cfg L1SyncerCfg, ctx context.Context) (err error) {
useExternalTx := tx != nil
if !useExternalTx {
tx, err = cfg.db.BeginRw(ctx)
if err != nil {
return err
}
defer tx.Rollback()
}
log.Debug("l1 sync: unwinding")

/*
1. unwind sequences table
2. unwind verifications table
3. update l1verifications batchno and l1syncer stage progress
*/

err = tx.ClearBucket(hermez_db.L1SEQUENCES)
if err != nil {
return err
}
err = tx.ClearBucket(hermez_db.L1VERIFICATIONS)
if err != nil {
return err
}

// the below are very inefficient due to key layout
//hermezDb := hermez_db.NewHermezDb(tx)
//err = hermezDb.TruncateSequences(u.UnwindPoint)
//if err != nil {
// return err
//}
//
//err = hermezDb.TruncateVerifications(u.UnwindPoint)
//if err != nil {
// return err
//}
// get the now latest l1 verification
//v, err := hermezDb.GetLatestVerification()
//if err != nil {
// return err
//}

if err := stages.SaveStageProgress(tx, stages.L1VerificationsBatchNo, 0); err != nil {
return fmt.Errorf("failed to save stage progress, %w", err)
}
if err := stages.SaveStageProgress(tx, stages.L1Syncer, 0); err != nil {
return fmt.Errorf("failed to save stage progress, %w", err)
}

if !useExternalTx {
if err := tx.Commit(); err != nil {
return err
}
}
// we want to keep L1 data during an unwind, as we only sync finalised data there should be
// no need to unwind here
return nil
}

func PruneL1SyncerStage(s *stagedsync.PruneState, tx kv.RwTx, cfg L1SyncerCfg, ctx context.Context) (err error) {
useExternalTx := tx != nil
if !useExternalTx {
tx, err = cfg.db.BeginRw(ctx)
if err != nil {
return err
}
defer tx.Rollback()
}

// TODO: implement prune L1 Verifications stage! (if required)

if !useExternalTx {
if err := tx.Commit(); err != nil {
return err
}
}
// no need to prune this data
return nil
}

Expand Down

0 comments on commit 30d3369

Please sign in to comment.