From e1229c36d0ac86de7b68f19ff64f56d95c02a076 Mon Sep 17 00:00:00 2001 From: rajarshimaitra Date: Mon, 13 Feb 2023 12:37:42 +0530 Subject: [PATCH] Ignore importdescriptor error The importdescriptor call will throw a `Resource temporarily unavialble` error only in the first initial sync, where the wallet has to rescan from genesis. The sync process carries on as usual after the error, so this patch makes it ignore only that particular error and carry on the with sync. All other errors are captured as usual. --- src/blockchain/rpc.rs | 51 +++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/src/blockchain/rpc.rs b/src/blockchain/rpc.rs index da19e20c6..03bd64c65 100644 --- a/src/blockchain/rpc.rs +++ b/src/blockchain/rpc.rs @@ -678,20 +678,43 @@ where }) .collect(), ); - for v in client.call::>("importdescriptors", &[requests])? { - match v["success"].as_bool() { - Some(true) => continue, - Some(false) => { - return Err(Error::Generic( - v["error"]["message"] - .as_str() - .map_or("unknown error".into(), ToString::to_string), - )) - } - _ => return Err(Error::Generic("Unexpected response form Core".to_string())), - } - } - Ok(()) + + client + .call::>("importdescriptors", &[requests]) + .map_or_else( + |e| { + // While rescaning a new wallet from genesis, core rpc sometimes throw "Resource Temporarily Unavailable" Transport error. + // This doesn't stop the sync, so it's safe to ignore. + // See: https://github.com/bitcoindevkit/bdk/issues/859 + if let bitcoincore_rpc::Error::JsonRpc( + bitcoincore_rpc::jsonrpc::Error::Transport(_), + ) = e + { + debug!("Resource Temporarily Unavailable, carrying on!!"); + Ok(()) + } else { + Err(e.into()) + } + }, + |result| { + for v in result { + match v["success"].as_bool() { + Some(true) => continue, + Some(false) => { + return Err(Error::Generic( + v["error"]["message"] + .as_str() + .map_or("unknown error".into(), ToString::to_string), + )) + } + _ => { + return Err(Error::Generic("Unexpected response form Core".to_string())) + } + } + } + Ok(()) + }, + ) } fn import_multi<'a, S>(client: &Client, start_epoch: u64, scripts_iter: S) -> Result<(), Error>