MCPcopy Create free account
hub / github.com/circlefin/arc-node / reconnect

Function reconnect

crates/eth-engine/src/persistence_meter.rs:368–393  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

366/// Retries forever. This runs in the background task, not in the caller's
367/// loop, so it never directly blocks block processing.
368async 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

Callers 1

background_readerFunction · 0.85

Calls 3

sleepFunction · 0.85
minMethod · 0.80
connect_and_subscribeFunction · 0.70

Tested by

no test coverage detected