From 643ba5fdf36e7506fc2316a5985ccce5004acdff Mon Sep 17 00:00:00 2001 From: Miguel de Elias Date: Tue, 16 Apr 2024 13:00:36 -0300 Subject: [PATCH 1/2] chore: add a retry option for ipfs request --- availability-oracle/src/ipfs.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/availability-oracle/src/ipfs.rs b/availability-oracle/src/ipfs.rs index 5b5a195..b4fbe2b 100644 --- a/availability-oracle/src/ipfs.rs +++ b/availability-oracle/src/ipfs.rs @@ -86,7 +86,24 @@ impl Ipfs for IpfsImpl { return Result::Ok(cached_bytes); } - let res = self.call("cat", cid).await; + async fn call_with_retry( + ipfs: &IpfsImpl, + cid: Cid, + retries: usize, + ) -> Result { + let mut last_err = None; + for _ in 0..=retries { + match ipfs.call("cat", cid).await { + Ok(res) => return Ok(res), + Err(e) => { + last_err = Some(e); + }, + } + } + Err(last_err.unwrap()) + } + + let res = call_with_retry(self, cid, 1).await; METRICS.ipfs_requests_total.inc(); let final_bytes = res?.bytes().map_err(|e| IpfsError::Other(e.into())).await?; From e8491d5a5c95364be514d0efce844711cd7ce9c0 Mon Sep 17 00:00:00 2001 From: Miguel de Elias Date: Tue, 16 Apr 2024 13:07:11 -0300 Subject: [PATCH 2/2] fix: fmt errors --- availability-oracle/src/ipfs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/availability-oracle/src/ipfs.rs b/availability-oracle/src/ipfs.rs index b4fbe2b..6d49cfe 100644 --- a/availability-oracle/src/ipfs.rs +++ b/availability-oracle/src/ipfs.rs @@ -97,7 +97,7 @@ impl Ipfs for IpfsImpl { Ok(res) => return Ok(res), Err(e) => { last_err = Some(e); - }, + } } } Err(last_err.unwrap())