@@ -3,7 +3,7 @@ package api
33import (
44 "errors"
55 "fmt"
6- "math/rand "
6+ "sort "
77
88 "github.com/gin-gonic/gin"
99 "github.com/prometheus/client_golang/prometheus"
@@ -79,7 +79,9 @@ func (ptc *GetTaskController) incGetTaskAccessCounter(ctx *gin.Context) error {
7979 return nil
8080}
8181
82- // GetTasks get assigned chunk/batch task
82+ // GetTasks get assigned chunk/batch/bundle task, trying proof types in priority
83+ // order: Bundle > Batch > Chunk. This lets the pipeline finalize the earliest
84+ // ready bundle before proving unrelated chunks/batches further ahead.
8385func (ptc * GetTaskController ) GetTasks (ctx * gin.Context ) {
8486 var getTaskParameter coordinatorType.GetTaskParameter
8587 if err := ctx .ShouldBind (& getTaskParameter ); err != nil {
@@ -99,35 +101,36 @@ func (ptc *GetTaskController) GetTasks(ctx *gin.Context) {
99101 }
100102 }
101103
102- proofType := ptc .proofType (& getTaskParameter )
103- proverTask , isExist := ptc .proverTasks [proofType ]
104- if ! isExist {
105- nerr := fmt .Errorf ("parameter wrong proof type:%v" , proofType )
106- types .RenderFailure (ctx , types .ErrCoordinatorParameterInvalidNo , nerr )
107- return
108- }
104+ proofTypes := ptc .prioritizedProofTypes (& getTaskParameter )
109105
110106 if err := ptc .incGetTaskAccessCounter (ctx ); err != nil {
111107 log .Warn ("get_task access counter inc failed" , "error" , err .Error ())
112108 }
113109
114- result , err := proverTask .Assign (ctx , & getTaskParameter )
115- if err != nil {
116- nerr := fmt .Errorf ("return prover task err:%w" , err )
117- types .RenderFailure (ctx , types .ErrCoordinatorGetTaskFailure , nerr )
118- return
119- }
110+ for _ , proofType := range proofTypes {
111+ proverTask , isExist := ptc .proverTasks [proofType ]
112+ if ! isExist {
113+ continue
114+ }
120115
121- if result == nil {
122- nerr := errors .New ("get empty prover task" )
123- types .RenderFailure (ctx , types .ErrCoordinatorEmptyProofData , nerr )
124- return
116+ result , err := proverTask .Assign (ctx , & getTaskParameter )
117+ if err != nil {
118+ nerr := fmt .Errorf ("return prover task err:%w" , err )
119+ types .RenderFailure (ctx , types .ErrCoordinatorGetTaskFailure , nerr )
120+ return
121+ }
122+
123+ if result != nil {
124+ types .RenderSuccess (ctx , result )
125+ return
126+ }
125127 }
126128
127- types .RenderSuccess (ctx , result )
129+ nerr := errors .New ("get empty prover task" )
130+ types .RenderFailure (ctx , types .ErrCoordinatorEmptyProofData , nerr )
128131}
129132
130- func (ptc * GetTaskController ) proofType (para * coordinatorType.GetTaskParameter ) message.ProofType {
133+ func (ptc * GetTaskController ) prioritizedProofTypes (para * coordinatorType.GetTaskParameter ) [] message.ProofType {
131134 var proofTypes []message.ProofType
132135 for _ , proofType := range para .TaskTypes {
133136 proofTypes = append (proofTypes , message .ProofType (proofType ))
@@ -141,8 +144,9 @@ func (ptc *GetTaskController) proofType(para *coordinatorType.GetTaskParameter)
141144 }
142145 }
143146
144- rand .Shuffle (len (proofTypes ), func (i , j int ) {
145- proofTypes [i ], proofTypes [j ] = proofTypes [j ], proofTypes [i ]
147+ // Bundle (3) > Batch (2) > Chunk (1)
148+ sort .Slice (proofTypes , func (i , j int ) bool {
149+ return proofTypes [i ] > proofTypes [j ]
146150 })
147- return proofTypes [ 0 ]
151+ return proofTypes
148152}
0 commit comments