Retry the subscription connection with exponential backoff (1s → 60s cap). Retries forever. This runs in the background task, not in the caller's loop, so it never directly blocks block processing.
(
endpoint: &SubscriptionEndpoint,
)
| 366 | /// Retries forever. This runs in the background task, not in the caller's |
| 367 | /// loop, so it never directly blocks block processing. |
| 368 | async fn reconnect( |
| 369 | endpoint: &SubscriptionEndpoint, |
| 370 | ) -> (Client, jsonrpsee::core::client::Subscription<BlockNumHash>) { |
| 371 | let mut backoff = RECONNECT_BACKOFF; |
| 372 | loop { |
| 373 | match connect_and_subscribe(endpoint).await { |
| 374 | Ok((client, subscription)) => { |
| 375 | info!("Persistence meter: reconnected to persisted block subscription"); |
| 376 | return (client, subscription); |
| 377 | } |
| 378 | Err(error) => { |
| 379 | warn!( |
| 380 | %error, |
| 381 | backoff = ?backoff, |
| 382 | "Persistence meter: reconnection failed; retrying" |
| 383 | ); |
| 384 | tokio::time::sleep(backoff).await; |
| 385 | // backoff <= MAX_RECONNECT_BACKOFF (60s); *2 fits in Duration |
| 386 | #[allow(clippy::arithmetic_side_effects)] |
| 387 | { |
| 388 | backoff = (backoff * 2).min(MAX_RECONNECT_BACKOFF); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /// Establish a fresh connection and subscribe to persisted block |
| 396 | /// notifications. Used both for the initial connection in |
no test coverage detected