From 7461da972243a1f5e9fa91c45910d9fd881bd14e Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 7 Aug 2024 07:12:53 -0400 Subject: [PATCH] request connection switch on poll if txs not updated within 3 minutes --- .../java/haveno/core/xmr/wallet/XmrWalletService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 52620957..4db9538a 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -127,6 +127,7 @@ public class XmrWalletService extends XmrWalletBase { private static final String THREAD_ID = XmrWalletService.class.getSimpleName(); private static final long SHUTDOWN_TIMEOUT_MS = 60000; private static final long NUM_BLOCKS_BEHIND_TOLERANCE = 5; + private static final long POLL_TXS_TOLERANCE_MS = 1000 * 60 * 3; // request connection switch if txs not updated within 3 minutes private final User user; private final Preferences preferences; @@ -150,7 +151,8 @@ public class XmrWalletService extends XmrWalletBase { private TaskLooper pollLooper; private boolean pollInProgress; private Long pollPeriodMs; - private Long lastLogPollErrorTimestamp; + private long lastLogPollErrorTimestamp; + private long lastPollTxsTimestamp; private final Object pollLock = new Object(); private Long cachedHeight; private BigInteger cachedBalance; @@ -1789,14 +1791,15 @@ public class XmrWalletService extends XmrWalletBase { MoneroRpcConnection sourceConnection = xmrConnectionService.getConnection(); try { cachedTxs = wallet.getTxs(new MoneroTxQuery().setIncludeOutputs(true)); + lastPollTxsTimestamp = System.currentTimeMillis(); } catch (Exception e) { // fetch from pool can fail if (!isShutDownStarted) { // throttle error handling - if (lastLogPollErrorTimestamp == null || System.currentTimeMillis() - lastLogPollErrorTimestamp > HavenoUtils.LOG_POLL_ERROR_PERIOD_MS) { + if (System.currentTimeMillis() - lastLogPollErrorTimestamp > HavenoUtils.LOG_POLL_ERROR_PERIOD_MS) { log.warn("Error polling main wallet's transactions from the pool: {}", e.getMessage()); lastLogPollErrorTimestamp = System.currentTimeMillis(); - requestSwitchToNextBestConnection(sourceConnection); + if (System.currentTimeMillis() - lastPollTxsTimestamp > POLL_TXS_TOLERANCE_MS) requestSwitchToNextBestConnection(sourceConnection); } } }