@@ -112,68 +112,67 @@ async fn shasta_batch_handler(
112112 sub_batch_ids,
113113 ) = process_shasta_batch ( & shasta_request, & image_id) ;
114114
115- let result = if shasta_request. aggregate {
116- prove_aggregation (
117- & actor,
118- RequestKey :: ShastaAggregation ( AggregationRequestKey :: new_with_image_id (
119- shasta_request. proof_type ,
120- sub_batch_ids. clone ( ) ,
121- image_id. clone ( ) ,
122- ) ) ,
123- RequestEntity :: ShastaAggregation ( AggregationRequestEntity :: new (
124- sub_batch_ids,
125- vec ! [ ] ,
126- shasta_request. proof_type ,
127- shasta_request. prover_args . clone ( ) ,
128- ) ) ,
129- sub_request_keys,
130- sub_request_entities,
131- )
132- . await
115+ // Run input step first to reuse cached guest input (both aggregate and non-aggregate)
116+ let statuses =
117+ prove_many ( & actor, sub_input_request_keys, sub_input_request_entities) . await ?;
118+ let is_all_sub_success = statuses
119+ . iter ( )
120+ . all ( |status| matches ! ( status, raiko_reqpool:: Status :: Success { .. } ) ) ;
121+ let result = if !is_all_sub_success {
122+ Ok ( raiko_reqpool:: Status :: Registered )
133123 } else {
134- let statuses =
135- prove_many ( & actor, sub_input_request_keys, sub_input_request_entities) . await ?;
136- let is_all_sub_success = statuses
124+ let guest_inputs: Vec < _ > = statuses
137125 . iter ( )
138- . all ( |status| matches ! ( status, raiko_reqpool:: Status :: Success { .. } ) ) ;
139- if !is_all_sub_success {
140- Ok ( raiko_reqpool:: Status :: Registered )
126+ . map ( |s| match s {
127+ raiko_reqpool:: Status :: Success { proof, .. } => proof. proof . clone ( ) . unwrap ( ) ,
128+ _ => unreachable ! ( ) ,
129+ } )
130+ . collect ( ) ;
131+ let sub_request_entities_with_input: Vec < _ > = sub_request_entities
132+ . iter ( )
133+ . zip ( guest_inputs)
134+ . map ( |( entity, guest_input) | match entity {
135+ raiko_reqpool:: RequestEntity :: ShastaProof ( e) => {
136+ let mut prover_args = e. prover_args ( ) . clone ( ) ;
137+ prover_args. insert (
138+ PROVER_ARG_SHASTA_GUEST_INPUT . to_string ( ) ,
139+ encode_guest_input_str_to_prover_arg_value ( & guest_input) . expect ( "wrap" ) ,
140+ ) ;
141+ ShastaProofRequestEntity :: new_with_guest_input_entity (
142+ e. guest_input_entity ( ) . clone ( ) ,
143+ * e. proof_type ( ) ,
144+ prover_args,
145+ )
146+ . into ( )
147+ }
148+ _ => unreachable ! ( ) ,
149+ } )
150+ . collect ( ) ;
151+
152+ if shasta_request. aggregate {
153+ prove_aggregation (
154+ & actor,
155+ RequestKey :: ShastaAggregation ( AggregationRequestKey :: new_with_image_id_and_prover (
156+ shasta_request. proof_type ,
157+ sub_batch_ids. clone ( ) ,
158+ image_id. clone ( ) ,
159+ shasta_request. prover . to_string ( ) ,
160+ ) ) ,
161+ RequestEntity :: ShastaAggregation ( AggregationRequestEntity :: new (
162+ sub_batch_ids,
163+ vec ! [ ] ,
164+ shasta_request. proof_type ,
165+ shasta_request. prover_args . clone ( ) ,
166+ ) ) ,
167+ sub_request_keys,
168+ sub_request_entities_with_input,
169+ )
170+ . await
141171 } else {
142- let guest_inputs_of_entities = statuses
143- . iter ( )
144- . map ( |status| match status {
145- // get saved guest input and pass down to real prover
146- raiko_reqpool:: Status :: Success { proof, .. } => proof. proof . clone ( ) . unwrap ( ) ,
147- _ => unreachable ! ( "is_all_sub_success checked" ) ,
148- } )
149- . collect :: < Vec < _ > > ( ) ;
150- let sub_request_entities = sub_request_entities
151- . iter ( )
152- . zip ( guest_inputs_of_entities)
153- . to_owned ( )
154- . map ( |( entity, guest_input) | match entity {
155- raiko_reqpool:: RequestEntity :: ShastaProof ( request_entity) => {
156- let mut prover_args = request_entity. prover_args ( ) . clone ( ) ;
157- prover_args. insert (
158- PROVER_ARG_SHASTA_GUEST_INPUT . to_string ( ) ,
159- encode_guest_input_str_to_prover_arg_value ( & guest_input)
160- . expect ( "failed to wrap shasta_guest_input string" ) ,
161- ) ;
162- ShastaProofRequestEntity :: new_with_guest_input_entity (
163- request_entity. guest_input_entity ( ) . clone ( ) ,
164- * request_entity. proof_type ( ) ,
165- prover_args,
166- )
167- . into ( )
168- }
169- _ => unreachable ! ( "Invalid request entity" ) ,
170- } )
171- . collect :: < Vec < _ > > ( ) ;
172- prove_many ( & actor, sub_request_keys, sub_request_entities)
172+ prove_many ( & actor, sub_request_keys, sub_request_entities_with_input)
173173 . await
174- . map ( |statuses| {
175- statuses
176- . into_iter ( )
174+ . map ( |s| {
175+ s. into_iter ( )
177176 . next ( )
178177 . unwrap_or_else ( || raiko_reqpool:: Status :: Failed {
179178 error : "No status returned" . to_string ( ) ,
0 commit comments