Skip to content

Commit

Permalink
rejig of batch closing logic in the sequencer (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott committed Sep 3, 2024
1 parent 5e898e9 commit c05dae2
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions zk/stages/stage_sequence_execute_data_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (sbc *SequencerBatchStreamWriter) writeBlockDetailsToDatastream(verifiedBun
func alignExecutionToDatastream(batchContext *BatchContext, batchState *BatchState, lastExecutedBlock uint64, u stagedsync.Unwinder) (bool, error) {
lastExecutedBatch := batchState.batchNumber - 1

lastDatastreamBatch, err := batchContext.cfg.datastreamServer.GetHighestBatchNumber()
lastDatastreamBatch, err := batchContext.cfg.datastreamServer.GetHighestClosedBatch()
if err != nil {
return false, err
}
Expand All @@ -97,22 +97,24 @@ func alignExecutionToDatastream(batchContext *BatchContext, batchState *BatchSta
return false, err
}

if lastExecutedBatch == lastDatastreamBatch && lastExecutedBlock == lastDatastreamBlock {
return false, nil
if lastExecutedBatch != lastDatastreamBatch {
if err := finalizeLastBatchInDatastreamIfNotFinalized(batchContext, lastExecutedBatch, lastDatastreamBlock); err != nil {
return false, err
}
}

if err := finalizeLastBatchInDatastreamIfNotFinalized(batchContext, lastDatastreamBatch, lastDatastreamBlock); err != nil {
return false, err
}
if lastExecutedBlock != lastDatastreamBlock {
block, err := rawdb.ReadBlockByNumber(batchContext.sdb.tx, lastDatastreamBlock)
if err != nil {
return false, err
}

block, err := rawdb.ReadBlockByNumber(batchContext.sdb.tx, lastDatastreamBlock)
if err != nil {
return false, err
log.Warn(fmt.Sprintf("[%s] Unwinding due to a datastream gap", batchContext.s.LogPrefix()), "streamHeight", lastDatastreamBlock, "sequencerHeight", lastExecutedBlock)
u.UnwindTo(lastDatastreamBlock, block.Hash())
return true, nil
}

log.Warn(fmt.Sprintf("[%s] Unwinding due to a datastream gap", batchContext.s.LogPrefix()), "streamHeight", lastDatastreamBlock, "sequencerHeight", lastExecutedBlock)
u.UnwindTo(lastDatastreamBlock, block.Hash())
return true, nil
return false, nil
}

func finalizeLastBatchInDatastreamIfNotFinalized(batchContext *BatchContext, batchToClose, blockToCloseAt uint64) error {
Expand Down

0 comments on commit c05dae2

Please sign in to comment.