@@ -4,12 +4,12 @@ use crate::{
4
4
api:: v3:: { ProofResponse , Status } ,
5
5
handler:: prove_many,
6
6
prove_aggregation,
7
- utils:: { is_zk_any_request, to_v3_status} ,
7
+ utils:: { draw_for_zk_any_batch_request , is_zk_any_request, to_v3_status} ,
8
8
} ,
9
9
} ;
10
10
use axum:: { extract:: State , routing:: post, Json , Router } ;
11
11
use raiko_core:: {
12
- interfaces:: { BatchMetadata , BatchProofRequest , BatchProofRequestOpt } ,
12
+ interfaces:: { BatchMetadata , BatchProofRequest , BatchProofRequestOpt , RaikoError } ,
13
13
merge,
14
14
} ;
15
15
use raiko_lib:: { proof_type:: ProofType , prover:: Proof } ;
@@ -41,20 +41,46 @@ async fn batch_handler(
41
41
State ( actor) : State < Actor > ,
42
42
Json ( batch_request_opt) : Json < Value > ,
43
43
) -> HostResult < Status > {
44
- if is_zk_any_request ( & batch_request_opt) {
45
- return Ok ( Status :: Ok {
46
- proof_type : ProofType :: Native ,
47
- data : ProofResponse :: Status {
48
- status : TaskStatus :: ZKAnyNotDrawn ,
49
- } ,
50
- } ) ;
51
- }
44
+ tracing:: debug!(
45
+ "Received batch request: {}" ,
46
+ serde_json:: to_string( & batch_request_opt) ?
47
+ ) ;
52
48
53
49
let batch_request = {
54
50
// Override the existing proof request config from the config file and command line
55
51
// options with the request from the client, and convert to a BatchProofRequest.
56
52
let mut opts = serde_json:: to_value ( actor. default_request_config ( ) ) ?;
57
53
merge ( & mut opts, & batch_request_opt) ;
54
+
55
+ let first_batch_id = {
56
+ let batches = opts[ "batches" ]
57
+ . as_array ( )
58
+ . ok_or ( RaikoError :: InvalidRequestConfig (
59
+ "Missing batches" . to_string ( ) ,
60
+ ) ) ?;
61
+ let first_batch = batches. first ( ) . ok_or ( RaikoError :: InvalidRequestConfig (
62
+ "batches is empty" . to_string ( ) ,
63
+ ) ) ?;
64
+ let first_batch_id = first_batch[ "batch_id" ] . as_u64 ( ) . expect ( "checked above" ) ;
65
+ first_batch_id
66
+ } ;
67
+
68
+ // For zk_any request, draw zk proof type based on the block hash.
69
+ if is_zk_any_request ( & opts) {
70
+ match draw_for_zk_any_batch_request ( & actor, & opts) . await ? {
71
+ Some ( proof_type) => opts[ "proof_type" ] = serde_json:: to_value ( proof_type) . unwrap ( ) ,
72
+ None => {
73
+ return Ok ( Status :: Ok {
74
+ proof_type : ProofType :: Native ,
75
+ batch_id : Some ( first_batch_id) ,
76
+ data : ProofResponse :: Status {
77
+ status : TaskStatus :: ZKAnyNotDrawn ,
78
+ } ,
79
+ } ) ;
80
+ }
81
+ }
82
+ }
83
+
58
84
let batch_request_opt: BatchProofRequestOpt = serde_json:: from_value ( opts) ?;
59
85
let batch_request: BatchProofRequest = batch_request_opt. try_into ( ) ?;
60
86
@@ -188,7 +214,12 @@ async fn batch_handler(
188
214
} )
189
215
}
190
216
} ;
191
- Ok ( to_v3_status ( batch_request. proof_type , result) )
217
+ tracing:: debug!( "Batch proof result: {}" , serde_json:: to_string( & result) ?) ;
218
+ Ok ( to_v3_status (
219
+ batch_request. proof_type ,
220
+ Some ( batch_request. batches . first ( ) . unwrap ( ) . batch_id ) ,
221
+ result,
222
+ ) )
192
223
}
193
224
194
225
#[ derive( OpenApi ) ]
0 commit comments