Skip to content

Commit

Permalink
do not restore backup wallet cache if shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jan 10, 2025
1 parent 1ac4c45 commit d9f9c1e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,7 @@ private void maybeInitMainWallet(boolean sync, int numSyncAttempts) {
try {
doMaybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS);
} catch (Exception e) {
if (isShutDownStarted) return;
log.warn("Error initializing main wallet: {}\n", e.getMessage(), e);
HavenoUtils.setTopError(e.getMessage());
throw e;
Expand Down Expand Up @@ -1510,10 +1511,11 @@ private MoneroWalletFull openWalletFull(MoneroWalletConfig config, boolean apply
// try opening wallet
config.setNetworkType(getMoneroNetworkType());
config.setServer(connection);
log.info("Opening full wallet " + config.getPath() + " with monerod=" + connection.getUri() + ", proxyUri=" + connection.getProxyUri());
log.info("Opening full wallet '{}' with monerod={}, proxyUri={}", config.getPath(), connection.getUri(), connection.getProxyUri());
try {
walletFull = MoneroWalletFull.openWallet(config);
} catch (Exception e) {
if (isShutDownStarted) throw e;
log.warn("Failed to open full wallet '{}', attempting to use backup cache files, error={}", config.getPath(), e.getMessage());
boolean retrySuccessful = false;
try {
Expand Down Expand Up @@ -1551,7 +1553,7 @@ private MoneroWalletFull openWalletFull(MoneroWalletConfig config, boolean apply

// retry opening wallet after cache deleted
try {
log.warn("Failed to open full wallet using backup cache files, retrying with cache deleted");
log.warn("Failed to open full wallet '{}' using backup cache files, retrying with cache deleted", config.getPath());
walletFull = MoneroWalletFull.openWallet(config);
log.warn("Successfully opened full wallet after cache deleted");
retrySuccessful = true;
Expand All @@ -1565,7 +1567,7 @@ private MoneroWalletFull openWalletFull(MoneroWalletConfig config, boolean apply
} else {

// restore original wallet cache
log.warn("Failed to open full wallet after deleting cache, restoring original cache");
log.warn("Failed to open full wallet '{}' after deleting cache, restoring original cache", config.getPath());
File cacheFile = new File(cachePath);
if (cacheFile.exists()) cacheFile.delete();
if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath));
Expand Down Expand Up @@ -1637,11 +1639,12 @@ private MoneroWalletRpc openWalletRpc(MoneroWalletConfig config, Integer port, b
if (!applyProxyUri) connection.setProxyUri(null);

// try opening wallet
log.info("Opening RPC wallet " + config.getPath() + " with monerod=" + connection.getUri() + ", proxyUri=" + connection.getProxyUri());
log.info("Opening RPC wallet '{}' with monerod={}, proxyUri={}", config.getPath(), connection.getUri(), connection.getProxyUri());
config.setServer(connection);
try {
walletRpc.openWallet(config);
} catch (Exception e) {
if (isShutDownStarted) throw e;
log.warn("Failed to open RPC wallet '{}', attempting to use backup cache files, error={}", config.getPath(), e.getMessage());
boolean retrySuccessful = false;
try {
Expand Down Expand Up @@ -1679,7 +1682,7 @@ private MoneroWalletRpc openWalletRpc(MoneroWalletConfig config, Integer port, b

// retry opening wallet after cache deleted
try {
log.warn("Failed to open RPC wallet using backup cache files, retrying with cache deleted");
log.warn("Failed to open RPC wallet '{}' using backup cache files, retrying with cache deleted", config.getPath());
walletRpc.openWallet(config);
log.warn("Successfully opened RPC wallet after cache deleted");
retrySuccessful = true;
Expand All @@ -1693,7 +1696,7 @@ private MoneroWalletRpc openWalletRpc(MoneroWalletConfig config, Integer port, b
} else {

// restore original wallet cache
log.warn("Failed to open RPC wallet after deleting cache, restoring original cache");
log.warn("Failed to open RPC wallet '{}' after deleting cache, restoring original cache", config.getPath());
File cacheFile = new File(cachePath);
if (cacheFile.exists()) cacheFile.delete();
if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath));
Expand Down

0 comments on commit d9f9c1e

Please sign in to comment.