Skip to content

Commit 0d03fac

Browse files
committed
fix: optimized polling
1 parent e31a2e2 commit 0d03fac

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

  • rust/main/agents/relayer/src/msg/metadata/ccip_read

rust/main/agents/relayer/src/msg/metadata/ccip_read/mod.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::blocks_in_conditions)] // TODO: `rustc` 1.80.1 clippy issue
22

3-
use std::time::Duration;
3+
use std::time::{Duration, Instant};
44

55
use async_trait::async_trait;
66
use cache_types::SerializedOffchainLookup;
@@ -31,6 +31,8 @@ use super::{
3131
mod cache_types;
3232

3333
pub const DEFAULT_TIMEOUT: u64 = 30;
34+
const FETCH_RETRY_INTERVAL: Duration = Duration::from_secs(3);
35+
const FETCH_RETRY_BUDGET: Duration = Duration::from_secs(60);
3436

3537
#[derive(Clone, Debug, Serialize)]
3638
struct OffchainLookupRequestBody {
@@ -241,12 +243,28 @@ async fn metadata_build(
241243
continue;
242244
}
243245

244-
// if we fail, we want to try the other urls
245-
match fetch_offchain_data(ism_builder, &info, url, origin_tx_hash.clone()).await {
246-
Ok(data) => return Ok(data),
247-
Err(err) => {
248-
tracing::warn!(?ism_address, url, ?err, "Failed to fetch offchain data");
249-
continue;
246+
let deadline = Instant::now() + FETCH_RETRY_BUDGET;
247+
loop {
248+
match fetch_offchain_data(ism_builder, &info, url, origin_tx_hash.clone()).await {
249+
Ok(data) => return Ok(data),
250+
Err(err) => {
251+
if Instant::now() >= deadline {
252+
tracing::warn!(
253+
?ism_address,
254+
url,
255+
?err,
256+
"Failed to fetch offchain data, budget exhausted"
257+
);
258+
break;
259+
}
260+
tracing::debug!(
261+
?ism_address,
262+
url,
263+
?err,
264+
"Failed to fetch offchain data, retrying"
265+
);
266+
tokio::time::sleep(FETCH_RETRY_INTERVAL).await;
267+
}
250268
}
251269
}
252270
}

0 commit comments

Comments
 (0)