Add Docker support with retry logic and custom cookie path
This commit is contained in:
parent
a169c99366
commit
9958a2fb0a
31
src/main.rs
31
src/main.rs
@ -432,13 +432,32 @@ async fn main() -> Result<()> {
|
|||||||
.set(PeerMap::new(HashMap::new()))
|
.set(PeerMap::new(HashMap::new()))
|
||||||
.expect("PeerMap initialization failed");
|
.expect("PeerMap initialization failed");
|
||||||
|
|
||||||
// Connect the rpc daemon
|
// Connect the rpc daemon with retry logic
|
||||||
DAEMON
|
let cookie_path = config.get_cookie_path().ok();
|
||||||
.set(Mutex::new(Box::new(Daemon::connect(
|
let mut retry_count = 0;
|
||||||
config.core_wallet,
|
const MAX_RETRIES: u32 = 5;
|
||||||
config.core_url,
|
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,
|
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");
|
.expect("DAEMON initialization failed");
|
||||||
|
|
||||||
let current_tip: u32 = DAEMON
|
let current_tip: u32 = DAEMON
|
||||||
|
Loading…
x
Reference in New Issue
Block a user