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

fix: Change no pending batches 404 error into a success response #279

Merged
merged 2 commits into from
Nov 29, 2023
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
2 changes: 1 addition & 1 deletion core/lib/types/src/prover_server_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct ProofGenerationDataRequest {}

#[derive(Debug, Serialize, Deserialize)]
pub enum ProofGenerationDataResponse {
Success(ProofGenerationData),
Success(Option<ProofGenerationData>),
Error(String),
}

Expand Down
19 changes: 10 additions & 9 deletions core/lib/zksync_core/src/proof_data_handler/request_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ pub(crate) struct RequestProcessor {
}

pub(crate) enum RequestProcessorError {
NoPendingBatches,
ObjectStore(ObjectStoreError),
Sqlx(SqlxError),
}

impl IntoResponse for RequestProcessorError {
fn into_response(self) -> Response {
let (status_code, message) = match self {
Self::NoPendingBatches => (
StatusCode::NOT_FOUND,
"No pending batches to process".to_owned(),
),
RequestProcessorError::ObjectStore(err) => {
tracing::error!("GCS error: {:?}", err);
(
Expand Down Expand Up @@ -88,15 +83,19 @@ impl RequestProcessor {
) -> Result<Json<ProofGenerationDataResponse>, RequestProcessorError> {
tracing::info!("Received request for proof generation data: {:?}", request);

let l1_batch_number = self
let l1_batch_number_result = self
.pool
.access_storage()
.await
.unwrap()
.proof_generation_dal()
.get_next_block_to_be_proven(self.config.proof_generation_timeout())
.await
.ok_or(RequestProcessorError::NoPendingBatches)?;
.await;

let l1_batch_number = match l1_batch_number_result {
Some(number) => number,
None => return Ok(Json(ProofGenerationDataResponse::Success(None))), // no batches pending to be proven
};

let blob = self
.blob_store
Expand Down Expand Up @@ -125,7 +124,9 @@ impl RequestProcessor {
l1_verifier_config,
};

Ok(Json(ProofGenerationDataResponse::Success(proof_gen_data)))
Ok(Json(ProofGenerationDataResponse::Success(Some(
proof_gen_data,
))))
}

pub(crate) async fn submit_proof(
Expand Down
1 change: 1 addition & 0 deletions prover/prover_fri_gateway/src/api_data_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl PeriodicApiStruct {
Resp: DeserializeOwned,
{
tracing::info!("Sending request to {}", endpoint);

self.client
.post(endpoint)
.json(&request)
Expand Down
6 changes: 5 additions & 1 deletion prover/prover_fri_gateway/src/proof_gen_data_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl PeriodicApiStruct {
impl PeriodicApi<ProofGenerationDataRequest> for PeriodicApiStruct {
type JobId = ();
type Response = ProofGenerationDataResponse;

const SERVICE_NAME: &'static str = "ProofGenDataFetcher";

async fn get_next_request(&self) -> Option<(Self::JobId, ProofGenerationDataRequest)> {
Expand All @@ -49,7 +50,10 @@ impl PeriodicApi<ProofGenerationDataRequest> for PeriodicApiStruct {

async fn handle_response(&self, _: (), response: Self::Response) {
match response {
ProofGenerationDataResponse::Success(data) => {
ProofGenerationDataResponse::Success(None) => {
tracing::info!("There are currently no pending batches to be proven");
}
ProofGenerationDataResponse::Success(Some(data)) => {
tracing::info!("Received proof gen data for: {:?}", data.l1_batch_number);
self.save_proof_gen_data(data).await;
}
Expand Down
Loading