Skip to content

Commit

Permalink
fixup! fix: use NO_CONTENT instead of NOT_FOUND for no job
Browse files Browse the repository at this point in the history
Signed-off-by: Harald Hoyer <[email protected]>
  • Loading branch information
haraldh committed Oct 17, 2024
1 parent bf03aaf commit 1d1b243
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
19 changes: 6 additions & 13 deletions core/node/proof_data_handler/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use zksync_dal::DalError;
use zksync_object_store::ObjectStoreError;

pub(crate) enum RequestProcessorError {
NoJob,
GeneralError(String),
ObjectStore(ObjectStoreError),
Dal(DalError),
Expand All @@ -20,35 +19,29 @@ impl From<DalError> for RequestProcessorError {

impl IntoResponse for RequestProcessorError {
fn into_response(self) -> Response {
match self {
RequestProcessorError::GeneralError(err) => {
let (status_code, message) = match self {
Self::GeneralError(err) => {
tracing::error!("Error: {:?}", err);
(
StatusCode::INTERNAL_SERVER_ERROR,
"An internal error occurred".to_owned(),
)
.into_response()
}
RequestProcessorError::ObjectStore(err) => {
Self::ObjectStore(err) => {
tracing::error!("GCS error: {:?}", err);
(
StatusCode::BAD_GATEWAY,
"Failed fetching/saving from GCS".to_owned(),
)
.into_response()
}
RequestProcessorError::Dal(err) => {
Self::Dal(err) => {
tracing::error!("Sqlx error: {:?}", err);
(
StatusCode::BAD_GATEWAY,
"Failed fetching/saving from db".to_owned(),
)
.into_response()
}
RequestProcessorError::NoJob => {
tracing::trace!("No job found");
(StatusCode::NO_CONTENT, ()).into_response()
}
}
};
(status_code, message).into_response()
}
}
3 changes: 2 additions & 1 deletion core/node/proof_data_handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ fn create_proof_processing_router(
.await;

match result {
Ok(data) => (StatusCode::OK, data).into_response(),
Ok(Some(data)) => (StatusCode::OK, data).into_response(),
Ok(None) => { StatusCode::NO_CONTENT.into_response()},
Err(e) => e.into_response(),
}
},
Expand Down
15 changes: 9 additions & 6 deletions core/node/proof_data_handler/src/tee_request_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,27 @@ impl TeeRequestProcessor {
pub(crate) async fn get_proof_generation_data(
&self,
request: Json<TeeProofGenerationDataRequest>,
) -> Result<Json<TeeProofGenerationDataResponse>, RequestProcessorError> {
) -> Result<Option<Json<TeeProofGenerationDataResponse>>, RequestProcessorError> {
tracing::info!("Received request for proof generation data: {:?}", request);

let mut min_batch_number: Option<L1BatchNumber> = None;
let mut missing_range: Option<(L1BatchNumber, L1BatchNumber)> = None;

let result = loop {
let l1_batch_number = self
let Some(l1_batch_number) = self
.lock_batch_for_proving(request.tee_type, min_batch_number)
.await?;
.await?
else {
// No job available
return Ok(None);
};

match self
.tee_verifier_input_for_existing_batch(l1_batch_number)
.await
{
Ok(input) => {
break Ok(Json(TeeProofGenerationDataResponse(Box::new(input))));
break Ok(Some(Json(TeeProofGenerationDataResponse(Box::new(input)))));
}
Err(RequestProcessorError::ObjectStore(ObjectStoreError::KeyNotFound(_))) => {
missing_range = match missing_range {
Expand Down Expand Up @@ -152,7 +156,7 @@ impl TeeRequestProcessor {
&self,
tee_type: TeeType,
min_batch_number: Option<L1BatchNumber>,
) -> Result<L1BatchNumber, RequestProcessorError> {
) -> Result<Option<L1BatchNumber>, RequestProcessorError> {
self.pool
.connection_tagged("tee_request_processor")
.await?
Expand All @@ -164,7 +168,6 @@ impl TeeRequestProcessor {
)
.await
.map_err(RequestProcessorError::Dal)
.and_then(|batch_number| batch_number.ok_or(RequestProcessorError::NoJob))
}

async fn unlock_batch(
Expand Down

0 comments on commit 1d1b243

Please sign in to comment.