forked from Qortal/qortal
Improve minting/syncing status reporting
Added API call GET /admin/status which reports whether minting is possible (have minting keys & up-to-date) and whether node is currently attempting to sync. Corresponding change to system tray mouseover text. Corresponding text added to SysTray transaction resources.
This commit is contained in:
parent
79f7f68b0c
commit
db270f559f
15
src/main/java/org/qortal/api/model/NodeStatus.java
Normal file
15
src/main/java/org/qortal/api/model/NodeStatus.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package org.qortal.api.model;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class NodeStatus {
|
||||||
|
|
||||||
|
public boolean isMintingPossible;
|
||||||
|
public boolean isSynchronizing;
|
||||||
|
|
||||||
|
public NodeStatus() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -45,6 +45,7 @@ import org.qortal.api.ApiExceptionFactory;
|
|||||||
import org.qortal.api.Security;
|
import org.qortal.api.Security;
|
||||||
import org.qortal.api.model.ActivitySummary;
|
import org.qortal.api.model.ActivitySummary;
|
||||||
import org.qortal.api.model.NodeInfo;
|
import org.qortal.api.model.NodeInfo;
|
||||||
|
import org.qortal.api.model.NodeStatus;
|
||||||
import org.qortal.block.BlockChain;
|
import org.qortal.block.BlockChain;
|
||||||
import org.qortal.controller.Controller;
|
import org.qortal.controller.Controller;
|
||||||
import org.qortal.controller.Synchronizer.SynchronizationResult;
|
import org.qortal.controller.Synchronizer.SynchronizationResult;
|
||||||
@ -120,6 +121,27 @@ public class AdminResource {
|
|||||||
return nodeInfo;
|
return nodeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/status")
|
||||||
|
@Operation(
|
||||||
|
summary = "Fetch node status",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = NodeStatus.class))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public NodeStatus status() {
|
||||||
|
Security.checkApiCallAllowed(request);
|
||||||
|
|
||||||
|
NodeStatus nodeStatus = new NodeStatus();
|
||||||
|
|
||||||
|
nodeStatus.isMintingPossible = Controller.getInstance().isMintingPossible();
|
||||||
|
nodeStatus.isSynchronizing = Controller.getInstance().isSynchronizing();
|
||||||
|
|
||||||
|
return nodeStatus;
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/stop")
|
@Path("/stop")
|
||||||
@Operation(
|
@Operation(
|
||||||
|
@ -133,6 +133,9 @@ 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;
|
||||||
|
|
||||||
|
/** Whether we are attempting to synchronize. */
|
||||||
|
private volatile boolean isSynchronizing = false;
|
||||||
|
|
||||||
/** Latest block signatures from other peers that we know are on inferior chains. */
|
/** Latest block signatures from other peers that we know are on inferior chains. */
|
||||||
List<ByteArray> inferiorChainSignatures = new ArrayList<>();
|
List<ByteArray> inferiorChainSignatures = new ArrayList<>();
|
||||||
|
|
||||||
@ -245,6 +248,15 @@ public class Controller extends Thread {
|
|||||||
return isStopping;
|
return isStopping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For API use
|
||||||
|
public boolean isMintingPossible() {
|
||||||
|
return this.isMintingPossible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSynchronizing() {
|
||||||
|
return this.isSynchronizing;
|
||||||
|
}
|
||||||
|
|
||||||
// Entry point
|
// Entry point
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -497,7 +509,13 @@ public class Controller extends Thread {
|
|||||||
int index = new SecureRandom().nextInt(peers.size());
|
int index = new SecureRandom().nextInt(peers.size());
|
||||||
Peer peer = peers.get(index);
|
Peer peer = peers.get(index);
|
||||||
|
|
||||||
|
isSynchronizing = true;
|
||||||
|
updateSysTray();
|
||||||
|
|
||||||
actuallySynchronize(peer, false);
|
actuallySynchronize(peer, false);
|
||||||
|
|
||||||
|
isSynchronizing = false;
|
||||||
|
requestSysTrayUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SynchronizationResult actuallySynchronize(Peer peer, boolean force) throws InterruptedException {
|
public SynchronizationResult actuallySynchronize(Peer peer, boolean force) throws InterruptedException {
|
||||||
@ -601,9 +619,17 @@ public class Controller extends Thread {
|
|||||||
|
|
||||||
String connectionsText = Translator.INSTANCE.translate("SysTray", numberOfPeers != 1 ? "CONNECTIONS" : "CONNECTION");
|
String connectionsText = Translator.INSTANCE.translate("SysTray", numberOfPeers != 1 ? "CONNECTIONS" : "CONNECTION");
|
||||||
String heightText = Translator.INSTANCE.translate("SysTray", "BLOCK_HEIGHT");
|
String heightText = Translator.INSTANCE.translate("SysTray", "BLOCK_HEIGHT");
|
||||||
String mintingText = Translator.INSTANCE.translate("SysTray", isMintingPossible ? "MINTING_ENABLED" : "MINTING_DISABLED");
|
|
||||||
|
|
||||||
String tooltip = String.format("%s - %d %s - %s %d", mintingText, numberOfPeers, connectionsText, heightText, height);
|
String actionKey;
|
||||||
|
if (isMintingPossible)
|
||||||
|
actionKey = "MINTING_ENABLED";
|
||||||
|
else if (isSynchronizing)
|
||||||
|
actionKey = "SYNCHRONIZING_BLOCKCHAIN";
|
||||||
|
else
|
||||||
|
actionKey = "MINTING_DISABLED";
|
||||||
|
String actionText = Translator.INSTANCE.translate("SysTray", actionKey);
|
||||||
|
|
||||||
|
String tooltip = String.format("%s - %d %s - %s %d", actionText, numberOfPeers, connectionsText, heightText, height);
|
||||||
SysTray.getInstance().setToolTipText(tooltip);
|
SysTray.getInstance().setToolTipText(tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,4 +26,6 @@ OPEN_UI = Open UI
|
|||||||
|
|
||||||
SYNCHRONIZE_CLOCK = Synchronize clock
|
SYNCHRONIZE_CLOCK = Synchronize clock
|
||||||
|
|
||||||
|
SYNCHRONIZING_BLOCKCHAIN = Synchronizing
|
||||||
|
|
||||||
SYNCHRONIZING_CLOCK = Synchronizing clock
|
SYNCHRONIZING_CLOCK = Synchronizing clock
|
||||||
|
@ -26,4 +26,6 @@ OPEN_UI = \u5F00\u542F\u754C\u9762
|
|||||||
|
|
||||||
SYNCHRONIZE_CLOCK = \u540C\u6B65\u65F6\u949F
|
SYNCHRONIZE_CLOCK = \u540C\u6B65\u65F6\u949F
|
||||||
|
|
||||||
|
SYNCHRONIZING_BLOCKCHAIN = \u540C\u6B65\u533A\u5757\u94FE
|
||||||
|
|
||||||
SYNCHRONIZING_CLOCK = \u540C\u6B65\u7740\u65F6\u949F
|
SYNCHRONIZING_CLOCK = \u540C\u6B65\u7740\u65F6\u949F
|
||||||
|
Loading…
x
Reference in New Issue
Block a user