Skip to content

Commit e1229c3

Browse files
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.
1 parent c2a4249 commit e1229c3

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

src/blockchain/rpc.rs

+37-14
Original file line numberDiff line numberDiff line change
@@ -678,20 +678,43 @@ where
678678
})
679679
.collect(),
680680
);
681-
for v in client.call::<Vec<Value>>("importdescriptors", &[requests])? {
682-
match v["success"].as_bool() {
683-
Some(true) => continue,
684-
Some(false) => {
685-
return Err(Error::Generic(
686-
v["error"]["message"]
687-
.as_str()
688-
.map_or("unknown error".into(), ToString::to_string),
689-
))
690-
}
691-
_ => return Err(Error::Generic("Unexpected response form Core".to_string())),
692-
}
693-
}
694-
Ok(())
681+
682+
client
683+
.call::<Vec<Value>>("importdescriptors", &[requests])
684+
.map_or_else(
685+
|e| {
686+
// While rescaning a new wallet from genesis, core rpc sometimes throw "Resource Temporarily Unavailable" Transport error.
687+
// This doesn't stop the sync, so it's safe to ignore.
688+
// See: https://github.com/bitcoindevkit/bdk/issues/859
689+
if let bitcoincore_rpc::Error::JsonRpc(
690+
bitcoincore_rpc::jsonrpc::Error::Transport(_),
691+
) = e
692+
{
693+
debug!("Resource Temporarily Unavailable, carrying on!!");
694+
Ok(())
695+
} else {
696+
Err(e.into())
697+
}
698+
},
699+
|result| {
700+
for v in result {
701+
match v["success"].as_bool() {
702+
Some(true) => continue,
703+
Some(false) => {
704+
return Err(Error::Generic(
705+
v["error"]["message"]
706+
.as_str()
707+
.map_or("unknown error".into(), ToString::to_string),
708+
))
709+
}
710+
_ => {
711+
return Err(Error::Generic("Unexpected response form Core".to_string()))
712+
}
713+
}
714+
}
715+
Ok(())
716+
},
717+
)
695718
}
696719

697720
fn import_multi<'a, S>(client: &Client, start_epoch: u64, scripts_iter: S) -> Result<(), Error>

0 commit comments

Comments
 (0)