Skip to content

Commit

Permalink
fix pending batches 404
Browse files Browse the repository at this point in the history
  • Loading branch information
igamigo committed Oct 20, 2023
1 parent 71ffe99 commit dcdc21a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
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
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -104,4 +105,4 @@ pub(crate) trait PeriodicApi<Req: Send>: Sync + Send {
) -> reqwest::Result<Self::Response>;

async fn handle_response(&self, job_id: Self::JobId, response: Self::Response);
}
}
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

0 comments on commit dcdc21a

Please sign in to comment.