forked from Qortal/qortal
Tighten up sync status reporting, especially when using forcesync
This commit is contained in:
parent
de8e5ec920
commit
ca3fcc3c67
@ -20,17 +20,14 @@ public class NodeStatus {
|
|||||||
public final int height;
|
public final int height;
|
||||||
|
|
||||||
public NodeStatus() {
|
public NodeStatus() {
|
||||||
isMintingPossible = Controller.getInstance().isMintingPossible();
|
this.isMintingPossible = Controller.getInstance().isMintingPossible();
|
||||||
isSynchronizing = Controller.getInstance().isSynchronizing();
|
|
||||||
|
|
||||||
if (isSynchronizing)
|
this.syncPercent = Controller.getInstance().getSyncPercent();
|
||||||
syncPercent = Controller.getInstance().getSyncPercent();
|
this.isSynchronizing = this.syncPercent != null;
|
||||||
else
|
|
||||||
syncPercent = null;
|
|
||||||
|
|
||||||
numberOfConnections = Network.getInstance().getHandshakedPeers().size();
|
this.numberOfConnections = Network.getInstance().getHandshakedPeers().size();
|
||||||
|
|
||||||
height = Controller.getInstance().getChainHeight();
|
this.height = Controller.getInstance().getChainHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,8 @@ public class Controller extends Thread {
|
|||||||
/** Whether we can mint new blocks, as reported by BlockMinter. */
|
/** Whether we can mint new blocks, as reported by BlockMinter. */
|
||||||
private volatile boolean isMintingPossible = false;
|
private volatile boolean isMintingPossible = false;
|
||||||
|
|
||||||
|
/** Synchronization object for sync variables below */
|
||||||
|
private final Object syncLock = new Object();
|
||||||
/** Whether we are attempting to synchronize. */
|
/** Whether we are attempting to synchronize. */
|
||||||
private volatile boolean isSynchronizing = false;
|
private volatile boolean isSynchronizing = false;
|
||||||
/** Temporary estimate of synchronization progress for SysTray use. */
|
/** Temporary estimate of synchronization progress for SysTray use. */
|
||||||
@ -272,7 +274,9 @@ public class Controller extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Integer getSyncPercent() {
|
public Integer getSyncPercent() {
|
||||||
return this.isSynchronizing ? this.syncPercent : null;
|
synchronized (this.syncLock) {
|
||||||
|
return this.isSynchronizing ? this.syncPercent : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry point
|
// Entry point
|
||||||
@ -511,6 +515,10 @@ public class Controller extends Thread {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private void potentiallySynchronize() throws InterruptedException {
|
private void potentiallySynchronize() throws InterruptedException {
|
||||||
|
// Already synchronizing via another thread?
|
||||||
|
if (this.isSynchronizing)
|
||||||
|
return;
|
||||||
|
|
||||||
List<Peer> peers = Network.getInstance().getHandshakedPeers();
|
List<Peer> peers = Network.getInstance().getHandshakedPeers();
|
||||||
|
|
||||||
// Disregard peers that have "misbehaved" recently
|
// Disregard peers that have "misbehaved" recently
|
||||||
@ -543,13 +551,21 @@ public class Controller extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SynchronizationResult actuallySynchronize(Peer peer, boolean force) throws InterruptedException {
|
public SynchronizationResult actuallySynchronize(Peer peer, boolean force) throws InterruptedException {
|
||||||
syncPercent = (this.chainTip.getHeight() * 100) / peer.getChainTipData().getLastHeight();
|
boolean hasStatusChanged = false;
|
||||||
// Only update SysTray if we're potentially changing height
|
|
||||||
if (syncPercent < 100) {
|
synchronized (this.syncLock) {
|
||||||
isSynchronizing = true;
|
this.syncPercent = (this.chainTip.getHeight() * 100) / peer.getChainTipData().getLastHeight();
|
||||||
updateSysTray();
|
|
||||||
|
// Only update SysTray if we're potentially changing height
|
||||||
|
if (this.syncPercent < 100) {
|
||||||
|
this.isSynchronizing = true;
|
||||||
|
hasStatusChanged = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasStatusChanged)
|
||||||
|
updateSysTray();
|
||||||
|
|
||||||
BlockData priorChainTip = this.chainTip;
|
BlockData priorChainTip = this.chainTip;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -649,14 +665,17 @@ public class Controller extends Thread {
|
|||||||
String heightText = Translator.INSTANCE.translate("SysTray", "BLOCK_HEIGHT");
|
String heightText = Translator.INSTANCE.translate("SysTray", "BLOCK_HEIGHT");
|
||||||
|
|
||||||
String actionText;
|
String actionText;
|
||||||
if (isMintingPossible)
|
|
||||||
actionText = Translator.INSTANCE.translate("SysTray", "MINTING_ENABLED");
|
synchronized (this.syncLock) {
|
||||||
else if (isSynchronizing)
|
if (this.isMintingPossible)
|
||||||
actionText = String.format("%s - %d%%", Translator.INSTANCE.translate("SysTray", "SYNCHRONIZING_BLOCKCHAIN"), syncPercent);
|
actionText = Translator.INSTANCE.translate("SysTray", "MINTING_ENABLED");
|
||||||
else if (numberOfPeers < Settings.getInstance().getMinBlockchainPeers())
|
else if (this.isSynchronizing)
|
||||||
actionText = Translator.INSTANCE.translate("SysTray", "CONNECTING");
|
actionText = String.format("%s - %d%%", Translator.INSTANCE.translate("SysTray", "SYNCHRONIZING_BLOCKCHAIN"), this.syncPercent);
|
||||||
else
|
else if (numberOfPeers < Settings.getInstance().getMinBlockchainPeers())
|
||||||
actionText = Translator.INSTANCE.translate("SysTray", "MINTING_DISABLED");
|
actionText = Translator.INSTANCE.translate("SysTray", "CONNECTING");
|
||||||
|
else
|
||||||
|
actionText = Translator.INSTANCE.translate("SysTray", "MINTING_DISABLED");
|
||||||
|
}
|
||||||
|
|
||||||
String tooltip = String.format("%s - %d %s - %s %d", actionText, numberOfPeers, connectionsText, heightText, height);
|
String tooltip = String.format("%s - %d %s - %s %d", actionText, numberOfPeers, connectionsText, heightText, height);
|
||||||
SysTray.getInstance().setToolTipText(tooltip);
|
SysTray.getInstance().setToolTipText(tooltip);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user