Skip to content

Commit

Permalink
fix(tee-prover): fix deserialization of std::time::Duration in `env…
Browse files Browse the repository at this point in the history
…y` config (#2817)

## 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:
serde-rs/serde#339 (comment)

## 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`.
  • Loading branch information
pbeza committed Sep 6, 2024
1 parent ac75d87 commit df8641a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
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

0 comments on commit df8641a

Please sign in to comment.