Skip to content

Commit

Permalink
fix: no resequence if l1 sync enabled (#1578)
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Staykov authored Dec 18, 2024
1 parent 59008ac commit 991fecf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
isSequencer := sequencer.IsSequencer()

// if the L1 block sync is set we're in recovery so can't run as a sequencer
if cfg.L1SyncStartBlock > 0 {
if cfg.IsL1Recovery() {
if !isSequencer {
panic("you cannot launch in l1 sync mode as an RPC node")
}
Expand Down
4 changes: 4 additions & 0 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ func (c *Zk) HasExecutors() bool {
func (c *Zk) ShouldImportInitialBatch() bool {
return c.InitialBatchCfgFile != ""
}

func (c *Zk) IsL1Recovery() bool {
return c.L1SyncStartBlock > 0
}
11 changes: 8 additions & 3 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func SpawnSequencingStage(
}

if lastBatch < highestBatchInDs {
return resequence(s, u, ctx, cfg, historyCfg, lastBatch, highestBatchInDs)
if err = cfg.dataStreamServer.UnwindToBatchStart(lastBatch + 1); err != nil {
return err
}
if !cfg.zk.IsL1Recovery() {
return resequence(s, u, ctx, cfg, historyCfg, lastBatch, highestBatchInDs)
}
}

if cfg.zk.SequencerResequence {
Expand Down Expand Up @@ -108,15 +113,15 @@ func sequencingBatchStep(
return nil
}

batchNumberForStateInitialization, err := prepareBatchNumber(sdb, forkId, lastBatch, cfg.zk.L1SyncStartBlock > 0)
batchNumberForStateInitialization, err := prepareBatchNumber(sdb, forkId, lastBatch, cfg.zk.IsL1Recovery())
if err != nil {
return err
}

var block *types.Block
runLoopBlocks := true
batchContext := newBatchContext(ctx, &cfg, &historyCfg, s, sdb)
batchState := newBatchState(forkId, batchNumberForStateInitialization, executionAt+1, cfg.zk.HasExecutors(), cfg.zk.L1SyncStartBlock > 0, cfg.txPool, resequenceBatchJob)
batchState := newBatchState(forkId, batchNumberForStateInitialization, executionAt+1, cfg.zk.HasExecutors(), cfg.zk.IsL1Recovery(), cfg.txPool, resequenceBatchJob)
blockDataSizeChecker := NewBlockDataChecker(cfg.zk.ShouldCountersBeUnlimited(batchState.isL1Recovery()))
streamWriter := newSequencerBatchStreamWriter(batchContext, batchState)

Expand Down
4 changes: 0 additions & 4 deletions zk/stages/stage_sequence_execute_resequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ func resequence(
return err
}

if err = cfg.dataStreamServer.UnwindToBatchStart(lastBatch + 1); err != nil {
return err
}

log.Info(fmt.Sprintf("[%s] Resequence from batch %d to %d in data stream", s.LogPrefix(), lastBatch+1, highestBatchInDs))
for _, batch := range batches {
batchJob := NewResequenceBatchJob(batch)
Expand Down
2 changes: 1 addition & 1 deletion zk/stages/stage_sequencer_l1_block_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func SpawnSequencerL1BlockSyncStage(
log.Info(fmt.Sprintf("[%s] Starting L1 block sync stage", logPrefix))
defer log.Info(fmt.Sprintf("[%s] Finished L1 block sync stage", logPrefix))

if cfg.zkCfg.L1SyncStartBlock == 0 {
if !cfg.zkCfg.IsL1Recovery() {
log.Info(fmt.Sprintf("[%s] Skipping L1 block sync stage", logPrefix))
return nil
}
Expand Down

0 comments on commit 991fecf

Please sign in to comment.