Search in sources :

Example 21 with BFTHeader

use of com.radixdlt.hotstuff.BFTHeader 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.hotstuff.bft.VerifiedVertex) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) EpochView(com.radixdlt.hotstuff.epoch.EpochView) BFTHeader(com.radixdlt.hotstuff.BFTHeader) ImmutableSet(com.google.common.collect.ImmutableSet) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Objects(java.util.Objects) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) View(com.radixdlt.hotstuff.bft.View) 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) Optional(java.util.Optional) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) BFTHeader(com.radixdlt.hotstuff.BFTHeader) EpochView(com.radixdlt.hotstuff.epoch.EpochView)

Example 22 with BFTHeader

use of com.radixdlt.hotstuff.BFTHeader in project radixdlt by radixdlt.

the class BFTHeaderSerializeTest method get.

private static BFTHeader get() {
    View view = View.of(1234567890L);
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    return new BFTHeader(view, HashUtils.random256(), ledgerHeader);
}
Also used : LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTHeader(com.radixdlt.hotstuff.BFTHeader) View(com.radixdlt.hotstuff.bft.View)

Aggregations

BFTHeader (com.radixdlt.hotstuff.BFTHeader)22 Test (org.junit.Test)12 View (com.radixdlt.hotstuff.bft.View)11 VoteData (com.radixdlt.hotstuff.VoteData)10 HighQC (com.radixdlt.hotstuff.HighQC)9 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)9 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)9 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)8 Vote (com.radixdlt.hotstuff.Vote)8 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)8 HashCode (com.google.common.hash.HashCode)5 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)4 Builder (com.radixdlt.hotstuff.safety.SafetyState.Builder)4 PreparedVertex (com.radixdlt.hotstuff.bft.PreparedVertex)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Inject (com.google.inject.Inject)1 Hasher (com.radixdlt.crypto.Hasher)1 EventDispatcher (com.radixdlt.environment.EventDispatcher)1 TestInvariantError (com.radixdlt.harness.simulation.TestInvariant.TestInvariantError)1