Search in sources :

Example 1 with EpochView

use of com.radixdlt.consensus.epoch.EpochView in project radixdlt by radixdlt.

the class RecoveryLivenessTest method processUntilNextCommittedEmitted.

private int processUntilNextCommittedEmitted(int maxSteps) {
    var lastCommitted = this.lastCommitViewEmitted().orElse(new EpochView(0, View.genesis()));
    int count = 0;
    int senderIndex;
    do {
        if (count > maxSteps) {
            throw new IllegalStateException("Already lost liveness");
        }
        var msg = processNext();
        senderIndex = msg.value().channelId().senderIndex();
        count++;
    } while (this.lastCommitViewEmitted().stream().noneMatch(v -> v.compareTo(lastCommitted) > 0));
    return senderIndex;
}
Also used : EpochView(com.radixdlt.consensus.epoch.EpochView)

Example 2 with EpochView

use of com.radixdlt.consensus.epoch.EpochView in project radixdlt by radixdlt.

the class SafetyChecker method process.

private Optional<TestInvariantError> process(BFTNode node, VerifiedVertex vertex) {
    final EpochView epochView = EpochView.of(vertex.getParentHeader().getLedgerHeader().getEpoch(), vertex.getView());
    final VerifiedVertex currentVertexAtView = committedVertices.get(epochView);
    if (currentVertexAtView != null) {
        if (!currentVertexAtView.getId().equals(vertex.getId())) {
            return conflictingVerticesError(vertex, currentVertexAtView);
        }
    } else {
        EpochView parentEpochView = EpochView.of(vertex.getParentHeader().getLedgerHeader().getEpoch(), vertex.getParentHeader().getView());
        VerifiedVertex parent = committedVertices.get(parentEpochView);
        if (parent == null) {
            Entry<EpochView, VerifiedVertex> higherCommitted = committedVertices.higherEntry(parentEpochView);
            if (higherCommitted != null) {
                BFTHeader higherParentHeader = higherCommitted.getValue().getParentHeader();
                EpochView higherCommittedParentEpochView = EpochView.of(higherParentHeader.getLedgerHeader().getEpoch(), higherParentHeader.getView());
                if (epochView.compareTo(higherCommittedParentEpochView) > 0) {
                    return brokenChainError(vertex, higherCommitted.getValue());
                }
            }
        }
        committedVertices.put(epochView, vertex);
    }
    // Clean up old vertices so that we avoid consuming too much memory
    lastCommittedByNode.put(node, epochView);
    final EpochView lowest = nodes.stream().map(n -> lastCommittedByNode.getOrDefault(n, EpochView.of(0, View.genesis()))).reduce((v0, v1) -> v0.compareTo(v1) < 0 ? v0 : v1).orElse(EpochView.of(0, View.genesis()));
    committedVertices.headMap(lowest).clear();
    return Optional.empty();
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) EpochView(com.radixdlt.consensus.epoch.EpochView) Objects(java.util.Objects) BFTHeader(com.radixdlt.consensus.BFTHeader) List(java.util.List) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) ImmutableList(com.google.common.collect.ImmutableList) TestInvariantError(com.radixdlt.harness.simulation.TestInvariant.TestInvariantError) TreeMap(java.util.TreeMap) Map(java.util.Map) Entry(java.util.Map.Entry) BFTNode(com.radixdlt.consensus.bft.BFTNode) Optional(java.util.Optional) PreparedVertex(com.radixdlt.consensus.bft.PreparedVertex) View(com.radixdlt.consensus.bft.View) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) BFTHeader(com.radixdlt.consensus.BFTHeader) EpochView(com.radixdlt.consensus.epoch.EpochView)

Aggregations

EpochView (com.radixdlt.consensus.epoch.EpochView)2 ImmutableList (com.google.common.collect.ImmutableList)1 Inject (com.google.inject.Inject)1 BFTHeader (com.radixdlt.consensus.BFTHeader)1 BFTCommittedUpdate (com.radixdlt.consensus.bft.BFTCommittedUpdate)1 BFTNode (com.radixdlt.consensus.bft.BFTNode)1 PreparedVertex (com.radixdlt.consensus.bft.PreparedVertex)1 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)1 View (com.radixdlt.consensus.bft.View)1 TestInvariantError (com.radixdlt.harness.simulation.TestInvariant.TestInvariantError)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1 NotThreadSafe (javax.annotation.concurrent.NotThreadSafe)1