From 2e86d4a62aa4d244fa98662335a23954cbbc9f67 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 27 Dec 2023 14:08:51 -0500 Subject: [PATCH] check local connection before switching --- .../haveno/core/api/XmrConnectionService.java | 22 ++++++++++++++----- .../core/xmr/wallet/XmrWalletService.java | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/haveno/core/api/XmrConnectionService.java b/core/src/main/java/haveno/core/api/XmrConnectionService.java index de42e08a..abac2bca 100644 --- a/core/src/main/java/haveno/core/api/XmrConnectionService.java +++ b/core/src/main/java/haveno/core/api/XmrConnectionService.java @@ -400,12 +400,24 @@ public final class XmrConnectionService { @Override public void onConnectionChanged(MoneroRpcConnection connection) { log.info("Local monerod connection changed: " + connection); - if (isShutDownStarted || !connectionManager.getAutoSwitch() || !accountService.isAccountOpen()) return; - if (xmrLocalNode.isConnected() && !xmrLocalNode.shouldBeIgnored()) { - setConnection(connection.getUri()); // switch to local node if connected and not ignored - checkConnection(); + + // skip if ignored + if (isShutDownStarted || !connectionManager.getAutoSwitch() || !accountService.isAccountOpen() || + !connectionManager.hasConnection(connection.getUri()) || xmrLocalNode.shouldBeIgnored()) return; + + // check connection + boolean isConnected = false; + if (xmrLocalNode.isConnected()) { + MoneroRpcConnection conn = connectionManager.getConnectionByUri(connection.getUri()); + conn.checkConnection(connectionManager.getTimeout()); + isConnected = Boolean.TRUE.equals(conn.isConnected()); + } + + // update connection + if (isConnected) { + setConnection(connection.getUri()); } else if (getConnection() != null && getConnection().getUri().equals(connection.getUri())) { - setConnection(getBestAvailableConnection()); // switch to best available connection + setConnection(getBestAvailableConnection()); // switch to best connection } } }); 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 5adb58dd..eafb8938 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -951,7 +951,7 @@ public class XmrWalletService { }); } - log.info("Done setting main wallet daemon connection: " + (connection == null ? null : connection.getUri())); + log.info("Done setting main wallet daemon connection: " + (wallet.getDaemonConnection() == null ? null : wallet.getDaemonConnection().getUri())); } }