@@ -95,49 +95,14 @@ impl Backend {
9595 let handle = tokio:: spawn ( async move {
9696 let _permit = permit;
9797
98- let result = match request_entity {
99- RequestEntity :: SingleProof ( _)
100- | RequestEntity :: Aggregation ( _)
101- | RequestEntity :: BatchProof ( _)
102- | RequestEntity :: GuestInput ( _)
103- | RequestEntity :: BatchGuestInput ( _) => Err (
104- "legacy single-block and batch proving are removed; use Shasta only"
105- . to_string ( ) ,
106- ) ,
107- RequestEntity :: ShastaGuestInput ( entity) => {
108- do_generate_shasta_proposal_guest_input (
109- & mut pool_,
110- & chain_specs,
111- request_key_. clone ( ) ,
112- entity,
113- )
114- . await
115- }
116- RequestEntity :: ShastaProof ( entity) => {
117- do_prove_shasta_proposal (
118- & mut pool_,
119- & chain_specs,
120- request_key_. clone ( ) ,
121- entity,
122- )
123- . await
124- }
125- RequestEntity :: ShastaAggregation ( entity) => {
126- do_shasta_aggregation ( & mut pool_, request_key_. clone ( ) , entity) . await
127- }
128- } ;
129- let status = match result {
130- Ok ( proof) => {
131- let proof_str = format ! ( "{}" , proof) ;
132- tracing:: info!(
133- "Actor Backend successfully proved {request_key_}. Proof: {proof_str}"
134- ) ;
135- Status :: Success { proof }
136- }
137- Err ( e) => Status :: Failed {
138- error : e. to_string ( ) ,
139- } ,
140- } ;
98+ let result = dispatch_proof_request (
99+ & mut pool_,
100+ & chain_specs,
101+ request_key_. clone ( ) ,
102+ request_entity,
103+ )
104+ . await ;
105+ let status = result_to_status ( & result, & request_key_) ;
141106 let _ = pool_. update_status (
142107 request_key_. clone ( ) ,
143108 StatusWithContext :: new ( status, chrono:: Utc :: now ( ) ) ,
@@ -151,19 +116,62 @@ impl Backend {
151116 tokio:: spawn ( async move {
152117 if let Err ( e) = handle. await {
153118 tracing:: error!( "Actor thread errored while proving {request_key}: {e:?}" ) ;
154- let status = Status :: Failed {
155- error : e. to_string ( ) ,
156- } ;
157- let _ = pool_. update_status ( request_key. clone ( ) , status. clone ( ) . into ( ) ) ;
119+ let status =
120+ StatusWithContext :: new ( Status :: Failed { error : e. to_string ( ) } , chrono:: Utc :: now ( ) ) ;
121+ let _ = pool_. update_status ( request_key. clone ( ) , status) ;
158122 }
159-
160- let _res = done_tx_. send ( request_key. clone ( ) ) . await ;
123+ let _ = done_tx_. send ( request_key) . await ;
161124 notifier_. notify_one ( ) ;
162125 } ) ;
163126 }
164127 }
165128}
166129
130+ /// Dispatches the request to the appropriate proof handler.
131+ async fn dispatch_proof_request (
132+ pool : & mut Pool ,
133+ chain_specs : & SupportedChainSpecs ,
134+ request_key : RequestKey ,
135+ request_entity : RequestEntity ,
136+ ) -> Result < raiko_lib:: prover:: Proof , String > {
137+ match request_entity {
138+ RequestEntity :: SingleProof ( _)
139+ | RequestEntity :: Aggregation ( _)
140+ | RequestEntity :: BatchProof ( _)
141+ | RequestEntity :: GuestInput ( _)
142+ | RequestEntity :: BatchGuestInput ( _) => Err (
143+ "legacy single-block and batch proving are removed; use Shasta only" . to_string ( ) ,
144+ ) ,
145+ RequestEntity :: ShastaGuestInput ( entity) => {
146+ do_generate_shasta_proposal_guest_input ( pool, chain_specs, request_key, entity) . await
147+ }
148+ RequestEntity :: ShastaProof ( entity) => {
149+ do_prove_shasta_proposal ( pool, chain_specs, request_key, entity) . await
150+ }
151+ RequestEntity :: ShastaAggregation ( entity) => {
152+ do_shasta_aggregation ( pool, request_key, entity) . await
153+ }
154+ }
155+ }
156+
157+ /// Converts proof result to pool status.
158+ fn result_to_status (
159+ result : & Result < raiko_lib:: prover:: Proof , String > ,
160+ request_key : & RequestKey ,
161+ ) -> Status {
162+ match result {
163+ Ok ( proof) => {
164+ tracing:: info!( "Actor Backend successfully proved {request_key}. Proof: {proof}" ) ;
165+ Status :: Success {
166+ proof : proof. clone ( ) ,
167+ }
168+ }
169+ Err ( e) => Status :: Failed {
170+ error : e. clone ( ) ,
171+ } ,
172+ }
173+ }
174+
167175async fn do_shasta_aggregation (
168176 pool : & mut dyn IdWrite ,
169177 request_key : RequestKey ,
0 commit comments