use of com.radixdlt.hotstuff.bft.VerifiedVertex 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();
}
Aggregations