Skip to content

Commit

Permalink
Merge branch 'develop' into feat-envvar-for-rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
Thegaram authored Aug 22, 2024
2 parents 48aad34 + 517469a commit ad96e25
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
2 changes: 2 additions & 0 deletions prover/src/coordinator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use types::*;

use crate::{config::Config, key_signer::KeySigner};

pub use errors::ProofStatusNotOKError;

pub struct CoordinatorClient<'a> {
api: Api,
token: Option<String>,
Expand Down
22 changes: 20 additions & 2 deletions prover/src/coordinator_client/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::types::*;
use crate::{coordinator_client::ProofStatusNotOKError, types::ProofStatus};

use super::{errors::*, types::*};
use anyhow::{bail, Result};
use core::time::Duration;
use reqwest::{header::CONTENT_TYPE, Url};
Expand Down Expand Up @@ -76,7 +78,23 @@ impl Api {
token: &String,
) -> Result<Response<SubmitProofResponseData>> {
let method = "/coordinator/v1/submit_proof";
self.post_with_token(method, req, token).await
let response = self
.post_with_token::<SubmitProofRequest, Response<SubmitProofResponseData>>(
method, req, token,
)
.await?;

// when req's status already not ok, we mark the error returned from coordinator and will
// ignore it later.
if response.errcode == ErrorCode::ErrCoordinatorHandleZkProofFailure
&& req.status != ProofStatus::Ok
&& response
.errmsg
.contains("validator failure proof msg status not ok")
{
return Err(anyhow::anyhow!(ProofStatusNotOKError));
}
Ok(response)
}

async fn post_with_token<Req, Resp>(
Expand Down
12 changes: 12 additions & 0 deletions prover/src/coordinator_client/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::{Deserialize, Deserializer};
use std::fmt;

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ErrorCode {
Expand Down Expand Up @@ -51,3 +52,14 @@ impl<'de> Deserialize<'de> for ErrorCode {
Ok(ErrorCode::from_i32(v))
}
}

// ====================================================

#[derive(Debug, Clone)]
pub struct ProofStatusNotOKError;

impl fmt::Display for ProofStatusNotOKError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "proof status not ok")
}
}
9 changes: 8 additions & 1 deletion prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Args {
log_file: Option<String>,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
fn start() -> Result<()> {
let args = Args::parse();

if args.version {
Expand Down Expand Up @@ -76,3 +76,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

fn main() {
let result = start();
if let Err(e) = result {
log::error!("main exit with error {:#}", e)
}
}
25 changes: 18 additions & 7 deletions prover/src/task_processor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{prover::Prover, task_cache::TaskCache};
use super::{coordinator_client::ProofStatusNotOKError, prover::Prover, task_cache::TaskCache};
use anyhow::{Context, Result};
use std::rc::Rc;

Expand All @@ -16,7 +16,11 @@ impl<'a> TaskProcessor<'a> {
loop {
log::info!("start a new round.");
if let Err(err) = self.prove_and_submit() {
log::error!("encounter error: {:#}", err);
if err.is::<ProofStatusNotOKError>() {
log::info!("proof status not ok, downgrade level to info.");
} else {
log::error!("encounter error: {:#}", err);
}
} else {
log::info!("prove & submit succeed.");
}
Expand Down Expand Up @@ -54,11 +58,18 @@ impl<'a> TaskProcessor<'a> {
);
let result = match self.prover.prove_task(&task_wrapper.task) {
Ok(proof_detail) => self.prover.submit_proof(proof_detail, &task_wrapper.task),
Err(error) => self.prover.submit_error(
&task_wrapper.task,
super::types::ProofFailureType::NoPanic,
error,
),
Err(error) => {
log::error!(
"failed to prove task, id: {}, error: {:#}",
&task_wrapper.task.id,
error
);
self.prover.submit_error(
&task_wrapper.task,
super::types::ProofFailureType::NoPanic,
error,
)
}
};
return result;
}
Expand Down
2 changes: 0 additions & 2 deletions prover/src/zk_circuits_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl<'a> CircuitsHandlerProvider<'a> {
if let Some(handler) = &self.current_circuit {
Ok(handler.clone())
} else {
log::error!("missing cached handler, there must be something wrong.");
bail!("missing cached handler, there must be something wrong.")
}
}
Expand All @@ -136,7 +135,6 @@ impl<'a> CircuitsHandlerProvider<'a> {
self.current_circuit = Some(rc_handler.clone());
Ok(rc_handler)
} else {
log::error!("missing builder, there must be something wrong.");
bail!("missing builder, there must be something wrong.")
}
}
Expand Down

0 comments on commit ad96e25

Please sign in to comment.