diff --git a/bitcoin-wallet/src/lib.rs b/bitcoin-wallet/src/lib.rs index 3f6be7de8b..48789e9a74 100644 --- a/bitcoin-wallet/src/lib.rs +++ b/bitcoin-wallet/src/lib.rs @@ -49,6 +49,8 @@ pub trait BitcoinWallet: Send + Sync { async fn sync(&self) -> Result<()>; + async fn health_check(&self) -> Result<()>; + async fn subscribe_to(&self, tx: Box) -> Subscription; async fn status_of_script(&self, tx: &dyn Watchable) -> Result; diff --git a/bitcoin-wallet/src/wallet.rs b/bitcoin-wallet/src/wallet.rs index 6183aad3ca..785ed78c69 100644 --- a/bitcoin-wallet/src/wallet.rs +++ b/bitcoin-wallet/src/wallet.rs @@ -1096,6 +1096,13 @@ impl Wallet { .context("Failed to sync Bitcoin wallet after retries") } + pub async fn health_check(&self) -> Result<()> { + self.electrum_client + .update_block_height() + .await + .context("Bitcoin wallet failed to reach the Electrum backend") + } + /// Calculate the fee for a given transaction. /// /// Will fail if the transaction inputs are not owned by this wallet. @@ -1663,7 +1670,7 @@ impl Client { } /// Update the block height. - async fn update_block_height(&self) -> Result<()> { + pub async fn update_block_height(&self) -> Result<()> { let latest_block = self .inner .call_async("block_headers_subscribe", |client| { @@ -2166,6 +2173,10 @@ impl BitcoinWallet for Wallet { Wallet::sync(self).await } + async fn health_check(&self) -> Result<()> { + Wallet::health_check(self).await + } + async fn subscribe_to(&self, tx: Box) -> Subscription { Wallet::subscribe_to(self, tx).await } @@ -2976,6 +2987,10 @@ impl BitcoinWallet for Wallet { unimplemented!("stub method called erroneously") } + async fn health_check(&self) -> Result<()> { + unimplemented!("stub method called erroneously") + } + async fn subscribe_to(&self, tx: Box) -> Subscription { unimplemented!("stub method called erroneously") } diff --git a/swap/src/asb/event_loop.rs b/swap/src/asb/event_loop.rs index 30ce0b1e9e..c944baf3fd 100644 --- a/swap/src/asb/event_loop.rs +++ b/swap/src/asb/event_loop.rs @@ -1292,6 +1292,11 @@ async fn capture_wallet_snapshot( ) -> Result { let start_time = Instant::now(); + bitcoin_wallet + .health_check() + .await + .context("Bitcoin wallet health check failed while capturing wallet snapshot")?; + let unlocked_balance = monero_wallet.main_wallet().await.unlocked_balance().await?; let total_balance = monero_wallet.main_wallet().await.total_balance().await?;