Skip to content

Commit beb3eef

Browse files
committed
fix: use NO_CONTENT instead of NOT_FOUND for no job
Signed-off-by: Harald Hoyer <harald@matterlabs.dev>
1 parent c3d0833 commit beb3eef

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

core/bin/zksync_tee_prover/src/api_client.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use reqwest::Client;
1+
use reqwest::{Client, Response, StatusCode};
22
use secp256k1::{ecdsa::Signature, PublicKey};
3-
use serde::{de::DeserializeOwned, Serialize};
3+
use serde::Serialize;
44
use url::Url;
55
use zksync_basic_types::H256;
66
use zksync_prover_interface::{
7-
api::{
8-
RegisterTeeAttestationRequest, RegisterTeeAttestationResponse, SubmitTeeProofRequest,
9-
SubmitTeeProofResponse, TeeProofGenerationDataRequest, TeeProofGenerationDataResponse,
10-
},
7+
api::{RegisterTeeAttestationRequest, SubmitTeeProofRequest, TeeProofGenerationDataRequest},
118
inputs::TeeVerifierInput,
129
outputs::L1BatchTeeProofForL1,
1310
};
@@ -31,10 +28,9 @@ impl TeeApiClient {
3128
}
3229
}
3330

34-
async fn post<Req, Resp, S>(&self, endpoint: S, request: Req) -> Result<Resp, reqwest::Error>
31+
async fn post<Req, S>(&self, endpoint: S, request: Req) -> Result<Response, reqwest::Error>
3532
where
3633
Req: Serialize + std::fmt::Debug,
37-
Resp: DeserializeOwned,
3834
S: AsRef<str>,
3935
{
4036
let url = self.api_base_url.join(endpoint.as_ref()).unwrap();
@@ -46,9 +42,7 @@ impl TeeApiClient {
4642
.json(&request)
4743
.send()
4844
.await?
49-
.error_for_status()?
50-
.json::<Resp>()
51-
.await
45+
.error_for_status()
5246
}
5347

5448
/// Registers the attestation quote with the TEE prover interface API, effectively proving that
@@ -63,8 +57,7 @@ impl TeeApiClient {
6357
attestation: attestation_quote_bytes,
6458
pubkey: public_key.serialize().to_vec(),
6559
};
66-
self.post::<_, RegisterTeeAttestationResponse, _>("/tee/register_attestation", request)
67-
.await?;
60+
self.post("/tee/register_attestation", request).await?;
6861
tracing::info!(
6962
"Attestation quote was successfully registered for the public key {}",
7063
public_key
@@ -77,12 +70,17 @@ impl TeeApiClient {
7770
pub async fn get_job(
7871
&self,
7972
tee_type: TeeType,
80-
) -> Result<Box<TeeVerifierInput>, TeeProverError> {
73+
) -> Result<Option<TeeVerifierInput>, TeeProverError> {
8174
let request = TeeProofGenerationDataRequest { tee_type };
82-
let response = self
83-
.post::<_, TeeProofGenerationDataResponse, _>("/tee/proof_inputs", request)
84-
.await?;
85-
Ok(response.0)
75+
let response = self.post("/tee/proof_inputs", request).await?;
76+
match response.status() {
77+
StatusCode::OK => Ok(Some(response.json::<TeeVerifierInput>().await?)),
78+
StatusCode::NO_CONTENT => Ok(None),
79+
_ => response
80+
.json::<Option<TeeVerifierInput>>()
81+
.await
82+
.map_err(TeeProverError::Request),
83+
}
8684
}
8785

8886
/// Submits the successfully verified proof to the TEE prover interface API.
@@ -101,7 +99,7 @@ impl TeeApiClient {
10199
tee_type,
102100
}));
103101
let observer = METRICS.proof_submitting_time.start();
104-
self.post::<_, SubmitTeeProofResponse, _>(
102+
self.post(
105103
format!("/tee/submit_proofs/{batch_number}").as_str(),
106104
request,
107105
)

core/bin/zksync_tee_prover/src/tee_prover.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fmt;
22

3-
use reqwest::StatusCode;
43
use secp256k1::{ecdsa::Signature, Message, PublicKey, Secp256k1};
54
use zksync_basic_types::H256;
65
use zksync_node_framework::{
@@ -92,8 +91,8 @@ impl TeeProver {
9291

9392
async fn step(&self, public_key: &PublicKey) -> Result<Option<L1BatchNumber>, TeeProverError> {
9493
match self.api_client.get_job(self.config.tee_type).await {
95-
Ok(job) => {
96-
let (signature, batch_number, root_hash) = self.verify(*job)?;
94+
Ok(Some(job)) => {
95+
let (signature, batch_number, root_hash) = self.verify(job)?;
9796
self.api_client
9897
.submit_proof(
9998
batch_number,
@@ -105,15 +104,11 @@ impl TeeProver {
105104
.await?;
106105
Ok(Some(batch_number))
107106
}
108-
Err(err) => match err {
109-
TeeProverError::Request(req_err)
110-
if req_err.status() == Some(StatusCode::NOT_FOUND) =>
111-
{
112-
tracing::trace!("There are currently no pending batches to be proven");
113-
Ok(None)
114-
}
115-
_ => Err(err),
116-
},
107+
Ok(None) => {
108+
tracing::trace!("There are currently no pending batches to be proven");
109+
Ok(None)
110+
}
111+
Err(err) => Err(err),
117112
}
118113
}
119114
}

core/node/proof_data_handler/src/errors.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,35 @@ impl From<DalError> for RequestProcessorError {
2020

2121
impl IntoResponse for RequestProcessorError {
2222
fn into_response(self) -> Response {
23-
let (status_code, message) = match self {
23+
match self {
2424
RequestProcessorError::GeneralError(err) => {
2525
tracing::error!("Error: {:?}", err);
2626
(
2727
StatusCode::INTERNAL_SERVER_ERROR,
2828
"An internal error occurred".to_owned(),
2929
)
30+
.into_response()
3031
}
3132
RequestProcessorError::ObjectStore(err) => {
3233
tracing::error!("GCS error: {:?}", err);
3334
(
3435
StatusCode::BAD_GATEWAY,
3536
"Failed fetching/saving from GCS".to_owned(),
3637
)
38+
.into_response()
3739
}
3840
RequestProcessorError::Dal(err) => {
3941
tracing::error!("Sqlx error: {:?}", err);
4042
(
4143
StatusCode::BAD_GATEWAY,
4244
"Failed fetching/saving from db".to_owned(),
4345
)
46+
.into_response()
4447
}
4548
RequestProcessorError::NoJob => {
4649
tracing::trace!("No job found");
47-
(StatusCode::NOT_FOUND, "No job found".to_owned())
50+
(StatusCode::NO_CONTENT, ()).into_response()
4851
}
49-
};
50-
(status_code, message).into_response()
52+
}
5153
}
5254
}

0 commit comments

Comments
 (0)