Skip to content
Merged
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
35 changes: 18 additions & 17 deletions core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1394,10 +1394,10 @@ private void maybeInitMainWallet(boolean sync) {
maybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS);
}

private void maybeInitMainWallet(boolean sync, int numSyncAttempts) {
private void maybeInitMainWallet(boolean sync, int numSyncAttemptsRemaining) {
ThreadUtils.execute(() -> {
try {
doMaybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS);
doMaybeInitMainWallet(sync, numSyncAttemptsRemaining);
} catch (Exception e) {
if (isShutDownStarted) return;
log.warn("Error initializing main wallet: {}\n", e.getMessage(), e);
Expand All @@ -1407,7 +1407,7 @@ private void maybeInitMainWallet(boolean sync, int numSyncAttempts) {
}, THREAD_ID);
}

private void doMaybeInitMainWallet(boolean sync, int numSyncAttempts) {
private void doMaybeInitMainWallet(boolean sync, int numSyncAttemptsRemaining) {
synchronized (walletLock) {
if (isShutDownStarted) return;

Expand Down Expand Up @@ -1435,7 +1435,7 @@ private void doMaybeInitMainWallet(boolean sync, int numSyncAttempts) {

// sync main wallet if applicable
// TODO: error handling and re-initialization is jenky, refactor
if (sync && numSyncAttempts > 0) {
if (sync && numSyncAttemptsRemaining > 0) {
try {

// switch connection if disconnected
Expand All @@ -1454,13 +1454,14 @@ private void doMaybeInitMainWallet(boolean sync, int numSyncAttempts) {
if (wallet != null) log.warn("Error syncing wallet with progress on startup: " + e.getMessage());
forceCloseMainWallet();
requestSwitchToNextBestConnection(sourceConnection);
maybeInitMainWallet(true, numSyncAttempts - 1); // re-initialize wallet and sync again
maybeInitMainWallet(true, numSyncAttemptsRemaining - 1); // re-initialize wallet and sync again
return;
}
log.info("Done syncing main wallet in " + (System.currentTimeMillis() - time) + " ms");

// poll wallet
doPollWallet(true);
if (getBalance() == null) throw new RuntimeException("Balance is null after polling main wallet");
if (walletInitListener != null) xmrConnectionService.downloadPercentageProperty().removeListener(walletInitListener);

// log wallet balances
Expand Down Expand Up @@ -1488,9 +1489,9 @@ private void doMaybeInitMainWallet(boolean sync, int numSyncAttempts) {
saveWallet(false);
} catch (Exception e) {
if (isClosingWallet || isShutDownStarted || HavenoUtils.havenoSetup.getWalletInitialized().get()) return; // ignore if wallet closing, shut down started, or app already initialized
log.warn("Error initially syncing main wallet: {}", e.getMessage());
if (numSyncAttempts <= 1) {
log.warn("Failed to sync main wallet. Opening app without syncing", numSyncAttempts);
log.warn("Error initially syncing main wallet, numSyncAttemptsRemaining={}", numSyncAttemptsRemaining, e);
if (numSyncAttemptsRemaining <= 1) {
log.warn("Failed to sync main wallet. Opening app without syncing.");
HavenoUtils.havenoSetup.getWalletInitialized().set(true);
saveWallet(false);

Expand All @@ -1501,7 +1502,7 @@ private void doMaybeInitMainWallet(boolean sync, int numSyncAttempts) {
} else {
log.warn("Trying again in {} seconds", xmrConnectionService.getRefreshPeriodMs() / 1000);
UserThread.runAfter(() -> {
maybeInitMainWallet(true, numSyncAttempts - 1);
maybeInitMainWallet(true, numSyncAttemptsRemaining - 1);
}, xmrConnectionService.getRefreshPeriodMs() / 1000);
}
}
Expand Down Expand Up @@ -2063,15 +2064,15 @@ else if (isWalletConnectedToDaemon()) {
}
}
saveWalletWithDelay();
}

// cache wallet info last
synchronized (walletLock) {
if (wallet != null && !isShutDownStarted) {
try {
cacheWalletInfo();
} catch (Exception e) {
log.warn("Error caching wallet info: " + e.getMessage() + "\n", e);
// cache wallet info last
synchronized (walletLock) {
if (wallet != null && !isShutDownStarted) {
try {
cacheWalletInfo();
} catch (Exception e) {
log.warn("Error caching wallet info: " + e.getMessage() + "\n", e);
}
}
}
}
Expand Down
Loading