@@ -21,6 +21,7 @@ import (
2121 "scroll-tech/coordinator/internal/config"
2222 "scroll-tech/coordinator/internal/orm"
2323 coordinatorType "scroll-tech/coordinator/internal/types"
24+ cutils "scroll-tech/coordinator/internal/utils"
2425)
2526
2627// BundleProverTask is prover task implement for bundle proof
@@ -63,6 +64,18 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat
6364
6465 maxActiveAttempts := bp .cfg .ProverManager .ProversPerSession
6566 maxTotalAttempts := bp .cfg .ProverManager .SessionAttempts
67+ if taskCtx .ProverProviderType == uint8 (coordinatorType .ProverProviderTypeExternal ) {
68+ unassignedBundleCount , getCountError := bp .bundleOrm .GetUnassignedBundleCount (ctx .Copy (), maxActiveAttempts , maxTotalAttempts )
69+ if getCountError != nil {
70+ log .Error ("failed to get unassigned bundle proving tasks count" , "height" , getTaskParameter .ProverHeight , "err" , getCountError )
71+ return nil , ErrCoordinatorInternalFailure
72+ }
73+ // Assign external prover if unassigned task number exceeds threshold
74+ if unassignedBundleCount < bp .cfg .ProverManager .ExternalProverThreshold {
75+ return nil , nil
76+ }
77+ }
78+
6679 var bundleTask * orm.Bundle
6780 for i := 0 ; i < 5 ; i ++ {
6881 var getTaskError error
@@ -88,6 +101,20 @@ func (bp *BundleProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinat
88101 return nil , nil
89102 }
90103
104+ // Don't dispatch the same failing job to the same prover
105+ proverTasks , getTaskError := bp .proverTaskOrm .GetFailedProverTasksByHash (ctx .Copy (), message .ProofTypeBundle , tmpBundleTask .Hash , 2 )
106+ if getTaskError != nil {
107+ log .Error ("failed to get prover tasks" , "proof type" , message .ProofTypeBundle .String (), "task ID" , tmpBundleTask .Hash , "error" , getTaskError )
108+ return nil , ErrCoordinatorInternalFailure
109+ }
110+ for i := 0 ; i < len (proverTasks ); i ++ {
111+ if proverTasks [i ].ProverPublicKey == taskCtx .PublicKey ||
112+ taskCtx .ProverProviderType == uint8 (coordinatorType .ProverProviderTypeExternal ) && cutils .IsExternalProverNameMatch (proverTasks [i ].ProverName , taskCtx .ProverName ) {
113+ log .Debug ("get empty bundle, the prover already failed this task" , "height" , getTaskParameter .ProverHeight )
114+ return nil , nil
115+ }
116+ }
117+
91118 rowsAffected , updateAttemptsErr := bp .bundleOrm .UpdateBundleAttempts (ctx .Copy (), tmpBundleTask .Hash , tmpBundleTask .ActiveAttempts , tmpBundleTask .TotalAttempts )
92119 if updateAttemptsErr != nil {
93120 log .Error ("failed to update bundle attempts" , "height" , getTaskParameter .ProverHeight , "err" , updateAttemptsErr )
0 commit comments