From 7efdeff5bc1c03f6d69e2552727891400780a2b3 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Fri, 26 Nov 2021 15:54:34 +0800 Subject: [PATCH] fix: fix bugs in event mechanism fix bugs in event delivering cross nodes --- .../client/NodeCenterClientController.java | 4 ++-- .../SelfAdaptiveShardingExecutor.java | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/bdware/server/nodecenter/client/NodeCenterClientController.java b/src/main/java/org/bdware/server/nodecenter/client/NodeCenterClientController.java index 6c134ce..a635ac3 100644 --- a/src/main/java/org/bdware/server/nodecenter/client/NodeCenterClientController.java +++ b/src/main/java/org/bdware/server/nodecenter/client/NodeCenterClientController.java @@ -271,8 +271,8 @@ public class NodeCenterClientController implements NodeCenterConn { } @Action(async = true) - public void receiveEMsg(JsonObject jo, ResultCallback cb) { - CMActions.manager.deliverEMessage( + public void deliverEvent(JsonObject jo, ResultCallback cb) { + CMActions.manager.deliverEvent( JsonUtil.fromJson(jo.get("data").getAsString(), REvent.class)); } diff --git a/src/main/java/org/bdware/server/trustedmodel/SelfAdaptiveShardingExecutor.java b/src/main/java/org/bdware/server/trustedmodel/SelfAdaptiveShardingExecutor.java index eb31fde..4292234 100644 --- a/src/main/java/org/bdware/server/trustedmodel/SelfAdaptiveShardingExecutor.java +++ b/src/main/java/org/bdware/server/trustedmodel/SelfAdaptiveShardingExecutor.java @@ -9,6 +9,7 @@ import org.bdware.sc.ContractManager; import org.bdware.sc.ContractResult; import org.bdware.sc.bean.ContractRequest; import org.bdware.sc.bean.FunctionDesp; +import org.bdware.sc.bean.SM2Verifiable; import org.bdware.sc.conn.OnHashCallback; import org.bdware.sc.conn.ResultCallback; import org.bdware.sc.units.MultiContractMeta; @@ -224,11 +225,12 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor { return this.b; } - static class Block { + static class Block extends SM2Verifiable { String prevHash = "0"; String hash; String checkPoint; String body; + String nodePubKey; ContractRequest[] requests; long timestamp; @@ -244,10 +246,11 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor { this.timestamp = System.currentTimeMillis(); this.body = merkle(requests); this.hash = computeHash(); + doSignature(CMActions.manager.nodeCenterConn.getNodeKeyPair()); } public boolean isValid() { - return computeHash().equals(hash) && body.equals(merkle(this.requests)); + return computeHash().equals(hash) && body.equals(merkle(this.requests)) && verifySignature(); } private String computeHash() { @@ -280,5 +283,19 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor { return reqQueue.poll(); } + @Override + public String getPublicKey() { + return nodePubKey; + } + + @Override + public void setPublicKey(String pubkey) { + this.nodePubKey = pubkey; + } + + @Override + public String getContentStr() { + return this.hash; + } } }