Skip to content

Commit

Permalink
throttle warnings when monerod not synced within tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Aug 30, 2024
1 parent ffe88b4 commit 7eeb441
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class XmrWalletService extends XmrWalletBase {
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 static final long LOG_DAEMON_NOT_SYNCED_WARN_PERIOD_MS = 1000 * 30; // log warnings when daemon not synced once every 30s

private final User user;
private final Preferences preferences;
Expand All @@ -151,6 +152,7 @@ public class XmrWalletService extends XmrWalletBase {
private TaskLooper pollLooper;
private boolean pollInProgress;
private Long pollPeriodMs;
private long lastLogDaemonNotSyncedTimestamp;
private long lastLogPollErrorTimestamp;
private long lastPollTxsTimestamp;
private final Object pollLock = new Object();
Expand Down Expand Up @@ -1767,9 +1769,15 @@ private void doPollWallet(boolean updateTxs) {
return;
}
if (!xmrConnectionService.isSyncedWithinTolerance()) {
log.warn("Monero daemon is not synced within tolerance, height={}, targetHeight={}", xmrConnectionService.chainHeightProperty().get(), xmrConnectionService.getTargetHeight());

// throttle warnings
if (System.currentTimeMillis() - lastLogDaemonNotSyncedTimestamp > LOG_DAEMON_NOT_SYNCED_WARN_PERIOD_MS) {
log.warn("Monero daemon is not synced within tolerance, height={}, targetHeight={}, monerod={}", xmrConnectionService.chainHeightProperty().get(), xmrConnectionService.getTargetHeight(), xmrConnectionService.getConnection() == null ? null : xmrConnectionService.getConnection().getUri());
lastLogDaemonNotSyncedTimestamp = System.currentTimeMillis();
}
return;
}

// sync wallet if behind daemon
if (walletHeight.get() < xmrConnectionService.getTargetHeight()) {
synchronized (walletLock) { // avoid long sync from blocking other operations
Expand Down

0 comments on commit 7eeb441

Please sign in to comment.