Skip to content

Commit

Permalink
Eagerly compute witness when sequencing
Browse files Browse the repository at this point in the history
Before this change, the witness of a batch is computed only right before being sent to an executor. This mechanism can result in a longer time in chain unwinding if the witness to be computed is far away from the head. For example, if the batch to be verified is 1000 batches behind the tip of the sequencer, the sequencer will need to unwind the same amount batches before computing the witness. Overall, the unnecessary computation complexity of this behavior is O(n^2), where n is the number of pending batches to be verified.
We can remove this redundant computation by always eagerly computing the witness when a batch is closed, without delaying to the verification promise and therefore avoid chain unwinding overall.
  • Loading branch information
cffls committed Oct 16, 2024
1 parent b87b00f commit 8d1f0d9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions zk/legacy_executor_verifier/legacy_executor_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,6 @@ func (v *LegacyExecutorVerifier) VerifyAsync(request *VerifierRequest) *Promise[
verifierBundle := NewVerifierBundle(request, nil, false)
blockNumbers := verifierBundle.Request.BlockNumbers

e := v.GetNextOnlineAvailableExecutor()
if e == nil {
return verifierBundle, ErrNoExecutorAvailable
}

t := utils.StartTimer("legacy-executor-verifier", "verify-async")
defer t.LogTimer()

e.AquireAccess()
defer e.ReleaseAccess()
if v.cancelAllVerifications.Load() {
return nil, ErrPromiseCancelled
}

var err error
ctx := context.Background()
// mapmutation has some issue with us not having a quit channel on the context call to `Done` so
Expand Down Expand Up @@ -300,6 +286,20 @@ func (v *LegacyExecutorVerifier) VerifyAsync(request *VerifierRequest) *Promise[

verifierBundle.markAsreadyForSendingRequest()

e := v.GetNextOnlineAvailableExecutor()
if e == nil {
return verifierBundle, ErrNoExecutorAvailable
}

t := utils.StartTimer("legacy-executor-verifier", "verify-async")
defer t.LogTimer()

e.AquireAccess()
defer e.ReleaseAccess()
if v.cancelAllVerifications.Load() {
return nil, ErrPromiseCancelled
}

ok, executorResponse, executorErr, generalErr := e.Verify(payload, request, previousBlock.Root())
if generalErr != nil {
return verifierBundle, generalErr
Expand Down

0 comments on commit 8d1f0d9

Please sign in to comment.