fix: fix bugs in event mechanism

fix bugs in event delivering cross nodes
This commit is contained in:
Frank.R.Wu 2021-11-26 15:54:34 +08:00
parent 789a896cca
commit 7efdeff5bc
2 changed files with 21 additions and 4 deletions

View File

@ -271,8 +271,8 @@ public class NodeCenterClientController implements NodeCenterConn {
} }
@Action(async = true) @Action(async = true)
public void receiveEMsg(JsonObject jo, ResultCallback cb) { public void deliverEvent(JsonObject jo, ResultCallback cb) {
CMActions.manager.deliverEMessage( CMActions.manager.deliverEvent(
JsonUtil.fromJson(jo.get("data").getAsString(), REvent.class)); JsonUtil.fromJson(jo.get("data").getAsString(), REvent.class));
} }

View File

@ -9,6 +9,7 @@ import org.bdware.sc.ContractManager;
import org.bdware.sc.ContractResult; import org.bdware.sc.ContractResult;
import org.bdware.sc.bean.ContractRequest; import org.bdware.sc.bean.ContractRequest;
import org.bdware.sc.bean.FunctionDesp; import org.bdware.sc.bean.FunctionDesp;
import org.bdware.sc.bean.SM2Verifiable;
import org.bdware.sc.conn.OnHashCallback; import org.bdware.sc.conn.OnHashCallback;
import org.bdware.sc.conn.ResultCallback; import org.bdware.sc.conn.ResultCallback;
import org.bdware.sc.units.MultiContractMeta; import org.bdware.sc.units.MultiContractMeta;
@ -224,11 +225,12 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
return this.b; return this.b;
} }
static class Block { static class Block extends SM2Verifiable {
String prevHash = "0"; String prevHash = "0";
String hash; String hash;
String checkPoint; String checkPoint;
String body; String body;
String nodePubKey;
ContractRequest[] requests; ContractRequest[] requests;
long timestamp; long timestamp;
@ -244,10 +246,11 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
this.timestamp = System.currentTimeMillis(); this.timestamp = System.currentTimeMillis();
this.body = merkle(requests); this.body = merkle(requests);
this.hash = computeHash(); this.hash = computeHash();
doSignature(CMActions.manager.nodeCenterConn.getNodeKeyPair());
} }
public boolean isValid() { 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() { private String computeHash() {
@ -280,5 +283,19 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
return reqQueue.poll(); 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;
}
} }
} }