Add Docker support with retry logic and custom cookie path
This commit is contained in:
parent
f3010530d6
commit
22c3ef33e3
31
src/main.rs
31
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user