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(tee-prover): fix deserialization of std::time::Duration in envy config #2817

Merged
merged 3 commits into from
Sep 6, 2024
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
18 changes: 14 additions & 4 deletions core/bin/zksync_tee_prover/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ pub(crate) struct TeeProverConfig {
pub max_retries: usize,
/// Initial back-off interval when retrying recovery on a retriable error. Each subsequent retry interval
/// will be multiplied by [`Self.retry_backoff_multiplier`].
pub initial_retry_backoff: Duration,
pub initial_retry_backoff_sec: u64,
/// Multiplier for the back-off interval when retrying recovery on a retriable error.
pub retry_backoff_multiplier: f32,
/// Maximum back-off interval when retrying recovery on a retriable error.
pub max_backoff: Duration,
pub max_backoff_sec: u64,
}

impl TeeProverConfig {
pub fn initial_retry_backoff(&self) -> Duration {
Duration::from_secs(self.initial_retry_backoff_sec)
}

pub fn max_backoff(&self) -> Duration {
Duration::from_secs(self.max_backoff_sec)
}
}

impl FromEnv for TeeProverConfig {
Expand All @@ -39,9 +49,9 @@ impl FromEnv for TeeProverConfig {
/// export TEE_PROVER_TEE_TYPE="sgx"
/// export TEE_PROVER_API_URL="http://127.0.0.1:3320"
/// export TEE_PROVER_MAX_RETRIES=10
/// export TEE_PROVER_INITIAL_RETRY_BACKOFF=1
/// export TEE_PROVER_INITIAL_RETRY_BACKOFF_SEC=1
/// export TEE_PROVER_RETRY_BACKOFF_MULTIPLIER=2.0
/// export TEE_PROVER_MAX_BACKOFF=128
/// export TEE_PROVER_MAX_BACKOFF_SEC=128
/// ```
fn from_env() -> anyhow::Result<Self> {
let config: Self = envy::prefixed("TEE_PROVER_").from_env()?;
Expand Down
6 changes: 3 additions & 3 deletions core/bin/zksync_tee_prover/src/tee_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Task for TeeProver {
.await?;

let mut retries = 1;
let mut backoff = config.initial_retry_backoff;
let mut backoff = config.initial_retry_backoff();
let mut observer = METRICS.job_waiting_time.start();

loop {
Expand All @@ -141,7 +141,7 @@ impl Task for TeeProver {
let need_to_sleep = match result {
Ok(batch_number) => {
retries = 1;
backoff = config.initial_retry_backoff;
backoff = config.initial_retry_backoff();
if let Some(batch_number) = batch_number {
observer.observe();
observer = METRICS.job_waiting_time.start();
Expand All @@ -162,7 +162,7 @@ impl Task for TeeProver {
retries += 1;
backoff = std::cmp::min(
backoff.mul_f32(config.retry_backoff_multiplier),
config.max_backoff,
config.max_backoff(),
);
true
}
Expand Down
Loading