Skip to content

Commit af8f01b

Browse files
committed
Add error handler for curio peerId contract requests
1 parent a080668 commit af8f01b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

url_finder/src/provider_endpoints.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::time::Duration;
2+
13
use alloy::sol_types::SolType;
24
use alloy::{
35
network::TransactionBuilder,
@@ -7,8 +9,8 @@ use alloy::{
79
sol,
810
sol_types::SolCall,
911
};
10-
1112
use color_eyre::{Result, eyre::eyre};
13+
use tokio::time::sleep;
1214
use tracing::{debug, error};
1315

1416
use crate::config::CONFIG;
@@ -49,7 +51,22 @@ pub async fn valid_curio_provider(address: &str) -> Result<Option<String>> {
4951
.with_to(miner_peer_id_contract)
5052
.with_input(input);
5153

52-
let response = rpc_provider.call(tx).await?;
54+
let mut response = None;
55+
56+
for attempt in 1..=3 {
57+
match rpc_provider.call(tx.clone()).await {
58+
Ok(res) => {
59+
response = Some(res);
60+
break;
61+
}
62+
Err(e) => {
63+
println!("Attempt {attempt}/3 failed: {e} for address: {address}");
64+
sleep(Duration::from_secs(1)).await;
65+
}
66+
}
67+
}
68+
69+
let response = response.ok_or_else(|| eyre!("All 3 attempts failed for address {address}"))?;
5370

5471
let peer_data: PeerData = PeerData::abi_decode(response.as_ref())?;
5572

0 commit comments

Comments
 (0)