use of bftsmart.consensus.Epoch in project aware by bergerch.
the class Synchronizer method resumeLC.
// This method is invoked by the state transfer protocol to notify the replica
// that it can end synchronization
public void resumeLC() {
Consensus cons = execManager.getConsensus(tempLastHighestCID.getCID());
Epoch e = cons.getLastEpoch();
int ets = cons.getEts();
if (e == null || e.getTimestamp() != ets) {
e = cons.createEpoch(ets, controller);
} else {
e.clear();
}
byte[] hash = tom.computeHash(tempLastHighestCID.getDecision());
e.propValueHash = hash;
e.propValue = tempLastHighestCID.getDecision();
e.deserializedPropValue = tom.checkProposedValue(tempLastHighestCID.getDecision(), false);
finalise(tempRegency, tempLastHighestCID, tempSignedCollects, tempPropose, tempBatchSize, tempIAmLeader);
}
use of bftsmart.consensus.Epoch in project aware by bergerch.
the class ShutdownHookThread method run.
@Override
public void run() {
StringBuffer buffer = new StringBuffer();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
int lastCons = tomLayer.getLastExec();
int currentCons = tomLayer.getInExec();
Consensus c = null;
Epoch e = null;
buffer.append("\n---------- DEBUG INFO ----------\n");
buffer.append("\nCurrent time: " + sdf.format(new Date()));
buffer.append("\nCurrent leader: " + tomLayer.execManager.getCurrentLeader());
buffer.append("\nCurrent regency: " + tomLayer.getSynchronizer().getLCManager().getLastReg());
buffer.append("\n\nLast finished consensus: " + (lastCons == -1 ? "None" : lastCons));
if (lastCons > -1) {
c = tomLayer.execManager.getConsensus(lastCons);
for (TimestampValuePair rv : c.getWriteSet()) {
if (rv.getValue() != null && rv.getValue().length > 0)
rv.setHashedValue(md.digest(rv.getValue()));
}
buffer.append("\n\n\t -- Consensus state: \n\n\t\tETS=" + c.getEts() + " \n\t\tWriteSet=[" + c.getWriteSet() + "] \n\t\t(VAL,TS)=[" + c.getQuorumWrites() + "]");
e = c.getLastEpoch();
if (e != null) {
buffer.append("\n\n\t -- Epoch state: \n" + e.toString());
}
}
buffer.append("\n\nConsensus in execution: " + (currentCons == -1 ? "None" : currentCons));
c = null;
e = null;
if (currentCons > -1) {
c = tomLayer.execManager.getConsensus(currentCons);
for (TimestampValuePair rv : c.getWriteSet()) {
if (rv.getValue() != null && rv.getValue().length > 0)
rv.setHashedValue(md.digest(rv.getValue()));
}
buffer.append("\n\n\t -- Consensus state: \n\n\t\tETS=" + c.getEts() + " \n\t\tWriteSet=[" + c.getWriteSet() + "] \n\t\t(VAL,TS)=[" + c.getQuorumWrites() + "]");
e = c.getLastEpoch();
if (e != null) {
buffer.append("\n\n\t -- Epoch state: \n" + e.toString());
}
}
buffer.append("\n\n---------- ---------- ----------\n");
LoggerFactory.getLogger(this.getClass()).info(buffer.toString());
}
use of bftsmart.consensus.Epoch in project bftsmart by blockchain-jd-com.
the class ExecutionManager method isDecidable.
public boolean isDecidable(int cid) {
if (receivedOutOfContextPropose(cid)) {
Consensus cons = getConsensus(cid);
ConsensusMessage prop = outOfContextProposes.get(cons.getId());
Epoch epoch = cons.getEpoch(prop.getEpoch(), topology);
byte[] propHash = tomLayer.computeHash(prop.getValue());
List<ConsensusMessage> msgs = outOfContext.get(cid);
int countWrites = 0;
int countAccepts = 0;
if (msgs != null) {
for (ConsensusMessage msg : msgs) {
// 对于Accept类型的共识消息,需要通过getOrigPropValue取到预计算之前的提议值hash
if (msg.getEpoch() == epoch.getTimestamp() && (Arrays.equals(propHash, msg.getValue()) || Arrays.equals(propHash, msg.getOrigPropValue()))) {
if (msg.getType() == MessageFactory.WRITE)
countWrites++;
else if (msg.getType() == MessageFactory.ACCEPT)
countAccepts++;
}
}
}
if (topology.getStaticConf().isBFT()) {
return ((countWrites > (2 * topology.getCurrentViewF())) && (countAccepts > (2 * topology.getCurrentViewF())));
} else {
return (countAccepts > topology.getQuorum());
}
}
return false;
}
use of bftsmart.consensus.Epoch in project bftsmart by blockchain-jd-com.
the class ExecutionManager method preComputeRollback.
// 避免重复预计算
public void preComputeRollback(Consensus cons) {
if (cons != null && cons.getPrecomputed() && !cons.getPrecomputeCommited()) {
DefaultRecoverable defaultRecoverable = getAcceptor().getDefaultExecutor();
for (Epoch epoch : cons.getEpochs().values()) {
if (epoch != null && epoch.getBatchId() != null) {
LOGGER.info("I am proc {}, pre compute rollback occur!, cid = {}, epoch = {}", topology.getStaticConf().getProcessId(), cons.getId(), epoch.getTimestamp());
defaultRecoverable.preComputeRollback(cons.getId(), epoch.getBatchId());
}
}
cons.setPrecomputed(false);
}
}
use of bftsmart.consensus.Epoch in project bftsmart by blockchain-jd-com.
the class Synchronizer method resumeLC.
// This method is invoked by the state transfer protocol to notify the replica
// that it can end synchronization
public void resumeLC() {
Consensus cons = execManager.getConsensus(tempLastHighestCID.getCID());
Epoch e = cons.getLastEpoch();
int ets = cons.getEts();
if (e == null || e.getTimestamp() != ets) {
e = cons.createEpoch(ets, controller);
} else {
e.clear();
}
byte[] hash = tom.computeHash(tempLastHighestCID.getDecision());
e.propValueHash = hash;
e.propValue = tempLastHighestCID.getDecision();
e.deserializedPropValue = tom.checkProposedValue(tempLastHighestCID.getDecision(), false);
finalise(tempRegency, tempLastHighestCID, tempSignedCollects, tempPropose, tempBatchSize, tempIAmLeader);
}
Aggregations