From b975a0227ab66debded47a58650c4b3329a70eee Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Fri, 3 Dec 2021 15:29:50 +0800 Subject: [PATCH] feat: update SelfAdaptiveShardingExecutor update SelfAdaptiveShardingExecutor to add height to the blocks; update cmstop.sh to not print error message when process doesn't exits --- script/cmstop.sh | 2 +- .../server/action/p2p/MasterClientRecoverMechAction.java | 2 +- .../org/bdware/server/doip/ContractRepoConfigurer.java | 6 +++--- .../server/trustedmodel/SelfAdaptiveShardingExecutor.java | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/script/cmstop.sh b/script/cmstop.sh index 56b5cd9..7bbaf90 100755 --- a/script/cmstop.sh +++ b/script/cmstop.sh @@ -2,7 +2,7 @@ if [ -a "./PID" ]; then if [ -d '/proc' ]; then - ls /proc/$(cat PID)/cmdline + ls /proc/$(cat PID)/cmdline 1>/dev/null 2>/dev/null if [ $? -eq 0 ]; then kill -9 $(cat PID) echo "shutdown old contract manager" diff --git a/src/main/java/org/bdware/server/action/p2p/MasterClientRecoverMechAction.java b/src/main/java/org/bdware/server/action/p2p/MasterClientRecoverMechAction.java index 722cb8f..d245e13 100644 --- a/src/main/java/org/bdware/server/action/p2p/MasterClientRecoverMechAction.java +++ b/src/main/java/org/bdware/server/action/p2p/MasterClientRecoverMechAction.java @@ -588,7 +588,7 @@ public class MasterClientRecoverMechAction { try { FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); - String line = ""; + String line; String[] arrs = null; while ((line = br.readLine()) != null) { content[count++] = line; diff --git a/src/main/java/org/bdware/server/doip/ContractRepoConfigurer.java b/src/main/java/org/bdware/server/doip/ContractRepoConfigurer.java index db10011..d29129e 100644 --- a/src/main/java/org/bdware/server/doip/ContractRepoConfigurer.java +++ b/src/main/java/org/bdware/server/doip/ContractRepoConfigurer.java @@ -79,9 +79,9 @@ public class ContractRepoConfigurer implements DoipServiceInfoConfigurer { doipServiceConfig = localConfig; //异步注册 ContractManager.threadPool.execute(() -> { - GlobalIrpClient.useInternalIrpClient(GlobalCertifications.localKeypair - , GlobalConfigurations.User_Handle - , GlobalConfigurations.LHS_Address); + GlobalIrpClient.useInternalIrpClient(GlobalCertifications.localKeypair, + GlobalConfigurations.User_Handle, + GlobalConfigurations.LHS_Address); if (doipServiceInfo.id.equals("")) { try { doipServiceInfo.id = GlobalIrpClient.getGlobalClient().register(doipServiceInfo.toServiceHandleRecord()); diff --git a/src/main/java/org/bdware/server/trustedmodel/SelfAdaptiveShardingExecutor.java b/src/main/java/org/bdware/server/trustedmodel/SelfAdaptiveShardingExecutor.java index 4292234..c3770fc 100644 --- a/src/main/java/org/bdware/server/trustedmodel/SelfAdaptiveShardingExecutor.java +++ b/src/main/java/org/bdware/server/trustedmodel/SelfAdaptiveShardingExecutor.java @@ -187,7 +187,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor { block.requests.length, block.hash)); // TODO create check point - this.b = new Block(block.hash); + this.b = new Block(block.hash, this.b.height + 1); executedBlocks.add(block.hash); } @@ -228,6 +228,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor { static class Block extends SM2Verifiable { String prevHash = "0"; String hash; + int height; String checkPoint; String body; String nodePubKey; @@ -235,10 +236,12 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor { long timestamp; public Block() { + this.height = 0; } - public Block(String prev) { + public Block(String prev, int height) { this.prevHash = prev; + this.height = height; } public void fillBlock(ContractRequest[] requests) { @@ -255,6 +258,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor { private String computeHash() { return HashUtil.sha3( + String.valueOf(this.height), this.prevHash, this.checkPoint, this.body);