Skip to content

Commit 7c6e035

Browse files
committed
adjust db retries params + explanation
1 parent 34b2ece commit 7c6e035

File tree

3 files changed

+58
-6
lines changed
  • aggregation_mode

3 files changed

+58
-6
lines changed

aggregation_mode/gateway/src/db.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,27 @@ use crate::types::Receipt;
22
use db::{orchestrator::DbOrchestartor, retry::RetryConfig};
33
use sqlx::types::{BigDecimal, Uuid};
44

5-
// Retry parameters for Db queries
5+
// Retry/backoff behavior summary (see
6+
// aggregation_mode/db/src/orchestrator.rs:next_back_off_delay for implementation)
7+
//
8+
// NOTE: These retry limits are intentionally lower than in other crates.
9+
// This code runs in an HTTP server; in the worst case the request fails fast
10+
// and the client can retry the request. Prolonged blocking retries here are
11+
// less critical than in background or batch processing jobs.
12+
//
13+
// 1) Max wait time between failures if all retries fail:
14+
// The sleep between retries is capped at 10 seconds (RETRY_MAX_DELAY_SECONDS).
15+
//
16+
// 2) Wait before each retry attempt with the current config
17+
// (start = 500ms, factor = 2.0, max retries = 4):
18+
//
19+
// retry 1: 0.5s
20+
// retry 2: 1.0s
21+
// retry 3: 2.0s
22+
// retry 4: 4.0s
23+
//
24+
// Worst-case total sleep time across all retries: 7.5 seconds,
25+
// plus the execution time of each DB attempt.
626
/// Initial delay before first retry attempt (in milliseconds)
727
const RETRY_MIN_DELAY_MILLIS: u64 = 500;
828
/// Exponential backoff multiplier for retry delays

aggregation_mode/payments_poller/src/db.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
use db::{orchestrator::DbOrchestartor, retry::RetryConfig};
22
use sqlx::types::BigDecimal;
33

4-
// Retry parameters for Db queries
4+
// Retry/backoff behavior summary for DB queries (see
5+
// aggregation_mode/db/src/orchestrator.rs:next_back_off_delay for implementation)
6+
//
7+
// 1) Max wait time between failures if all retries fail:
8+
// The sleep between retries is capped at 30 seconds (RETRY_MAX_DELAY_SECONDS).
9+
//
10+
// 2) Wait before each retry attempt with the current config
11+
// (start = 500ms, factor = 4.0, max retries = 5):
12+
//
13+
// retry 1: 0.5s
14+
// retry 2: 2.0s
15+
// retry 3: 8.0s
16+
// retry 4: 30s (capped; 32s would have been next)
17+
// retry 5: 30s
18+
//
19+
// Worst-case total sleep time across all retries: 70.5 seconds -> 5 blocks of ethereum waiting,
20+
// plus the execution time of each DB attempt.
521
/// Initial delay before first retry attempt (in milliseconds)
622
const RETRY_MIN_DELAY_MILLIS: u64 = 500;
723
/// Exponential backoff multiplier for retry delays
8-
const RETRY_FACTOR: f32 = 2.0;
24+
const RETRY_FACTOR: f32 = 4.0;
925
/// Maximum number of retry attempts
1026
const RETRY_MAX_TIMES: usize = 5;
1127
/// Maximum delay between retry attempts (in seconds)

aggregation_mode/proof_aggregator/src/backend/db.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
use db::{orchestrator::DbOrchestartor, retry::RetryConfig, types::Task};
22
use sqlx::types::Uuid;
33

4-
// Retry parameters for Db queries
4+
// Retry/backoff behavior summary (see
5+
// aggregation_mode/db/src/orchestrator.rs:next_back_off_delay for implementation)
6+
//
7+
// 1) Max wait time between failures if all retries fail:
8+
// The sleep between retries is capped at 30 seconds (RETRY_MAX_DELAY_SECONDS).
9+
//
10+
// 2) Wait before each retry attempt with the current config
11+
// (start = 500ms, factor = 5.0, max retries = 10):
12+
//
13+
// retry 1: 0.5s
14+
// retry 2: 2.5s
15+
// retry 3: 12.5s
16+
// retry 4: 30s (capped)
17+
// retry 5–10: 30s each
18+
//
19+
// Worst-case total sleep time across all retries: ~3m 48s,
20+
// plus the execution time of each DB attempt.
521
/// Initial delay before first retry attempt (in milliseconds)
622
const RETRY_MIN_DELAY_MILLIS: u64 = 500;
723
/// Exponential backoff multiplier for retry delays
8-
const RETRY_FACTOR: f32 = 2.0;
24+
const RETRY_FACTOR: f32 = 5.0;
925
/// Maximum number of retry attempts
10-
const RETRY_MAX_TIMES: usize = 5;
26+
const RETRY_MAX_TIMES: usize = 10;
1127
/// Maximum delay between retry attempts (in seconds)
1228
const RETRY_MAX_DELAY_SECONDS: u64 = 30;
1329

0 commit comments

Comments
 (0)