diff --git a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/Cormorant.java b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/Cormorant.java index bbbdaf1b..917c46fa 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/Cormorant.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/Cormorant.java @@ -33,6 +33,8 @@ public class Cormorant { bitcoindClient.importWallets(AppServices.get().getOpenWallets().keySet()); } catch(ImportFailedException e) { log.debug("Failed to import wallets", e); + } finally { + bitcoindClient.signalInitialImportStarted(); } }, "Cormorant Initial Wallet Importer"); importThread.setDaemon(true); diff --git a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java index 355284ec..75dda98d 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java @@ -56,6 +56,8 @@ public class BitcoindClient { private boolean initialized; private boolean stopped; + private Exception lastPollException; + private boolean pruned; private boolean prunedWarningShown = false; private boolean legacyWalletExists; @@ -101,8 +103,15 @@ public class BitcoindClient { try { syncing = true; syncingCondition.await(); + + if(syncing) { + if(lastPollException instanceof RuntimeException runtimeException) { + throw runtimeException; + } + throw new RuntimeException("Error while waiting for sync to complete", lastPollException); + } } catch(InterruptedException e) { - throw new CormorantBitcoindException("Interrupted while waiting for sync to complete"); + throw new RuntimeException("Interrupted while waiting for sync to complete"); } finally { syncingLock.unlock(); } @@ -456,7 +465,7 @@ public class BitcoindClient { } } - private void signalInitialImportStarted() { + public void signalInitialImportStarted() { if(!initialImportStarted) { initialImportLock.lock(); try { @@ -542,7 +551,17 @@ public class BitcoindClient { } } } catch(Exception e) { + lastPollException = e; log.warn("Error polling Bitcoin Core: " + e.getMessage()); + + if(syncing) { + syncingLock.lock(); + try { + syncingCondition.signal(); + } finally { + syncingLock.unlock(); + } + } } } } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BlockchainInfo.java b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BlockchainInfo.java index 7d19ec7c..cfd10275 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BlockchainInfo.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BlockchainInfo.java @@ -11,6 +11,6 @@ public record BlockchainInfo(int blocks, int headers, String bestblockhash, bool } public int getProgressPercent() { - return (int) Math.round(verificationprogress * 100); + return (int) Math.floor(verificationprogress * 100); } }