Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch and retry on 'wallet already loading' error #451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions bitcoin/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ impl Error {
)
}

pub fn is_already_loading_wallet_error(&self) -> bool {
// Catch this error: `JSON-RPC error: RPC error response: RpcError { code: -4, message: "Wallet already
// loading.", data: None }`.
// In older versions, the message was "Wallet already being loading.". See https://github.com/bitcoin/bitcoin/commit/ae9d26a8f0435e2f4b39ad1181473e6575ac67b5
// We catch everything that starts with "Wallet already". As of the time of writing no error error messages
// start with that
matches!(self,
Error::BitcoinError(BitcoinError::JsonRpc(JsonRpcError::Rpc(err)))
if BitcoinRpcError::from(err.clone()) == BitcoinRpcError::RpcWalletError && err.message.starts_with("Wallet already")
)
}

pub fn rejected_by_network_rules(&self) -> bool {
matches!(self,
Error::BitcoinError(BitcoinError::JsonRpc(JsonRpcError::Rpc(err)))
Expand Down
8 changes: 6 additions & 2 deletions bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ impl BitcoinCore {
match call().await.map_err(Error::from) {
Err(inner) if inner.is_transport_error() && time.elapsed() >= TRANSPORT_TIMEOUT => {
info!("Call timed out - retrying...");
// timeout - retry again
}
Err(inner) if inner.is_already_loading_wallet_error() => {
info!("Wallet is already loading - retrying...");
}
result => return result,
};
Expand Down Expand Up @@ -961,7 +963,9 @@ impl BitcoinCoreApi for BitcoinCore {
info!("Loading wallet {wallet_name}...");
let result = self.rpc.load_wallet(wallet_name)?;
if let Some(warning) = result.warning {
warn!("Received error while loading wallet {wallet_name}: {warning}");
if !warning.is_empty() {
warn!("Received error while loading wallet {wallet_name}: {warning}");
}
}
} else {
info!("Creating wallet {wallet_name}...");
Expand Down