alloy-rs / alloy-rs/alloy

[Feature] Expose retry attempt count to RetryPolicy::backoff_hint

Aperta
#4,066 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Rust
Stelle
1.3k
Fork
668
Merge medio
2g 1h
PR unite (30g)
29

Descrizione

### Component

transports

### Describe the feature you would like

RetryPolicy::backoff_hint only receives the error:

` fn backoff_hint(&self, error: &TransportError) -> Option;`

When it returns None, RetryBackoffService falls back to a constant initial_backoff on every attempt — there is no exponential growth:

```
let backoff_hint = this.policy.backoff_hint(&err);
let next_backoff = backoff_hint.unwrap_or_else(|| this.initial_backoff());
```

Without access to the current attempt number, a custom policy cannot implement standard exponential backoff, e.g.:

` next_backoff = initial_backoff * (1 + backoff_coefficient)^(num_retries - 1)`

Proposal: pass the attempt count to the policy, e.g.

` fn backoff_hint(&self, error: &TransportError, num_retries: u32) -> Option;`

(or a context struct to keep it extensible). Alternatively, implement exponential backoff with a max ceiling directly in RetryBackoffService when no hint is
returned.

### Additional context

Downstream use case: hoprnet/blokli — custom retry policy with configurable initial_backoff, backoff_coefficient, max_backoff, currently unable to apply
them (hoprnet/hoprnet#7140).

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by locating RetryPolicy::backoff_hint and RetryBackoffService in the transports component, then inspect their implementations and call sites. Compare the proposed attempt-count API with the alternative fallback behavior, and treat the work as done when the selected behavior is implemented consistently and affected callers compile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust
Ambito
networking
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.