mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 11:39:29 +00:00
throttle warnings when monerod not synced within tolerance
This commit is contained in:
parent
30f0cf273c
commit
cae360b6c5
3 changed files with 19 additions and 5 deletions
|
@ -99,9 +99,10 @@ public final class XmrConnectionService {
|
|||
@Getter
|
||||
private MoneroDaemonInfo lastInfo;
|
||||
private Long lastLogPollErrorTimestamp;
|
||||
private Long syncStartHeight = null;
|
||||
private long lastLogDaemonNotSyncedTimestamp;
|
||||
private Long syncStartHeight;
|
||||
private TaskLooper daemonPollLooper;
|
||||
private long lastRefreshPeriodMs = 0;
|
||||
private long lastRefreshPeriodMs;
|
||||
@Getter
|
||||
private boolean isShutDownStarted;
|
||||
private List<MoneroConnectionManagerListener> listeners = new ArrayList<>();
|
||||
|
@ -371,7 +372,6 @@ public final class XmrConnectionService {
|
|||
Long targetHeight = getTargetHeight();
|
||||
if (targetHeight == null) return false;
|
||||
if (targetHeight - chainHeight.get() <= 3) return true; // synced if within 3 blocks of target height
|
||||
log.warn("Our chain height: {} is out of sync with peer nodes chain height: {}", chainHeight.get(), targetHeight);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -720,7 +720,7 @@ public final class XmrConnectionService {
|
|||
}
|
||||
|
||||
// log error message periodically
|
||||
if ((lastLogPollErrorTimestamp == null || System.currentTimeMillis() - lastLogPollErrorTimestamp > HavenoUtils.LOG_POLL_ERROR_PERIOD_MS)) {
|
||||
if (lastLogPollErrorTimestamp == null || System.currentTimeMillis() - lastLogPollErrorTimestamp > HavenoUtils.LOG_POLL_ERROR_PERIOD_MS) {
|
||||
log.warn("Failed to fetch daemon info, trying to switch to best connection: " + e.getMessage());
|
||||
if (DevEnv.isDevMode()) e.printStackTrace();
|
||||
lastLogPollErrorTimestamp = System.currentTimeMillis();
|
||||
|
@ -734,6 +734,12 @@ public final class XmrConnectionService {
|
|||
// connected to daemon
|
||||
isConnected = true;
|
||||
|
||||
// throttle warnings if daemon not synced
|
||||
if (!isSyncedWithinTolerance() && System.currentTimeMillis() - lastLogDaemonNotSyncedTimestamp > HavenoUtils.LOG_DAEMON_NOT_SYNCED_WARN_PERIOD_MS) {
|
||||
log.warn("Our chain height: {} is out of sync with peer nodes chain height: {}", chainHeight.get(), getTargetHeight());
|
||||
lastLogDaemonNotSyncedTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// announce connection change if refresh period changes
|
||||
if (getRefreshPeriodMs() != lastRefreshPeriodMs) {
|
||||
lastRefreshPeriodMs = getRefreshPeriodMs();
|
||||
|
|
|
@ -81,6 +81,7 @@ public class HavenoUtils {
|
|||
|
||||
// other configuration
|
||||
public static final long LOG_POLL_ERROR_PERIOD_MS = 1000 * 60 * 4; // log poll errors up to once every 4 minutes
|
||||
public static final long LOG_DAEMON_NOT_SYNCED_WARN_PERIOD_MS = 1000 * 30; // log warnings when daemon not synced once every 30s
|
||||
|
||||
// synchronize requests to the daemon
|
||||
private static boolean SYNC_DAEMON_REQUESTS = false; // sync long requests to daemon (e.g. refresh, update pool) // TODO: performance suffers by syncing daemon requests, but otherwise we sometimes get sporadic errors?
|
||||
|
|
|
@ -151,6 +151,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();
|
||||
|
@ -1767,9 +1768,15 @@ public class XmrWalletService extends XmrWalletBase {
|
|||
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 > HavenoUtils.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
|
||||
|
|
Loading…
Reference in a new issue