From 899a6eb1042ebcc19204cc6120f1621a92b6446d Mon Sep 17 00:00:00 2001 From: CalDescent Date: Mon, 20 Jun 2022 22:48:32 +0100 Subject: [PATCH] Rework of systray statuses - Show "Minting" as long as online accounts are submitted to the network (previously it related to block signing). - Fixed bug causing it to regularly show "Synchronizing 100%". - Only show "Synchronizing" if the chain falls more than 2 hours behind - anything less is unnecessary noise. --- .../org/qortal/controller/Controller.java | 19 ++++++++++++------- .../controller/OnlineAccountsManager.java | 14 +++++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/qortal/controller/Controller.java b/src/main/java/org/qortal/controller/Controller.java index 223ea745..67bfbf13 100644 --- a/src/main/java/org/qortal/controller/Controller.java +++ b/src/main/java/org/qortal/controller/Controller.java @@ -787,23 +787,24 @@ public class Controller extends Thread { String actionText; // Use a more tolerant latest block timestamp in the isUpToDate() calls below to reduce misleading statuses. - // Any block in the last 60 minutes is considered "up to date" for the purposes of displaying statuses. - final Long minLatestBlockTimestamp = NTP.getTime() - (60 * 60 * 1000L); + // Any block in the last 2 hours is considered "up to date" for the purposes of displaying statuses. + // This also aligns with the time interval required for continued online account submission. + final Long minLatestBlockTimestamp = NTP.getTime() - (2 * 60 * 60 * 1000L); + + // Only show sync percent if it's less than 100, to avoid confusion + final Integer syncPercent = Synchronizer.getInstance().getSyncPercent(); + final boolean isSyncing = (syncPercent != null && syncPercent < 100); synchronized (Synchronizer.getInstance().syncLock) { if (Settings.getInstance().isLite()) { actionText = Translator.INSTANCE.translate("SysTray", "LITE_NODE"); SysTray.getInstance().setTrayIcon(4); } - else if (this.isMintingPossible) { - actionText = Translator.INSTANCE.translate("SysTray", "MINTING_ENABLED"); - SysTray.getInstance().setTrayIcon(2); - } else if (numberOfPeers < Settings.getInstance().getMinBlockchainPeers()) { actionText = Translator.INSTANCE.translate("SysTray", "CONNECTING"); SysTray.getInstance().setTrayIcon(3); } - else if (!this.isUpToDate(minLatestBlockTimestamp) && Synchronizer.getInstance().isSynchronizing()) { + else if (!this.isUpToDate(minLatestBlockTimestamp) && isSyncing) { actionText = String.format("%s - %d%%", Translator.INSTANCE.translate("SysTray", "SYNCHRONIZING_BLOCKCHAIN"), Synchronizer.getInstance().getSyncPercent()); SysTray.getInstance().setTrayIcon(3); } @@ -811,6 +812,10 @@ public class Controller extends Thread { actionText = String.format("%s", Translator.INSTANCE.translate("SysTray", "SYNCHRONIZING_BLOCKCHAIN")); SysTray.getInstance().setTrayIcon(3); } + else if (OnlineAccountsManager.getInstance().hasOnlineAccounts()) { + actionText = Translator.INSTANCE.translate("SysTray", "MINTING_ENABLED"); + SysTray.getInstance().setTrayIcon(2); + } else { actionText = Translator.INSTANCE.translate("SysTray", "MINTING_DISABLED"); SysTray.getInstance().setTrayIcon(4); diff --git a/src/main/java/org/qortal/controller/OnlineAccountsManager.java b/src/main/java/org/qortal/controller/OnlineAccountsManager.java index 8d498700..c1286c47 100644 --- a/src/main/java/org/qortal/controller/OnlineAccountsManager.java +++ b/src/main/java/org/qortal/controller/OnlineAccountsManager.java @@ -60,6 +60,8 @@ public class OnlineAccountsManager extends Thread { private final List onlineAccountsImportQueue = Collections.synchronizedList(new ArrayList<>()); + private boolean hasOnlineAccounts = false; + /** Cache of current 'online accounts' */ List onlineAccounts = new ArrayList<>(); @@ -116,6 +118,10 @@ public class OnlineAccountsManager extends Thread { this.interrupt(); } + public boolean hasOnlineAccounts() { + return this.hasOnlineAccounts; + } + // Online accounts import queue @@ -327,6 +333,7 @@ public class OnlineAccountsManager extends Thread { // 'current' timestamp final long onlineAccountsTimestamp = toOnlineAccountTimestamp(now); boolean hasInfoChanged = false; + boolean existingAccountsExist = false; byte[] timestampBytes = Longs.toByteArray(onlineAccountsTimestamp); List ourOnlineAccounts = new ArrayList<>(); @@ -347,8 +354,10 @@ public class OnlineAccountsManager extends Thread { if (Arrays.equals(existingOnlineAccountData.getPublicKey(), ourOnlineAccountData.getPublicKey())) { // If our online account is already present, with same timestamp, then move on to next mintingAccount - if (existingOnlineAccountData.getTimestamp() == onlineAccountsTimestamp) + if (existingOnlineAccountData.getTimestamp() == onlineAccountsTimestamp) { + existingAccountsExist = true; continue MINTING_ACCOUNTS; + } // If our online account is already present, but with older timestamp, then remove it iterator.remove(); @@ -364,6 +373,9 @@ public class OnlineAccountsManager extends Thread { hasInfoChanged = true; } + // Keep track of whether we have online accounts circulating in the network, for systray status + this.hasOnlineAccounts = existingAccountsExist || !ourOnlineAccounts.isEmpty(); + if (!hasInfoChanged) return;