Skip to content

For bitcoind readyness wait 100ms instead of 500ms #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ impl BitcoinD {
.spawn()?;

let node_url_default = format!("{}/wallet/default", rpc_url);
let mut i = 0;
// wait bitcoind is ready, use default wallet
let client = loop {
if let Some(status) = process.try_wait()? {
Expand All @@ -303,9 +304,10 @@ impl BitcoinD {
return Err(Error::EarlyExit(status));
}
}
thread::sleep(Duration::from_millis(500));
thread::sleep(Duration::from_millis(100));
assert!(process.stderr.is_none());
let client_result = Client::new(&rpc_url, Auth::CookieFile(cookie_file.clone()));

if let Ok(client_base) = client_result {
// RpcApi has get_blockchain_info method, however being generic with `Value` allows
// to be compatible with different version, in the end we are only interested if
Expand All @@ -322,6 +324,14 @@ impl BitcoinD {
break Client::new(&node_url_default, Auth::CookieFile(cookie_file.clone()))?;
}
}

debug!(
"bitcoin client for process {} not ready ({})",
process.id(),
i
);

i += 1;
};

Ok(BitcoinD {
Expand Down