diff --git a/Cargo.lock b/Cargo.lock index c85c26c633b0..cbf364bdf6f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -662,16 +662,13 @@ dependencies = [ ] [[package]] -name = "backoff" -version = "0.4.0" +name = "backon" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" +checksum = "e4fa97bb310c33c811334143cf64c5bb2b7b3c06e453db6b095d7061eff8f113" dependencies = [ - "futures-core", - "getrandom", - "instant", - "pin-project-lite", - "rand", + "fastrand 2.2.0", + "gloo-timers", "tokio", ] @@ -3116,7 +3113,7 @@ dependencies = [ "async-trait", "asynchronous-codec", "axum", - "backoff", + "backon", "base64 0.22.1", "bigdecimal", "bimap", diff --git a/Cargo.toml b/Cargo.toml index 1947bd1479a1..1e0dea01279b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ async-fs = "2" async-trait = "0.1" asynchronous-codec = "0.7" axum = "0.7" -backoff = { version = "0.4", features = ['tokio'] } +backon = "1.2.0" base64 = "0.22" bigdecimal = "=0.4.2" # TODO(forest): https://github.com/ChainSafe/forest/issues/4035 blake2b_simd = "1.0" diff --git a/deny.toml b/deny.toml index 51997b2dfd5e..7b75cd85241f 100644 --- a/deny.toml +++ b/deny.toml @@ -79,10 +79,6 @@ ignore = [ # Instant is unmaintained, but there is a replacement in # the pipeline - see # https://github.com/libp2p/rust-libp2p/pull/5674 - # We will likele need to get rid of `backoff` dependency - # in favour of something that is maintained too - see - # https://github.com/ihrwein/backoff/pull/70. Last commit - # to master was 3 years ago. "RUSTSEC-2024-0384", ] # If this is true, then cargo deny will use the git executable to fetch advisory database. diff --git a/src/beacon/drand.rs b/src/beacon/drand.rs index 63404b0f9d39..7e318eca09c0 100644 --- a/src/beacon/drand.rs +++ b/src/beacon/drand.rs @@ -15,11 +15,13 @@ use crate::shim::version::NetworkVersion; use crate::utils::net::global_http_client; use anyhow::Context as _; use async_trait::async_trait; +use backon::{ExponentialBuilder, Retryable}; use bls_signatures::Serialize as _; use itertools::Itertools as _; use lru::LruCache; use parking_lot::RwLock; use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize}; +use tracing::debug; use url::Url; /// Environmental Variable to ignore `Drand`. Lotus parallel is @@ -378,12 +380,15 @@ impl Beacon for DrandBeacon { anyhow::Ok(server.join(&format!("{}/public/{round}", self.hash))?) }) .try_collect()?; - Ok( - backoff::future::retry(backoff::ExponentialBackoff::default(), || async { - Ok(fetch_entry(urls.iter().cloned()).await?) + Ok((|| fetch_entry(urls.iter().cloned())) + .retry(ExponentialBuilder::default()) + .notify(|err, dur| { + debug!( + "retrying fetch_entry {err} after {}", + humantime::format_duration(dur) + ); }) - .await?, - ) + .await?) } } } diff --git a/src/utils/proofs_api/paramfetch.rs b/src/utils/proofs_api/paramfetch.rs index 39deb99b21fb..fed9457463eb 100644 --- a/src/utils/proofs_api/paramfetch.rs +++ b/src/utils/proofs_api/paramfetch.rs @@ -11,7 +11,6 @@ use std::{ io::{self, ErrorKind}, path::{Path, PathBuf}, sync::Arc, - time::Duration, }; use crate::{ @@ -22,7 +21,7 @@ use crate::{ }, }; use anyhow::{bail, Context}; -use backoff::{future::retry, ExponentialBackoffBuilder}; +use backon::{ExponentialBuilder, Retryable}; use futures::{stream::FuturesUnordered, AsyncWriteExt, TryStreamExt}; use tokio::fs::{self}; use tracing::{debug, info, warn}; @@ -156,16 +155,16 @@ async fn fetch_params_ipfs_gateway(path: &Path, info: &ParameterData) -> anyhow: "Fetching param file {path} from {gateway}", path = path.display() ); - let backoff = ExponentialBackoffBuilder::default() - // Up to 30 minutes for downloading the file. This may be drastic, - // but the gateway proved to be unreliable at times and we - // don't want to get stuck here. Better to fail fast and retry. - .with_max_elapsed_time(Some(Duration::from_secs(60 * 30))) - .build(); - let result = retry(backoff, || async { - Ok(download_ipfs_file_trustlessly(&info.cid, &gateway, path).await?) - }) - .await; + let result = (|| download_ipfs_file_trustlessly(&info.cid, &gateway, path)) + .retry(ExponentialBuilder::default()) + .notify(|err, dur| { + debug!( + "retrying download_ipfs_file_trustlessly {err} after {}", + humantime::format_duration(dur) + ); + }) + .await; + debug!( "Done fetching param file {path} from {gateway}", path = path.display(), @@ -176,13 +175,15 @@ async fn fetch_params_ipfs_gateway(path: &Path, info: &ParameterData) -> anyhow: /// Downloads the parameter file from Cloudflare R2 to the given path. It wraps the [`download_from_cloudflare`] function with a retry and timeout mechanisms. async fn fetch_params_cloudflare(name: &str, path: &Path) -> anyhow::Result<()> { info!("Fetching param file {name} from Cloudflare R2 {CLOUDFLARE_PROOF_PARAMETER_DOMAIN}"); - let backoff = ExponentialBackoffBuilder::default() - .with_max_elapsed_time(Some(Duration::from_secs(60 * 30))) - .build(); - let result = retry(backoff, || async { - Ok(download_from_cloudflare(name, path).await?) - }) - .await; + let result = (|| download_from_cloudflare(name, path)) + .retry(ExponentialBuilder::default()) + .notify(|err, dur| { + debug!( + "retrying download_from_cloudflare {err} after {}", + humantime::format_duration(dur) + ); + }) + .await; debug!( "Done fetching param file {} from Cloudflare", path.display()