Skip to content

Commit

Permalink
add retry limits and sleep between retries
Browse files Browse the repository at this point in the history
  • Loading branch information
RCasatta committed Aug 15, 2024
1 parent f3a13e7 commit 4a455d4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,21 @@ impl Daemon {
}

fn retry_reconnect(&self) -> Daemon {
// XXX add a max reconnection attempts limit?
loop {
let attempts = 600;
let sleep = Duration::from_secs(1);
for _ in 0..attempts {
match self.reconnect() {
Ok(daemon) => break daemon,
Ok(daemon) => return daemon,
Err(e) => {
warn!("failed connecting to RPC daemon: {}", e.display_chain());
std::thread::sleep(sleep);
}
}
}
panic!(
"Cannot connect to the daemon after retrying {} times",
attempts
);
}

// Send requests in parallel over multiple RPC connections as individual JSON-RPC requests (with no JSON-RPC batching),
Expand Down Expand Up @@ -596,7 +602,10 @@ impl Daemon {
// Missing estimates are logged but do not cause a failure, whatever is available is returned
#[allow(clippy::float_cmp)]
pub fn estimatesmartfee_batch(&self, conf_targets: &[u16]) -> Result<HashMap<u16, f64>> {
let params_list: Vec<Value> = conf_targets.iter().map(|t| json!([t, "ECONOMICAL"])).collect();
let params_list: Vec<Value> = conf_targets
.iter()
.map(|t| json!([t, "ECONOMICAL"]))
.collect();

Ok(self
.requests("estimatesmartfee", params_list)?
Expand Down

0 comments on commit 4a455d4

Please sign in to comment.