Search in sources :

Example 1 with Epoch

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);
}
Also used : Epoch(bftsmart.consensus.Epoch) Consensus(bftsmart.consensus.Consensus)

Example 2 with Epoch

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());
}
Also used : TimestampValuePair(bftsmart.consensus.TimestampValuePair) Epoch(bftsmart.consensus.Epoch) SimpleDateFormat(java.text.SimpleDateFormat) Consensus(bftsmart.consensus.Consensus) Date(java.util.Date)

Example 3 with Epoch

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;
}
Also used : ConsensusMessage(bftsmart.consensus.messages.ConsensusMessage) Epoch(bftsmart.consensus.Epoch) Consensus(bftsmart.consensus.Consensus)

Example 4 with Epoch

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);
    }
}
Also used : DefaultRecoverable(bftsmart.tom.server.defaultservices.DefaultRecoverable) Epoch(bftsmart.consensus.Epoch)

Example 5 with Epoch

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);
}
Also used : Epoch(bftsmart.consensus.Epoch) Consensus(bftsmart.consensus.Consensus)

Aggregations

Epoch (bftsmart.consensus.Epoch)16 Consensus (bftsmart.consensus.Consensus)14 ConsensusMessage (bftsmart.consensus.messages.ConsensusMessage)6 Decision (bftsmart.consensus.Decision)2 TimestampValuePair (bftsmart.consensus.TimestampValuePair)2 View (bftsmart.reconfiguration.views.View)2 ApplicationState (bftsmart.statemanagement.ApplicationState)2 TOMMessage (bftsmart.tom.core.messages.TOMMessage)2 CertifiedDecision (bftsmart.tom.leaderchange.CertifiedDecision)2 CollectData (bftsmart.tom.leaderchange.CollectData)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LCTimestampStatePair (bftsmart.tom.leaderchange.LCTimestampStatePair)1 DefaultRecoverable (bftsmart.tom.server.defaultservices.DefaultRecoverable)1