From d9f9c1e7368101af1b982e6c7794643b552b5f57 Mon Sep 17 00:00:00 2001
From: woodser <woodser@protonmail.com>
Date: Wed, 8 Jan 2025 21:24:31 -0500
Subject: [PATCH] do not restore backup wallet cache if shutting down

---
 .../haveno/core/xmr/wallet/XmrWalletService.java  | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java
index 3bf8cfde..4c459077 100644
--- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java
+++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java
@@ -1343,6 +1343,7 @@ public class XmrWalletService extends XmrWalletBase {
             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;
@@ -1510,10 +1511,11 @@ public class XmrWalletService extends XmrWalletBase {
             // 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 {
@@ -1551,7 +1553,7 @@ public class XmrWalletService extends XmrWalletBase {
 
                         // 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;
@@ -1565,7 +1567,7 @@ public class XmrWalletService extends XmrWalletBase {
                         } 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));
@@ -1637,11 +1639,12 @@ public class XmrWalletService extends XmrWalletBase {
             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 {
@@ -1679,7 +1682,7 @@ public class XmrWalletService extends XmrWalletBase {
 
                         // 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;
@@ -1693,7 +1696,7 @@ public class XmrWalletService extends XmrWalletBase {
                         } 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));