From 36fd9fa6caf5bd7b92a790e6b11db87a48981079 Mon Sep 17 00:00:00 2001 From: leej1012 Date: Wed, 25 Dec 2024 15:43:21 +0800 Subject: [PATCH] Update getPreConsensusCount --- .../ontio/service/impl/NodesServiceImpl.java | 6 +++--- .../github/ontio/util/OntologySDKService.java | 21 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java index 4adb2be0..1e3be73d 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java @@ -1198,14 +1198,14 @@ public ResponseBean getAddressRegisterNodeList(String address) { } list.sort((o1, o2) -> { // 先按照status排序(1-在线->3-已退出->2-正在退出),status相同的情况下按照节点质押数量倒序 - int compareByPrice = Integer.compare(o1.getStatus(), o2.getStatus()); - if (compareByPrice != 0) { + int compareByStatus = Integer.compare(o1.getStatus(), o2.getStatus()); + if (compareByStatus != 0) { if (o1.getStatus() == 2 && o2.getStatus() == 3) { return 1; } else if (o1.getStatus() == 3 && o2.getStatus() == 2) { return -1; } else { - return compareByPrice; + return compareByStatus; } } else { return Long.compare(o2.getInitPos(), o1.getInitPos()); diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/util/OntologySDKService.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/util/OntologySDKService.java index 2e64033d..6160cefd 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/util/OntologySDKService.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/util/OntologySDKService.java @@ -676,7 +676,13 @@ public int getPreConsensusCount() { Configuration preConfiguration = getPreConfiguration(); return preConfiguration.K; } catch (Exception e) { - log.warn("Getting authorize info failed: {}", e.getMessage()); + log.warn("getPreConfiguration failed: {}", e.getMessage()); + try { + Configuration vbftConfiguration = getVbftConfiguration(); + return vbftConfiguration.K; + } catch (Exception e1) { + log.warn("getVbftConfiguration failed: {}", e.getMessage()); + } } return 0; } @@ -694,6 +700,19 @@ public Configuration getPreConfiguration() throws Exception { return configuration; } + public Configuration getVbftConfiguration() throws Exception { + OntSdk ontSdk = getOntSdk(); + String res = ontSdk.getConnect().getStorage(Helper.reverse(contractAddress), Helper.toHexString("vbftConfig".getBytes())); + if (res == null) { + return null; + } + Configuration configuration = new Configuration(); + ByteArrayInputStream in = new ByteArrayInputStream(Helper.hexToBytes(res)); + BinaryReader reader = new BinaryReader(in); + configuration.deserialize(reader); + return configuration; + } + public Object getTxJson(String txHash) { OntSdk ontSdk = getOntSdk(); ontSdk.setRestful(paramsConfig.MASTERNODE_RESTFUL_URL);