From 1d1b24316a0d24883cf4cba3b902f55f00516e8d Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 17 Oct 2024 09:14:47 +0200 Subject: [PATCH] fixup! fix: use NO_CONTENT instead of NOT_FOUND for no job Signed-off-by: Harald Hoyer --- core/node/proof_data_handler/src/errors.rs | 19 ++++++------------- core/node/proof_data_handler/src/lib.rs | 3 ++- .../src/tee_request_processor.rs | 15 +++++++++------ 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/core/node/proof_data_handler/src/errors.rs b/core/node/proof_data_handler/src/errors.rs index 00ba7a3c11cd..7d0e33ea0a3a 100644 --- a/core/node/proof_data_handler/src/errors.rs +++ b/core/node/proof_data_handler/src/errors.rs @@ -6,7 +6,6 @@ use zksync_dal::DalError; use zksync_object_store::ObjectStoreError; pub(crate) enum RequestProcessorError { - NoJob, GeneralError(String), ObjectStore(ObjectStoreError), Dal(DalError), @@ -20,35 +19,29 @@ impl From 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() } } diff --git a/core/node/proof_data_handler/src/lib.rs b/core/node/proof_data_handler/src/lib.rs index 2c6243fdb51c..a482a7bc07b2 100644 --- a/core/node/proof_data_handler/src/lib.rs +++ b/core/node/proof_data_handler/src/lib.rs @@ -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(), } }, diff --git a/core/node/proof_data_handler/src/tee_request_processor.rs b/core/node/proof_data_handler/src/tee_request_processor.rs index 8f10f573cd84..2c2a56300097 100644 --- a/core/node/proof_data_handler/src/tee_request_processor.rs +++ b/core/node/proof_data_handler/src/tee_request_processor.rs @@ -44,23 +44,27 @@ impl TeeRequestProcessor { pub(crate) async fn get_proof_generation_data( &self, request: Json, - ) -> Result, RequestProcessorError> { + ) -> Result>, RequestProcessorError> { tracing::info!("Received request for proof generation data: {:?}", request); let mut min_batch_number: Option = 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 { @@ -152,7 +156,7 @@ impl TeeRequestProcessor { &self, tee_type: TeeType, min_batch_number: Option, - ) -> Result { + ) -> Result, RequestProcessorError> { self.pool .connection_tagged("tee_request_processor") .await? @@ -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(