cormorant: syncing and pruning improvements

This commit is contained in:
Craig Raw 2022-12-15 14:03:56 +02:00
parent 064708f088
commit 41dabac75b
3 changed files with 24 additions and 3 deletions

View file

@ -33,6 +33,8 @@ public class Cormorant {
bitcoindClient.importWallets(AppServices.get().getOpenWallets().keySet()); bitcoindClient.importWallets(AppServices.get().getOpenWallets().keySet());
} catch(ImportFailedException e) { } catch(ImportFailedException e) {
log.debug("Failed to import wallets", e); log.debug("Failed to import wallets", e);
} finally {
bitcoindClient.signalInitialImportStarted();
} }
}, "Cormorant Initial Wallet Importer"); }, "Cormorant Initial Wallet Importer");
importThread.setDaemon(true); importThread.setDaemon(true);

View file

@ -56,6 +56,8 @@ public class BitcoindClient {
private boolean initialized; private boolean initialized;
private boolean stopped; private boolean stopped;
private Exception lastPollException;
private boolean pruned; private boolean pruned;
private boolean prunedWarningShown = false; private boolean prunedWarningShown = false;
private boolean legacyWalletExists; private boolean legacyWalletExists;
@ -101,8 +103,15 @@ public class BitcoindClient {
try { try {
syncing = true; syncing = true;
syncingCondition.await(); 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) { } catch(InterruptedException e) {
throw new CormorantBitcoindException("Interrupted while waiting for sync to complete"); throw new RuntimeException("Interrupted while waiting for sync to complete");
} finally { } finally {
syncingLock.unlock(); syncingLock.unlock();
} }
@ -456,7 +465,7 @@ public class BitcoindClient {
} }
} }
private void signalInitialImportStarted() { public void signalInitialImportStarted() {
if(!initialImportStarted) { if(!initialImportStarted) {
initialImportLock.lock(); initialImportLock.lock();
try { try {
@ -542,7 +551,17 @@ public class BitcoindClient {
} }
} }
} catch(Exception e) { } catch(Exception e) {
lastPollException = e;
log.warn("Error polling Bitcoin Core: " + e.getMessage()); log.warn("Error polling Bitcoin Core: " + e.getMessage());
if(syncing) {
syncingLock.lock();
try {
syncingCondition.signal();
} finally {
syncingLock.unlock();
}
}
} }
} }
} }

View file

@ -11,6 +11,6 @@ public record BlockchainInfo(int blocks, int headers, String bestblockhash, bool
} }
public int getProgressPercent() { public int getProgressPercent() {
return (int) Math.round(verificationprogress * 100); return (int) Math.floor(verificationprogress * 100);
} }
} }