Merge #398: bitcoind: do not error if watchonly wallet is loading on bitcoind

f0beef5f6095bdff399aa10e72ee01a6a678707f bitcoind: do not error if watchonly wallet is loading on bitcoind (Antoine Poinsot)

Pull request description:

  Fixes #380

ACKs for top commit:
  darosior:
    ACK f0beef5f6095bdff399aa10e72ee01a6a678707f -- tested manually.

Tree-SHA512: 6c22243623f3300379e90849e3d0ba0860da2cf23d38664465e0e844f0b04ca35af30082e1012d82f8e7454dbaf7a5a883067ca4ad3b1409624679a8e8370ad0
This commit is contained in:
Antoine Poinsot 2023-03-31 14:50:51 +02:00
commit 943cc16e77
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

View File

@ -586,13 +586,32 @@ impl BitcoinD {
/// Load the watchonly wallet on bitcoind, if it isn't already.
pub fn maybe_load_watchonly_wallet(&self) -> Result<(), BitcoindError> {
if !self.list_wallets().contains(&self.watchonly_wallet_path) {
self.make_fallible_node_request(
"loadwallet",
&params!(Json::String(self.watchonly_wallet_path.clone()),),
)?;
if self.list_wallets().contains(&self.watchonly_wallet_path) {
return Ok(());
}
Ok(())
let res = self.make_fallible_node_request(
"loadwallet",
&params!(Json::String(self.watchonly_wallet_path.clone()),),
);
match res {
Err(BitcoindError::Server(jsonrpc::Error::Rpc(ref e))) => {
if e.code == -4 && e.message.to_lowercase().contains("wallet already loading") {
log::warn!("The watchonly wallet is already loading on bitcoind. Waiting for completion.");
loop {
thread::sleep(Duration::from_secs(3));
if self.list_wallets().contains(&self.watchonly_wallet_path) {
log::warn!("Watchonly wallet now loaded. Continuing.");
return Ok(());
}
log::debug!(
"Watchonly wallet loading still not complete. Waiting 3 more seconds."
);
}
}
res
}
r => r,
}.map(|_| ())
}
/// Perform various non-wallet-related sanity checks on the bitcoind instance.