Search in sources :

Example 6 with QuorumCertificate

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

the class ProposalSerializeTest method get.

private static Proposal get() {
    View view = View.of(1234567891L);
    HashCode id = HashUtils.random256();
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    BFTHeader header = new BFTHeader(view, id, ledgerHeader);
    BFTHeader parent = new BFTHeader(View.of(1234567890L), HashUtils.random256(), ledgerHeader);
    VoteData voteData = new VoteData(header, parent, null);
    QuorumCertificate qc = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
    var txn = Txn.create(new byte[] { 0, 1, 2, 3 });
    // add a particle to ensure atom is valid and has at least one shard
    BFTNode author = BFTNode.create(ECKeyPair.generateNew().getPublicKey());
    UnverifiedVertex vertex = UnverifiedVertex.create(qc, view, List.of(txn), author);
    return new Proposal(vertex, qc, ECDSASignature.zeroSignature(), Optional.empty());
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTHeader(com.radixdlt.hotstuff.BFTHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) HashCode(com.google.common.hash.HashCode) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) View(com.radixdlt.hotstuff.bft.View) VoteData(com.radixdlt.hotstuff.VoteData) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) Proposal(com.radixdlt.hotstuff.Proposal)

Example 7 with QuorumCertificate

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

the class MessageCentralValidatorSyncTest method when_send_error_response__then_message_central_will_send_error_response.

@Test
public void when_send_error_response__then_message_central_will_send_error_response() {
    QuorumCertificate qc = mock(QuorumCertificate.class);
    HighQC highQC = mock(HighQC.class);
    when(highQC.highestQC()).thenReturn(qc);
    when(highQC.highestCommittedQC()).thenReturn(qc);
    BFTNode node = mock(BFTNode.class);
    ECPublicKey ecPublicKey = mock(ECPublicKey.class);
    when(node.getKey()).thenReturn(ecPublicKey);
    final var request = new GetVerticesRequest(HashUtils.random256(), 3);
    sync.verticesErrorResponseDispatcher().dispatch(node, new GetVerticesErrorResponse(highQC, request));
    verify(messageCentral, times(1)).send(eq(NodeId.fromPublicKey(ecPublicKey)), any(GetVerticesErrorResponseMessage.class));
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) ECPublicKey(com.radixdlt.crypto.ECPublicKey) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) Test(org.junit.Test)

Example 8 with QuorumCertificate

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

the class ConsensusModuleTest method createNextVertex.

private Pair<QuorumCertificate, VerifiedVertex> createNextVertex(QuorumCertificate parent, ECKeyPair proposerKeyPair, Txn txn) {
    final var proposerBftNode = BFTNode.create(proposerKeyPair.getPublicKey());
    var unverifiedVertex = UnverifiedVertex.create(parent, View.of(1), List.of(txn), proposerBftNode);
    var hash = hasher.hash(unverifiedVertex);
    var verifiedVertex = new VerifiedVertex(unverifiedVertex, hash);
    var next = new BFTHeader(View.of(1), verifiedVertex.getId(), LedgerHeader.create(1, View.of(1), new AccumulatorState(1, HashUtils.zero256()), 1));
    final var voteData = new VoteData(next, parent.getProposed(), parent.getParent());
    final var timestamp = 1;
    final var voteDataHash = Vote.getHashOfData(hasher, voteData, timestamp);
    final var qcSignature = proposerKeyPair.sign(voteDataHash);
    var unsyncedQC = new QuorumCertificate(voteData, new TimestampedECDSASignatures(Map.of(proposerBftNode, TimestampedECDSASignature.from(timestamp, qcSignature))));
    return Pair.of(unsyncedQC, verifiedVertex);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) BFTHeader(com.radixdlt.hotstuff.BFTHeader) AccumulatorState(com.radixdlt.ledger.AccumulatorState) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) VoteData(com.radixdlt.hotstuff.VoteData)

Example 9 with QuorumCertificate

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

the class VertexStoreTest method adding_a_qc_with_commit_should_commit_vertices_to_ledger.

@Test
public void adding_a_qc_with_commit_should_commit_vertices_to_ledger() {
    // Arrange
    final var vertices = Stream.generate(this.nextVertex).limit(4).toList();
    sut.insertVertex(vertices.get(0));
    sut.insertVertex(vertices.get(1));
    sut.insertVertex(vertices.get(2));
    // Act
    QuorumCertificate qc = vertices.get(3).getQC();
    boolean success = sut.addQC(qc);
    // Assert
    assertThat(success).isTrue();
    assertThat(sut.highQC().highestQC()).isEqualTo(qc);
    assertThat(sut.highQC().highestCommittedQC()).isEqualTo(qc);
    assertThat(sut.getVertices(vertices.get(2).getId(), 3)).hasValue(ImmutableList.of(vertices.get(2), vertices.get(1), vertices.get(0)));
    verify(committedSender, times(1)).dispatch(argThat(u -> u.committed().size() == 1 && u.committed().get(0).getVertex().equals(vertices.get(0))));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) ImmutableList(com.google.common.collect.ImmutableList) Ledger(com.radixdlt.hotstuff.Ledger) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AccumulatorState(com.radixdlt.ledger.AccumulatorState) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) HashUtils(com.radixdlt.crypto.HashUtils) Before(org.junit.Before) BFTHeader(com.radixdlt.hotstuff.BFTHeader) ImmutableMap(com.google.common.collect.ImmutableMap) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) Txn(com.radixdlt.atom.Txn) VoteData(com.radixdlt.hotstuff.VoteData) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) TimeoutCertificate(com.radixdlt.hotstuff.TimeoutCertificate) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 10 with QuorumCertificate

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

the class VertexStoreTest method adding_a_qc_should_update_highest_qc.

@Test
public void adding_a_qc_should_update_highest_qc() {
    // Arrange
    final var vertices = Stream.generate(this.nextVertex).limit(4).toList();
    sut.insertVertex(vertices.get(0));
    // Act
    QuorumCertificate qc = vertices.get(1).getQC();
    sut.addQC(qc);
    // Assert
    assertThat(sut.highQC().highestQC()).isEqualTo(qc);
    assertThat(sut.highQC().highestCommittedQC()).isEqualTo(rootQC);
}
Also used : QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Aggregations

QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)25 HighQC (com.radixdlt.hotstuff.HighQC)14 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)13 Test (org.junit.Test)13 BFTHeader (com.radixdlt.hotstuff.BFTHeader)12 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)12 VoteData (com.radixdlt.hotstuff.VoteData)12 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)9 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)8 View (com.radixdlt.hotstuff.bft.View)8 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)7 EventDispatcher (com.radixdlt.environment.EventDispatcher)6 Before (org.junit.Before)6 HashCode (com.google.common.hash.HashCode)5 Txn (com.radixdlt.atom.Txn)5 ViewUpdate (com.radixdlt.hotstuff.bft.ViewUpdate)5 Hasher (com.radixdlt.crypto.Hasher)4 Ledger (com.radixdlt.hotstuff.Ledger)4 Proposal (com.radixdlt.hotstuff.Proposal)4 VerifiedVertexStoreState (com.radixdlt.hotstuff.bft.VerifiedVertexStoreState)4