@@ -119,28 +119,42 @@ impl ProofAggregator {
119119 info ! ( "Starting proof aggregator service" ) ;
120120
121121 info ! ( "About to aggregate and submit proof to be verified on chain" ) ;
122- let res = self . aggregate_and_submit_proofs_on_chain ( ) . await ;
122+
123+ let ( proofs, tasks_id) = match self
124+ . fetcher
125+ . fetch_pending_proofs ( self . engine . clone ( ) , self . config . total_proofs_limit as i64 )
126+ . await
127+ . map_err ( AggregatedProofSubmissionError :: FetchingProofs )
128+ {
129+ Ok ( res) => res,
130+ Err ( e) => {
131+ error ! ( "Error while aggregating and submitting proofs: {:?}" , e) ;
132+ return ;
133+ }
134+ } ;
135+
136+ let res = self
137+ . aggregate_and_submit_proofs_on_chain ( ( proofs, & tasks_id) )
138+ . await ;
123139
124140 match res {
125141 Ok ( ( ) ) => {
126142 info ! ( "Process finished successfully" ) ;
127143 }
128144 Err ( err) => {
129145 error ! ( "Error while aggregating and submitting proofs: {:?}" , err) ;
146+ warn ! ( "Marking tasks back to pending after failure" ) ;
147+ if let Err ( e) = self . db . mark_tasks_as_pending ( & tasks_id) . await {
148+ error ! ( "Error while marking proofs to pending again: {:?}" , e) ;
149+ } ;
130150 }
131151 }
132152 }
133153
134- // TODO: on failure, mark proofs as pending again
135154 async fn aggregate_and_submit_proofs_on_chain (
136155 & mut self ,
156+ ( proofs, tasks_id) : ( Vec < AlignedProof > , & [ Uuid ] ) ,
137157 ) -> Result < ( ) , AggregatedProofSubmissionError > {
138- let ( proofs, tasks_id) = self
139- . fetcher
140- . fetch_pending_proofs ( self . engine . clone ( ) , self . config . total_proofs_limit as i64 )
141- . await
142- . map_err ( AggregatedProofSubmissionError :: FetchingProofs ) ?;
143-
144158 if proofs. is_empty ( ) {
145159 warn ! ( "No proofs collected, skipping aggregation..." ) ;
146160 return Ok ( ( ) ) ;
@@ -215,7 +229,7 @@ impl ProofAggregator {
215229
216230 info ! ( "Storing merkle paths for each task..." , ) ;
217231 let mut merkle_paths_for_tasks: Vec < ( Uuid , Vec < u8 > ) > = vec ! [ ] ;
218- for ( idx, task_id) in tasks_id. into_iter ( ) . enumerate ( ) {
232+ for ( idx, task_id) in tasks_id. iter ( ) . enumerate ( ) {
219233 let Some ( proof) = merkle_tree. get_proof_by_pos ( idx) else {
220234 warn ! ( "Proof not found for task id {task_id}" ) ;
221235 continue ;
@@ -226,7 +240,7 @@ impl ProofAggregator {
226240 . flat_map ( |e| e. to_vec ( ) )
227241 . collect :: < Vec < _ > > ( ) ;
228242
229- merkle_paths_for_tasks. push ( ( task_id, proof_bytes) )
243+ merkle_paths_for_tasks. push ( ( * task_id, proof_bytes) )
230244 }
231245 self . db
232246 . insert_tasks_merkle_path_and_mark_them_as_verified ( merkle_paths_for_tasks)
0 commit comments