Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(proof-data-handler): return 204 HTTP status code if no proofs are available #3037

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions core/lib/dal/src/tee_proof_generation_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,38 +196,6 @@ impl TeeProofGenerationDal<'_, '_> {
Ok(())
}

pub async fn insert_tee_proof_generation_job(
&mut self,
batch_number: L1BatchNumber,
tee_type: TeeType,
) -> DalResult<()> {
let batch_number = i64::from(batch_number.0);
let query = sqlx::query!(
r#"
INSERT INTO
tee_proof_generation_details (
l1_batch_number, tee_type, status, created_at, updated_at
)
VALUES
($1, $2, $3, NOW(), NOW())
ON CONFLICT (l1_batch_number, tee_type) DO NOTHING
"#,
batch_number,
tee_type.to_string(),
TeeProofGenerationJobStatus::Unpicked.to_string(),
);
let instrumentation = Instrumented::new("insert_tee_proof_generation_job")
.with_arg("l1_batch_number", &batch_number)
.with_arg("tee_type", &tee_type);
instrumentation
.clone()
.with(query)
.execute(self.storage)
.await?;

Ok(())
}

pub async fn save_attestation(&mut self, pubkey: &[u8], attestation: &[u8]) -> DalResult<()> {
let query = sqlx::query!(
r#"
Expand Down Expand Up @@ -291,6 +259,40 @@ impl TeeProofGenerationDal<'_, '_> {
Ok(proofs)
}

/// For testing purposes only.
pub async fn insert_tee_proof_generation_job(
&mut self,
batch_number: L1BatchNumber,
tee_type: TeeType,
) -> DalResult<()> {
let batch_number = i64::from(batch_number.0);
let query = sqlx::query!(
r#"
INSERT INTO
tee_proof_generation_details (
l1_batch_number, tee_type, status, created_at, updated_at
)
VALUES
($1, $2, $3, NOW(), NOW())
ON CONFLICT (l1_batch_number, tee_type) DO NOTHING
"#,
batch_number,
tee_type.to_string(),
TeeProofGenerationJobStatus::Unpicked.to_string(),
);
let instrumentation = Instrumented::new("insert_tee_proof_generation_job")
.with_arg("l1_batch_number", &batch_number)
.with_arg("tee_type", &tee_type);
instrumentation
.clone()
.with(query)
.execute(self.storage)
.await?;

Ok(())
}

/// For testing purposes only.
pub async fn get_oldest_unpicked_batch(&mut self) -> DalResult<Option<L1BatchNumber>> {
let query = sqlx::query!(
r#"
Expand Down
14 changes: 10 additions & 4 deletions core/node/proof_data_handler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{net::SocketAddr, sync::Arc};

use anyhow::Context as _;
use axum::{extract::Path, routing::post, Json, Router};
use axum::{extract::Path, http::StatusCode, response::IntoResponse, routing::post, Json, Router};
use request_processor::RequestProcessor;
use tee_request_processor::TeeRequestProcessor;
use tokio::sync::watch;
Expand All @@ -10,7 +10,7 @@ use zksync_dal::{ConnectionPool, Core};
use zksync_object_store::ObjectStore;
use zksync_prover_interface::api::{
ProofGenerationDataRequest, RegisterTeeAttestationRequest, SubmitProofRequest,
SubmitTeeProofRequest, TeeProofGenerationDataRequest,
SubmitTeeProofRequest, TeeProofGenerationDataRequest, TeeProofGenerationDataResponse,
};
use zksync_types::commitment::L1BatchCommitmentMode;

Expand Down Expand Up @@ -96,9 +96,15 @@ fn create_proof_processing_router(
"/tee/proof_inputs",
post(
move |payload: Json<TeeProofGenerationDataRequest>| async move {
get_tee_proof_gen_processor
let result: Result<Json<zksync_prover_interface::api::TeeProofGenerationDataResponse>, errors::RequestProcessorError> = get_tee_proof_gen_processor
.get_proof_generation_data(payload)
.await
.await;

match result {
Ok(Json(TeeProofGenerationDataResponse(None))) => (StatusCode::NO_CONTENT, Json("No new TeeVerifierInputs are available yet")).into_response(),
Ok(data) => (StatusCode::OK, data).into_response(),
Err(e) => e.into_response(),
}
},
),
)
Expand Down
4 changes: 3 additions & 1 deletion core/node/proof_data_handler/src/tee_request_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ impl TeeRequestProcessor {
.tee_verifier_input_for_existing_batch(l1_batch_number)
.await
{
Ok(input) => break Ok(Json(TeeProofGenerationDataResponse(Some(Box::new(input))))),
Ok(input) => {
break Ok(Json(TeeProofGenerationDataResponse(Some(Box::new(input)))));
}
Err(RequestProcessorError::ObjectStore(ObjectStoreError::KeyNotFound(_))) => {
missing_range = match missing_range {
Some((start, _)) => Some((start, l1_batch_number)),
Expand Down
7 changes: 2 additions & 5 deletions core/node/proof_data_handler/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ use crate::create_proof_processing_router;

#[tokio::test]
async fn request_tee_proof_inputs() {
let batch_number = L1BatchNumber::from(1);
let db_conn_pool = ConnectionPool::test_pool().await;

mock_tee_batch_status(db_conn_pool.clone(), batch_number).await;

let app = create_proof_processing_router(
MockObjectStore::arc(),
db_conn_pool,
db_conn_pool.clone(),
ProofDataHandlerConfig {
http_port: 1337,
proof_generation_timeout_in_secs: 10,
Expand All @@ -32,7 +29,7 @@ async fn request_tee_proof_inputs() {
L1BatchCommitmentMode::Rollup,
);
let test_cases = vec![
(json!({ "tee_type": "sgx" }), StatusCode::OK),
(json!({ "tee_type": "sgx" }), StatusCode::NO_CONTENT),
(
json!({ "tee_type": "Sgx" }),
StatusCode::UNPROCESSABLE_ENTITY,
Expand Down
Loading