Skip to content
Closed
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
15 changes: 10 additions & 5 deletions node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ pub enum Error {
RpcUserAndPasswordUsed,
/// Returned when expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set
SkipDownload,
/// It appears that bitcoind is not reachable.
NoBitcoindInstance,
/// Returned when bitcoind could not be reached after multiple attempts.
/// The attached string, if present, contains the error encountered when trying to connect.
NoBitcoindInstance(Option<String>),
}

impl fmt::Debug for Error {
Expand All @@ -154,7 +155,8 @@ impl fmt::Debug for Error {
BothDirsSpecified => write!(f, "tempdir and staticdir cannot be enabled at same time in configuration options"),
RpcUserAndPasswordUsed => write!(f, "`-rpcuser` and `-rpcpassword` cannot be used, it will be deprecated soon and it's recommended to use `-rpcauth` instead which works alongside with the default cookie authentication"),
SkipDownload => write!(f, "expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set"),
NoBitcoindInstance => write!(f, "it appears that bitcoind is not reachable"),
NoBitcoindInstance(Some(msg)) => write!(f, "it appears that bitcoind is not reachable: {}", msg),
NoBitcoindInstance(None) => write!(f, "it appears that bitcoind is not reachable."),
}
}
}
Expand All @@ -177,7 +179,7 @@ impl std::error::Error for Error {
| BothDirsSpecified
| RpcUserAndPasswordUsed
| SkipDownload
| NoBitcoindInstance => None,
| NoBitcoindInstance(_) => None,
}
}
}
Expand Down Expand Up @@ -388,20 +390,22 @@ impl Node {
assert!(process.stderr.is_none());

let mut tries = 0;
let mut last_error = None;
let auth = Auth::CookieFile(cookie_file.clone());

let client = loop {
tries += 1;

if tries > 10 {
error!("failed to get a response from bitcoind");
return Err(Error::NoBitcoindInstance.into());
return Err(Error::NoBitcoindInstance(last_error).into());
}

let client_base = match Client::new_with_auth(&rpc_url, auth.clone()) {
Ok(client) => client,
Err(e) => {
error!("failed to create client: {}. Retrying!", e);
last_error = Some(format!("{}", e));
thread::sleep(Duration::from_millis(1000));
continue;
}
Expand Down Expand Up @@ -439,6 +443,7 @@ impl Node {
}
Err(e) => {
error!("failed to get a response from bitcoind: {}. Retrying!", e);
last_error = Some(format!("{}", e));
thread::sleep(Duration::from_millis(1000));
continue;
}
Expand Down