mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-24 14:50:28 -04:00
fix npe on startup routine when monero node is not synced
This commit is contained in:
parent
a4345ae709
commit
ea536bb4ee
1 changed files with 18 additions and 17 deletions
|
@ -1394,10 +1394,10 @@ public class XmrWalletService extends XmrWalletBase {
|
|||
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);
|
||||
|
@ -1407,7 +1407,7 @@ public class XmrWalletService extends XmrWalletBase {
|
|||
}, THREAD_ID);
|
||||
}
|
||||
|
||||
private void doMaybeInitMainWallet(boolean sync, int numSyncAttempts) {
|
||||
private void doMaybeInitMainWallet(boolean sync, int numSyncAttemptsRemaining) {
|
||||
synchronized (walletLock) {
|
||||
if (isShutDownStarted) return;
|
||||
|
||||
|
@ -1435,7 +1435,7 @@ public class XmrWalletService extends XmrWalletBase {
|
|||
|
||||
// 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
|
||||
|
@ -1454,13 +1454,14 @@ public class XmrWalletService extends XmrWalletBase {
|
|||
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
|
||||
|
@ -1488,9 +1489,9 @@ public class XmrWalletService extends XmrWalletBase {
|
|||
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);
|
||||
|
||||
|
@ -1501,7 +1502,7 @@ public class XmrWalletService extends XmrWalletBase {
|
|||
} else {
|
||||
log.warn("Trying again in {} seconds", xmrConnectionService.getRefreshPeriodMs() / 1000);
|
||||
UserThread.runAfter(() -> {
|
||||
maybeInitMainWallet(true, numSyncAttempts - 1);
|
||||
maybeInitMainWallet(true, numSyncAttemptsRemaining - 1);
|
||||
}, xmrConnectionService.getRefreshPeriodMs() / 1000);
|
||||
}
|
||||
}
|
||||
|
@ -2063,15 +2064,15 @@ public class XmrWalletService extends XmrWalletBase {
|
|||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue