From 9958a2fb0abf39b21a647476fb486364fc68736c Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Fri, 22 Aug 2025 13:37:53 +0200 Subject: [PATCH] Add Docker support with retry logic and custom cookie path --- src/main.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index d7aae8a..3699ec9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -432,13 +432,32 @@ async fn main() -> Result<()> { .set(PeerMap::new(HashMap::new())) .expect("PeerMap initialization failed"); - // Connect the rpc daemon - DAEMON - .set(Mutex::new(Box::new(Daemon::connect( - config.core_wallet, - config.core_url, + // Connect the rpc daemon with retry logic + let cookie_path = config.get_cookie_path().ok(); + let mut retry_count = 0; + const MAX_RETRIES: u32 = 5; + const RETRY_DELAY_MS: u64 = 2000; // 2 seconds initial delay + + let daemon = loop { + match Daemon::connect( + config.core_wallet.clone(), + config.core_url.clone(), config.network, - )?))) + ) { + Ok(daemon) => break daemon, + Err(e) => { + retry_count += 1; + if retry_count >= MAX_RETRIES { + return Err(e.context("Failed to connect to Bitcoin Core after multiple attempts")); + } + log::warn!("Failed to connect to Bitcoin Core (attempt {}/{}): {}", retry_count, MAX_RETRIES, e); + std::thread::sleep(std::time::Duration::from_millis(RETRY_DELAY_MS * retry_count)); + } + } + }; + + DAEMON + .set(Mutex::new(Box::new(daemon))) .expect("DAEMON initialization failed"); let current_tip: u32 = DAEMON