Skip to content

Commit

Permalink
Ignore importdescriptor error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rajarshimaitra committed Feb 13, 2023
1 parent c2a4249 commit 66eb958
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions src/blockchain/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,20 +678,43 @@ where
})
.collect(),
);
for v in client.call::<Vec<Value>>("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::<Vec<Value>>("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 {
return 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>
Expand Down

0 comments on commit 66eb958

Please sign in to comment.