mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-01-07 03:19:26 +00:00
fix null wallet on error handling
This commit is contained in:
parent
018ac61054
commit
cccd9cf094
3 changed files with 29 additions and 25 deletions
|
@ -852,14 +852,6 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requestSwitchToNextBestConnection(MoneroRpcConnection sourceConnection) {
|
|
||||||
if (xmrConnectionService.requestSwitchToNextBestConnection(sourceConnection)) {
|
|
||||||
onConnectionChanged(xmrConnectionService.getConnection()); // change connection on same thread
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIdling() {
|
public boolean isIdling() {
|
||||||
return this instanceof ArbitratorTrade && isDepositsConfirmed() && walletExists() && pollNormalStartTimeMs == null; // arbitrator idles trade after deposits confirm unless overriden
|
return this instanceof ArbitratorTrade && isDepositsConfirmed() && walletExists() && pollNormalStartTimeMs == null; // arbitrator idles trade after deposits confirm unless overriden
|
||||||
}
|
}
|
||||||
|
@ -2386,7 +2378,8 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
|
||||||
return tradeVolumeProperty;
|
return tradeVolumeProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onConnectionChanged(MoneroRpcConnection connection) {
|
@Override
|
||||||
|
protected void onConnectionChanged(MoneroRpcConnection connection) {
|
||||||
synchronized (walletLock) {
|
synchronized (walletLock) {
|
||||||
|
|
||||||
// use current connection
|
// use current connection
|
||||||
|
|
|
@ -17,6 +17,7 @@ import javafx.beans.property.LongProperty;
|
||||||
import javafx.beans.property.SimpleLongProperty;
|
import javafx.beans.property.SimpleLongProperty;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import monero.common.MoneroRpcConnection;
|
||||||
import monero.common.TaskLooper;
|
import monero.common.TaskLooper;
|
||||||
import monero.daemon.model.MoneroTx;
|
import monero.daemon.model.MoneroTx;
|
||||||
import monero.wallet.MoneroWallet;
|
import monero.wallet.MoneroWallet;
|
||||||
|
@ -24,7 +25,7 @@ import monero.wallet.MoneroWalletFull;
|
||||||
import monero.wallet.model.MoneroWalletListener;
|
import monero.wallet.model.MoneroWalletListener;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class XmrWalletBase {
|
public abstract class XmrWalletBase {
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
public static final int SYNC_PROGRESS_TIMEOUT_SECONDS = 120;
|
public static final int SYNC_PROGRESS_TIMEOUT_SECONDS = 120;
|
||||||
|
@ -137,6 +138,19 @@ public class XmrWalletBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean requestSwitchToNextBestConnection(MoneroRpcConnection sourceConnection) {
|
||||||
|
if (xmrConnectionService.requestSwitchToNextBestConnection(sourceConnection)) {
|
||||||
|
onConnectionChanged(xmrConnectionService.getConnection()); // change connection on same thread
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void onConnectionChanged(MoneroRpcConnection connection);
|
||||||
|
|
||||||
|
|
||||||
|
// ------------------------------ PRIVATE HELPERS -------------------------
|
||||||
|
|
||||||
private void updateSyncProgress(long height, long targetHeight) {
|
private void updateSyncProgress(long height, long targetHeight) {
|
||||||
resetSyncProgressTimeout();
|
resetSyncProgressTimeout();
|
||||||
UserThread.execute(() -> {
|
UserThread.execute(() -> {
|
||||||
|
|
|
@ -1334,7 +1334,7 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
maybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS);
|
maybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeInitMainWallet(boolean sync, int numAttempts) {
|
private void maybeInitMainWallet(boolean sync, int numSyncAttempts) {
|
||||||
ThreadUtils.execute(() -> {
|
ThreadUtils.execute(() -> {
|
||||||
try {
|
try {
|
||||||
doMaybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS);
|
doMaybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS);
|
||||||
|
@ -1346,7 +1346,7 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
}, THREAD_ID);
|
}, THREAD_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doMaybeInitMainWallet(boolean sync, int numAttempts) {
|
private void doMaybeInitMainWallet(boolean sync, int numSyncAttempts) {
|
||||||
synchronized (walletLock) {
|
synchronized (walletLock) {
|
||||||
if (isShutDownStarted) return;
|
if (isShutDownStarted) return;
|
||||||
|
|
||||||
|
@ -1374,7 +1374,7 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
|
|
||||||
// sync main wallet if applicable
|
// sync main wallet if applicable
|
||||||
// TODO: error handling and re-initialization is jenky, refactor
|
// TODO: error handling and re-initialization is jenky, refactor
|
||||||
if (sync && numAttempts > 0) {
|
if (sync && numSyncAttempts > 0) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// switch connection if disconnected
|
// switch connection if disconnected
|
||||||
|
@ -1393,7 +1393,7 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
log.warn("Error syncing wallet with progress on startup: " + e.getMessage());
|
log.warn("Error syncing wallet with progress on startup: " + e.getMessage());
|
||||||
forceCloseMainWallet();
|
forceCloseMainWallet();
|
||||||
requestSwitchToNextBestConnection(sourceConnection);
|
requestSwitchToNextBestConnection(sourceConnection);
|
||||||
maybeInitMainWallet(true, numAttempts - 1); // re-initialize wallet and sync again
|
maybeInitMainWallet(true, numSyncAttempts - 1); // re-initialize wallet and sync again
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("Done syncing main wallet in " + (System.currentTimeMillis() - time) + " ms");
|
log.info("Done syncing main wallet in " + (System.currentTimeMillis() - time) + " ms");
|
||||||
|
@ -1428,8 +1428,8 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (isClosingWallet || isShutDownStarted || HavenoUtils.havenoSetup.getWalletInitialized().get()) return; // ignore if wallet closing, shut down started, or app already initialized
|
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());
|
log.warn("Error initially syncing main wallet: {}", e.getMessage());
|
||||||
if (numAttempts <= 1) {
|
if (numSyncAttempts <= 1) {
|
||||||
log.warn("Failed to sync main wallet. Opening app without syncing", numAttempts);
|
log.warn("Failed to sync main wallet. Opening app without syncing", numSyncAttempts);
|
||||||
HavenoUtils.havenoSetup.getWalletInitialized().set(true);
|
HavenoUtils.havenoSetup.getWalletInitialized().set(true);
|
||||||
saveMainWallet(false);
|
saveMainWallet(false);
|
||||||
|
|
||||||
|
@ -1440,7 +1440,7 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
} else {
|
} else {
|
||||||
log.warn("Trying again in {} seconds", xmrConnectionService.getRefreshPeriodMs() / 1000);
|
log.warn("Trying again in {} seconds", xmrConnectionService.getRefreshPeriodMs() / 1000);
|
||||||
UserThread.runAfter(() -> {
|
UserThread.runAfter(() -> {
|
||||||
maybeInitMainWallet(true, numAttempts - 1);
|
maybeInitMainWallet(true, numSyncAttempts - 1);
|
||||||
}, xmrConnectionService.getRefreshPeriodMs() / 1000);
|
}, xmrConnectionService.getRefreshPeriodMs() / 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1754,7 +1754,8 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
return MONERO_WALLET_RPC_MANAGER.startInstance(cmd);
|
return MONERO_WALLET_RPC_MANAGER.startInstance(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onConnectionChanged(MoneroRpcConnection connection) {
|
@Override
|
||||||
|
protected void onConnectionChanged(MoneroRpcConnection connection) {
|
||||||
synchronized (walletLock) {
|
synchronized (walletLock) {
|
||||||
|
|
||||||
// use current connection
|
// use current connection
|
||||||
|
@ -1858,13 +1859,13 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
log.warn("Force restarting main wallet");
|
log.warn("Force restarting main wallet");
|
||||||
if (isClosingWallet) return;
|
if (isClosingWallet) return;
|
||||||
forceCloseMainWallet();
|
forceCloseMainWallet();
|
||||||
maybeInitMainWallet(true);
|
doMaybeInitMainWallet(true, MAX_SYNC_ATTEMPTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleWalletError(Exception e, MoneroRpcConnection sourceConnection) {
|
public void handleWalletError(Exception e, MoneroRpcConnection sourceConnection) {
|
||||||
if (HavenoUtils.isUnresponsive(e)) forceCloseMainWallet(); // wallet can be stuck a while
|
if (HavenoUtils.isUnresponsive(e)) forceCloseMainWallet(); // wallet can be stuck a while
|
||||||
if (xmrConnectionService.isConnected()) requestSwitchToNextBestConnection(sourceConnection);
|
requestSwitchToNextBestConnection(sourceConnection);
|
||||||
getWallet(); // re-open wallet
|
if (wallet == null) doMaybeInitMainWallet(true, MAX_SYNC_ATTEMPTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startPolling() {
|
private void startPolling() {
|
||||||
|
@ -2033,10 +2034,6 @@ public class XmrWalletService extends XmrWalletBase {
|
||||||
return requestSwitchToNextBestConnection(null);
|
return requestSwitchToNextBestConnection(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requestSwitchToNextBestConnection(MoneroRpcConnection sourceConnection) {
|
|
||||||
return xmrConnectionService.requestSwitchToNextBestConnection(sourceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onNewBlock(long height) {
|
private void onNewBlock(long height) {
|
||||||
UserThread.execute(() -> {
|
UserThread.execute(() -> {
|
||||||
walletHeight.set(height);
|
walletHeight.set(height);
|
||||||
|
|
Loading…
Reference in a new issue