Skip to content

Commit 6d8ad35

Browse files
committed
feat(host): fill batch_id into response of batch-request
1 parent feb7df1 commit 6d8ad35

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

host/src/server/api/v2/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pub enum Status {
6969
Ok {
7070
#[serde(with = "raiko_lib::proof_type::lowercase")]
7171
proof_type: ProofType,
72+
#[serde(skip_serializing_if = "Option::is_none")]
73+
batch_id: Option<u64>,
7274
data: ProofResponse,
7375
},
7476
Error {

host/src/server/api/v2/proof/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ async fn proof_handler(
6161
None => {
6262
return Ok(Status::Ok {
6363
proof_type: ProofType::Native,
64+
batch_id: None,
6465
data: ProofResponse::Status {
6566
status: TaskStatus::ZKAnyNotDrawn,
6667
},
@@ -126,10 +127,10 @@ async fn proof_handler(
126127
.into();
127128

128129
let result = crate::server::prove(&actor, request_key, request_entity).await;
129-
Ok(to_v2_status(proof_type, result))
130+
Ok(to_v2_status(proof_type, None, result))
130131
}
131-
Ok(_) => Ok(to_v2_status(proof_type, result)),
132-
Err(_) => Ok(to_v2_status(proof_type, result)),
132+
Ok(_) => Ok(to_v2_status(proof_type, None, result)),
133+
Err(_) => Ok(to_v2_status(proof_type, None, result)),
133134
}
134135
}
135136

host/src/server/api/v3/proof/aggregate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async fn aggregation_handler(
6767
.into();
6868

6969
let result = crate::server::prove(&actor, agg_request_key, agg_request_entity).await;
70-
Ok(to_v3_status(proof_type, result))
70+
Ok(to_v3_status(proof_type, None, result))
7171
}
7272

7373
#[derive(OpenApi)]

host/src/server/api/v3/proof/batch.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
};
1212
use axum::{extract::State, routing::post, Json, Router};
1313
use raiko_core::{
14-
interfaces::{BatchMetadata, BatchProofRequest, BatchProofRequestOpt},
14+
interfaces::{BatchMetadata, BatchProofRequest, BatchProofRequestOpt, RaikoError},
1515
merge,
1616
};
1717
use raiko_lib::{proof_type::ProofType, prover::Proof};
@@ -58,13 +58,27 @@ async fn batch_handler(
5858
let mut opts = serde_json::to_value(actor.default_request_config())?;
5959
merge(&mut opts, &batch_request_opt);
6060

61+
let first_batch_id = {
62+
let batches = opts["batches"]
63+
.as_array()
64+
.ok_or(RaikoError::InvalidRequestConfig(
65+
"Missing batches".to_string(),
66+
))?;
67+
let first_batch = batches.first().ok_or(RaikoError::InvalidRequestConfig(
68+
"batches is empty".to_string(),
69+
))?;
70+
let first_batch_id = first_batch["batch_id"].as_u64().expect("checked above");
71+
first_batch_id
72+
};
73+
6174
// For zk_any request, draw zk proof type based on the block hash.
6275
if is_zk_any_request(&opts) {
6376
match draw_for_zk_any_batch_request(&actor, &opts).await? {
6477
Some(proof_type) => opts["proof_type"] = serde_json::to_value(proof_type).unwrap(),
6578
None => {
6679
return Ok(Status::Ok {
6780
proof_type: ProofType::Native,
81+
batch_id: Some(first_batch_id),
6882
data: ProofResponse::Status {
6983
status: TaskStatus::ZKAnyNotDrawn,
7084
},
@@ -207,7 +221,11 @@ async fn batch_handler(
207221
}
208222
};
209223
tracing::debug!("Batch proof result: {}", serde_json::to_string(&result)?);
210-
Ok(to_v3_status(batch_request.proof_type, result))
224+
Ok(to_v3_status(
225+
batch_request.proof_type,
226+
Some(batch_request.batches.first().unwrap().batch_id),
227+
result,
228+
))
211229
}
212230

213231
#[derive(OpenApi)]

host/src/server/api/v3/proof/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async fn proof_handler(
115115
sub_request_entities,
116116
)
117117
.await;
118-
Ok(to_v3_status(proof_type, result))
118+
Ok(to_v3_status(proof_type, None, result))
119119
}
120120

121121
#[derive(OpenApi)]

host/src/server/utils.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ use raiko_reqpool::Status;
99
use raiko_tasks::TaskStatus;
1010
use serde_json::Value;
1111

12-
pub fn to_v2_status(proof_type: ProofType, result: Result<Status, String>) -> v2::Status {
12+
pub fn to_v2_status(
13+
proof_type: ProofType,
14+
batch_id: Option<u64>,
15+
result: Result<Status, String>,
16+
) -> v2::Status {
1317
match result {
1418
Ok(status) => v2::Status::Ok {
1519
proof_type,
20+
batch_id,
1621
data: {
1722
match status {
1823
Status::Registered => v2::ProofResponse::Status {
@@ -57,8 +62,12 @@ pub fn to_v2_cancel_status(result: Result<Status, String>) -> v2::CancelStatus {
5762
}
5863

5964
// TODO: remove the staled interface
60-
pub fn to_v3_status(proof_type: ProofType, result: Result<Status, String>) -> v3::Status {
61-
to_v2_status(proof_type, result)
65+
pub fn to_v3_status(
66+
proof_type: ProofType,
67+
batch_id: Option<u64>,
68+
result: Result<Status, String>,
69+
) -> v3::Status {
70+
to_v2_status(proof_type, batch_id, result)
6271
}
6372

6473
pub fn to_v3_cancel_status(result: Result<Status, String>) -> v3::CancelStatus {

0 commit comments

Comments
 (0)