From df8641a912a8d480ceecff58b0bfaef05e04f0c8 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 6 Sep 2024 14:59:22 +0200 Subject: [PATCH] fix(tee-prover): fix deserialization of `std::time::Duration` in `envy` config (#2817) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ This PR fixes the deserialization issue of `std::time::Duration` in the `envy` configuration. Relevant logs from the `stage` environment showcasing the issue: https://grafana.matterlabs.dev/goto/IC-9k4eIR?orgId=1 Error message from the above logs: ``` Error: missing value for field initial_retry_backoff ``` The root cause of the problem supposedly boils down to the mismatch between the expected format of `TEE_PROVER_INITIAL_RETRY_BACKOFF` and the actual format. We export it as follows: ``` export TEE_PROVER_INITIAL_RETRY_BACKOFF=1 ``` which is not supported as explained here: https://github.com/serde-rs/serde/issues/339#issuecomment-539453327 ## Why ❔ To fix the bug. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --- core/bin/zksync_tee_prover/src/config.rs | 18 ++++++++++++++---- core/bin/zksync_tee_prover/src/tee_prover.rs | 6 +++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/bin/zksync_tee_prover/src/config.rs b/core/bin/zksync_tee_prover/src/config.rs index 5b009e33f25..1c2eb229d61 100644 --- a/core/bin/zksync_tee_prover/src/config.rs +++ b/core/bin/zksync_tee_prover/src/config.rs @@ -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 { @@ -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 { let config: Self = envy::prefixed("TEE_PROVER_").from_env()?; diff --git a/core/bin/zksync_tee_prover/src/tee_prover.rs b/core/bin/zksync_tee_prover/src/tee_prover.rs index 3d227118e57..1511f0c88e3 100644 --- a/core/bin/zksync_tee_prover/src/tee_prover.rs +++ b/core/bin/zksync_tee_prover/src/tee_prover.rs @@ -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 { @@ -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(); @@ -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 }