From 517469a55dbb518c7742f0b2f5b1d3c231bf906e Mon Sep 17 00:00:00 2001 From: Mengran Lan Date: Thu, 22 Aug 2024 16:03:20 +0800 Subject: [PATCH] feat(prover): log utilization (#1491) --- prover/src/coordinator_client.rs | 2 ++ prover/src/coordinator_client/api.rs | 22 ++++++++++++++++++++-- prover/src/coordinator_client/errors.rs | 12 ++++++++++++ prover/src/main.rs | 9 ++++++++- prover/src/task_processor.rs | 25 ++++++++++++++++++------- prover/src/zk_circuits_handler.rs | 2 -- 6 files changed, 60 insertions(+), 12 deletions(-) diff --git a/prover/src/coordinator_client.rs b/prover/src/coordinator_client.rs index 56fd58954e..46067d7ccf 100644 --- a/prover/src/coordinator_client.rs +++ b/prover/src/coordinator_client.rs @@ -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, diff --git a/prover/src/coordinator_client/api.rs b/prover/src/coordinator_client/api.rs index 53fdf2d49d..905a1e61c5 100644 --- a/prover/src/coordinator_client/api.rs +++ b/prover/src/coordinator_client/api.rs @@ -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}; @@ -76,7 +78,23 @@ impl Api { token: &String, ) -> Result> { let method = "/coordinator/v1/submit_proof"; - self.post_with_token(method, req, token).await + let response = self + .post_with_token::>( + 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( diff --git a/prover/src/coordinator_client/errors.rs b/prover/src/coordinator_client/errors.rs index 2d27b3cd82..9bad256fac 100644 --- a/prover/src/coordinator_client/errors.rs +++ b/prover/src/coordinator_client/errors.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Deserializer}; +use std::fmt; #[derive(Debug, Clone, Copy, PartialEq)] pub enum ErrorCode { @@ -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") + } +} diff --git a/prover/src/main.rs b/prover/src/main.rs index 22605a7a5c..d1bf82830b 100644 --- a/prover/src/main.rs +++ b/prover/src/main.rs @@ -37,7 +37,7 @@ struct Args { log_file: Option, } -fn main() -> Result<(), Box> { +fn start() -> Result<()> { let args = Args::parse(); if args.version { @@ -76,3 +76,10 @@ fn main() -> Result<(), Box> { Ok(()) } + +fn main() { + let result = start(); + if let Err(e) = result { + log::error!("main exit with error {:#}", e) + } +} diff --git a/prover/src/task_processor.rs b/prover/src/task_processor.rs index 3b4044f96f..df4629d5bd 100644 --- a/prover/src/task_processor.rs +++ b/prover/src/task_processor.rs @@ -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; @@ -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::() { + log::info!("proof status not ok, downgrade level to info."); + } else { + log::error!("encounter error: {:#}", err); + } } else { log::info!("prove & submit succeed."); } @@ -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; } diff --git a/prover/src/zk_circuits_handler.rs b/prover/src/zk_circuits_handler.rs index db254e2abb..ac2a43e384 100644 --- a/prover/src/zk_circuits_handler.rs +++ b/prover/src/zk_circuits_handler.rs @@ -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.") } } @@ -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.") } }