From 8d1f0d90abcf478f8b3edbd009d9918e13da5e6f Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 16 Oct 2024 08:15:55 -0700 Subject: [PATCH] Eagerly compute witness when sequencing 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. --- .../legacy_executor_verifier.go | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/zk/legacy_executor_verifier/legacy_executor_verifier.go b/zk/legacy_executor_verifier/legacy_executor_verifier.go index 7084d33aefe..b7392822d1a 100644 --- a/zk/legacy_executor_verifier/legacy_executor_verifier.go +++ b/zk/legacy_executor_verifier/legacy_executor_verifier.go @@ -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 @@ -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