Skip to content

Commit

Permalink
speed up L1 recovery process (0xPolygonHermez#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott authored Aug 23, 2024
1 parent ff806a4 commit a61220d
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ func SpawnSequencingStage(
// we consider the data stream as verified by the executor so treat it as "safe" and unwind blocks beyond there
// if we identify any. During normal operation this function will simply check and move on without performing
// any action.
isUnwinding, err := handleBatchEndChecks(batchContext, batchState, executionAt, u)
if err != nil || isUnwinding {
return err
if !batchState.isL1Recovery() {
isUnwinding, err := handleBatchEndChecks(batchContext, batchState, executionAt, u)
if err != nil || isUnwinding {
return err
}
}

tryHaltSequencer(batchContext, batchState.batchNumber)
Expand Down Expand Up @@ -220,12 +222,11 @@ func SpawnSequencingStage(
if err != nil {
return err
}
}

if len(batchState.blockState.transactionsForInclusion) == 0 {
time.Sleep(250 * time.Millisecond)
} else {
log.Trace(fmt.Sprintf("[%s] Yielded transactions from the pool", logPrefix), "txCount", len(batchState.blockState.transactionsForInclusion))
if len(batchState.blockState.transactionsForInclusion) == 0 {
time.Sleep(250 * time.Millisecond)
} else {
log.Trace(fmt.Sprintf("[%s] Yielded transactions from the pool", logPrefix), "txCount", len(batchState.blockState.transactionsForInclusion))
}
}

for i, transaction := range batchState.blockState.transactionsForInclusion {
Expand Down Expand Up @@ -334,21 +335,26 @@ func SpawnSequencingStage(
batchState.onBuiltBlock(blockNumber)

// commit block data here so it is accessible in other threads
if errCommitAndStart := sdb.CommitAndStart(); errCommitAndStart != nil {
return errCommitAndStart
if !batchState.isL1Recovery() {
if errCommitAndStart := sdb.CommitAndStart(); errCommitAndStart != nil {
return errCommitAndStart
}
defer sdb.tx.Rollback()
}
defer sdb.tx.Rollback()

cfg.legacyVerifier.StartAsyncVerification(batchState.forkId, batchState.batchNumber, block.Root(), batchCounters.CombineCollectorsNoChanges().UsedAsMap(), batchState.builtBlocks, batchState.hasExecutorForThisBatch, batchContext.cfg.zk.SequencerBatchVerificationTimeout)

// check for new responses from the verifier
needsUnwind, err := updateStreamAndCheckRollback(batchContext, batchState, streamWriter, u)

// lets commit everything after updateStreamAndCheckRollback no matter of its result
if errCommitAndStart := sdb.CommitAndStart(); errCommitAndStart != nil {
return errCommitAndStart
// lets commit everything after updateStreamAndCheckRollback no matter of its result unless
// we're in L1 recovery where losing some blocks on restart doesn't matter
if !batchState.isL1Recovery() {
if errCommitAndStart := sdb.CommitAndStart(); errCommitAndStart != nil {
return errCommitAndStart
}
defer sdb.tx.Rollback()
}
defer sdb.tx.Rollback()

// check the return values of updateStreamAndCheckRollback
if err != nil || needsUnwind {
Expand Down

0 comments on commit a61220d

Please sign in to comment.