@@ -80,7 +80,7 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
8080 var getTaskError error
8181 var tmpChunkTask * orm.Chunk
8282 if taskCtx .hasAssignedTask != nil {
83- log .Debug ("retrived assigned task chunk" , "taskID" , taskCtx .hasAssignedTask .TaskID , "prover" , taskCtx .ProverName )
83+ log .Debug ("retrieved assigned task chunk" , "taskID" , taskCtx .hasAssignedTask .TaskID , "prover" , taskCtx .ProverName )
8484 tmpChunkTask , getTaskError = cp .chunkOrm .GetChunkByHash (ctx .Copy (), taskCtx .hasAssignedTask .TaskID )
8585 if getTaskError != nil {
8686 log .Error ("failed to get chunk has assigned to prover" , "taskID" , taskCtx .hasAssignedTask .TaskID , "err" , getTaskError )
@@ -124,31 +124,33 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
124124 return nil , nil
125125 }
126126
127- // Don't dispatch the same failing job to the same prover
128- proverTasks , getFailedTaskError := cp .proverTaskOrm .GetFailedProverTasksByHash (ctx .Copy (), message .ProofTypeChunk , tmpChunkTask .Hash , 2 )
129- if getFailedTaskError != nil {
130- log .Error ("failed to get prover tasks" , "proof type" , message .ProofTypeChunk .String (), "task ID" , tmpChunkTask .Hash , "error" , getFailedTaskError )
131- return nil , ErrCoordinatorInternalFailure
132- }
133- for i := 0 ; i < len (proverTasks ); i ++ {
134- if proverTasks [i ].ProverPublicKey == taskCtx .PublicKey ||
135- taskCtx .ProverProviderType == uint8 (coordinatorType .ProverProviderTypeExternal ) && cutils .IsExternalProverNameMatch (proverTasks [i ].ProverName , taskCtx .ProverName ) {
136- log .Debug ("get empty chunk, the prover already failed this task" , "height" , getTaskParameter .ProverHeight , "task ID" , tmpChunkTask .Hash , "prover name" , taskCtx .ProverName , "prover public key" , taskCtx .PublicKey )
137- return nil , nil
127+ // we are simply pick the chunk which has been assigned, so don't bother to update attempts or check failed before
128+ if taskCtx .hasAssignedTask != nil {
129+ // Don't dispatch the same failing job to the same prover
130+ proverTasks , getFailedTaskError := cp .proverTaskOrm .GetFailedProverTasksByHash (ctx .Copy (), message .ProofTypeChunk , tmpChunkTask .Hash , 2 )
131+ if getFailedTaskError != nil {
132+ log .Error ("failed to get prover tasks" , "proof type" , message .ProofTypeChunk .String (), "task ID" , tmpChunkTask .Hash , "error" , getFailedTaskError )
133+ return nil , ErrCoordinatorInternalFailure
134+ }
135+ for i := 0 ; i < len (proverTasks ); i ++ {
136+ if proverTasks [i ].ProverPublicKey == taskCtx .PublicKey ||
137+ taskCtx .ProverProviderType == uint8 (coordinatorType .ProverProviderTypeExternal ) && cutils .IsExternalProverNameMatch (proverTasks [i ].ProverName , taskCtx .ProverName ) {
138+ log .Debug ("get empty chunk, the prover already failed this task" , "height" , getTaskParameter .ProverHeight , "task ID" , tmpChunkTask .Hash , "prover name" , taskCtx .ProverName , "prover public key" , taskCtx .PublicKey )
139+ return nil , nil
140+ }
138141 }
139- }
140142
141- rowsAffected , updateAttemptsErr := cp .chunkOrm .UpdateChunkAttempts (ctx .Copy (), tmpChunkTask .Index , tmpChunkTask .ActiveAttempts , tmpChunkTask .TotalAttempts )
142- if updateAttemptsErr != nil {
143- log .Error ("failed to update chunk attempts" , "height" , getTaskParameter .ProverHeight , "err" , updateAttemptsErr )
144- return nil , ErrCoordinatorInternalFailure
145- }
143+ rowsAffected , updateAttemptsErr := cp .chunkOrm .UpdateChunkAttempts (ctx .Copy (), tmpChunkTask .Index , tmpChunkTask .ActiveAttempts , tmpChunkTask .TotalAttempts )
144+ if updateAttemptsErr != nil {
145+ log .Error ("failed to update chunk attempts" , "height" , getTaskParameter .ProverHeight , "err" , updateAttemptsErr )
146+ return nil , ErrCoordinatorInternalFailure
147+ }
146148
147- if rowsAffected == 0 {
148- time .Sleep (100 * time .Millisecond )
149- continue
149+ if rowsAffected == 0 {
150+ time .Sleep (100 * time .Millisecond )
151+ continue
152+ }
150153 }
151-
152154 chunkTask = tmpChunkTask
153155 break
154156 }
@@ -200,6 +202,11 @@ func (cp *ChunkProverTask) Assign(ctx *gin.Context, getTaskParameter *coordinato
200202 log .Error ("insert chunk prover task fail" , "task_id" , chunkTask .Hash , "publicKey" , taskCtx .PublicKey , "err" , err )
201203 return nil , ErrCoordinatorInternalFailure
202204 }
205+ } else {
206+ if err = cp .proverTaskOrm .UpdateProverTaskAssignedTime (ctx .Copy (), proverTask .UUID , utils .NowUTC ()); err != nil {
207+ log .Error ("update assigned chunk prover task fail" , "task_id" , chunkTask .Hash , "publicKey" , taskCtx .PublicKey , "err" , err )
208+ return nil , ErrCoordinatorInternalFailure
209+ }
203210 }
204211 // notice uuid is set as a side effect of InsertProverTask
205212 taskMsg .UUID = proverTask .UUID .String ()
0 commit comments