Search in sources :

Example 6 with QuorumCertificate

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

the class Pacemaker method generateProposal.

private Optional<Proposal> generateProposal(View view) {
    final HighQC highQC = this.latestViewUpdate.getHighQC();
    final QuorumCertificate highestQC = highQC.highestQC();
    final List<Txn> nextTxns;
    // TODO: Remove isEndOfEpoch knowledge from consensus
    if (highestQC.getProposed().getLedgerHeader().isEndOfEpoch()) {
        nextTxns = List.of();
    } else {
        final List<PreparedVertex> preparedVertices = vertexStore.getPathFromRoot(highestQC.getProposed().getVertexId());
        nextTxns = nextTxnsGenerator.generateNextTxns(view, preparedVertices);
        systemCounters.add(SystemCounters.CounterType.BFT_PACEMAKER_PROPOSED_TRANSACTIONS, nextTxns.size());
    }
    final UnverifiedVertex proposedVertex = UnverifiedVertex.create(highestQC, view, nextTxns, self);
    final VerifiedVertex verifiedVertex = new VerifiedVertex(proposedVertex, hasher.hash(proposedVertex));
    return safetyRules.signProposal(verifiedVertex, highQC.highestCommittedQC(), highQC.highestTC());
}
Also used : HighQC(com.radixdlt.consensus.HighQC) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) PreparedVertex(com.radixdlt.consensus.bft.PreparedVertex) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Txn(com.radixdlt.atom.Txn) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex)

Example 7 with QuorumCertificate

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

the class ConsensusModuleTest method on_sync_request_timeout_should_retry.

@Test
public void on_sync_request_timeout_should_retry() {
    // Arrange
    BFTNode bftNode = BFTNode.random();
    QuorumCertificate parent = vertexStore.highQC().highestQC();
    Pair<QuorumCertificate, VerifiedVertex> nextVertex = createNextVertex(parent, bftNode);
    HighQC unsyncedHighQC = HighQC.from(nextVertex.getFirst(), nextVertex.getFirst(), Optional.empty());
    bftSync.syncToQC(unsyncedHighQC, bftNode);
    GetVerticesRequest request = new GetVerticesRequest(nextVertex.getSecond().getId(), 1);
    VertexRequestTimeout timeout = VertexRequestTimeout.create(request);
    // Act
    // FIXME: Remove when rate limit on send removed
    nothrowSleep(100);
    bftSync.vertexRequestTimeoutEventProcessor().process(timeout);
    // Assert
    verify(requestSender, times(2)).dispatch(eq(bftNode), argThat(r -> r.getCount() == 1 && r.getVertexId().equals(nextVertex.getSecond().getId())));
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) Module(com.google.inject.Module) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) GetVerticesRequest(com.radixdlt.consensus.sync.GetVerticesRequest) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Inject(com.google.inject.Inject) PacemakerTimeout(com.radixdlt.consensus.bft.PacemakerTimeout) Hasher(com.radixdlt.crypto.Hasher) HashSigner(com.radixdlt.consensus.HashSigner) TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) VertexRequestTimeout(com.radixdlt.consensus.sync.VertexRequestTimeout) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) Map(java.util.Map) ViewQuorumReached(com.radixdlt.consensus.bft.ViewQuorumReached) LedgerProof(com.radixdlt.consensus.LedgerProof) View(com.radixdlt.consensus.bft.View) HashUtils(com.radixdlt.crypto.HashUtils) SystemCounters(com.radixdlt.counters.SystemCounters) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) PersistentSafetyStateStore(com.radixdlt.consensus.safety.PersistentSafetyStateStore) Sha256Hasher(com.radixdlt.consensus.Sha256Hasher) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) BFTRebuildUpdate(com.radixdlt.consensus.bft.BFTRebuildUpdate) LedgerHeader(com.radixdlt.consensus.LedgerHeader) List(java.util.List) Stream(java.util.stream.Stream) BFTHighQCUpdate(com.radixdlt.consensus.bft.BFTHighQCUpdate) PacemakerMaxExponent(com.radixdlt.consensus.bft.PacemakerMaxExponent) Optional(java.util.Optional) ECDSASignature.zeroSignature(com.radixdlt.crypto.ECDSASignature.zeroSignature) TypeLiteral(com.google.inject.TypeLiteral) BFTSyncPatienceMillis(com.radixdlt.consensus.sync.BFTSyncPatienceMillis) Mockito.mock(org.mockito.Mockito.mock) HighQC(com.radixdlt.consensus.HighQC) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) Proposal(com.radixdlt.consensus.Proposal) LocalTimeoutOccurrence(com.radixdlt.consensus.liveness.LocalTimeoutOccurrence) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) NextTxnsGenerator(com.radixdlt.consensus.liveness.NextTxnsGenerator) BFTSync(com.radixdlt.consensus.sync.BFTSync) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) VertexStore(com.radixdlt.consensus.bft.VertexStore) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) BFTValidator(com.radixdlt.consensus.bft.BFTValidator) ImmutableList(com.google.common.collect.ImmutableList) Vote(com.radixdlt.consensus.Vote) TimestampedECDSASignature(com.radixdlt.consensus.TimestampedECDSASignature) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) Ledger(com.radixdlt.consensus.Ledger) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) Txn(com.radixdlt.atom.Txn) Mockito.times(org.mockito.Mockito.times) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VerifiedVertexStoreState(com.radixdlt.consensus.bft.VerifiedVertexStoreState) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Mockito.verify(org.mockito.Mockito.verify) BFTHeader(com.radixdlt.consensus.BFTHeader) VoteData(com.radixdlt.consensus.VoteData) Provides(com.google.inject.Provides) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) ECKeyPair(com.radixdlt.crypto.ECKeyPair) NoVote(com.radixdlt.consensus.bft.NoVote) PacemakerRate(com.radixdlt.consensus.bft.PacemakerRate) Self(com.radixdlt.consensus.bft.Self) Guice(com.google.inject.Guice) BFTNode(com.radixdlt.consensus.bft.BFTNode) Pair(com.radixdlt.utils.Pair) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) LastProof(com.radixdlt.store.LastProof) GetVerticesErrorResponse(com.radixdlt.consensus.sync.GetVerticesErrorResponse) GetVerticesResponse(com.radixdlt.consensus.sync.GetVerticesResponse) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.consensus.bft.BFTNode) GetVerticesRequest(com.radixdlt.consensus.sync.GetVerticesRequest) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) VertexRequestTimeout(com.radixdlt.consensus.sync.VertexRequestTimeout) Test(org.junit.Test)

Example 8 with QuorumCertificate

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

the class ConsensusModuleTest method on_synced_to_vertex_should_request_for_parent.

@Test
public void on_synced_to_vertex_should_request_for_parent() {
    // Arrange
    BFTNode bftNode = BFTNode.random();
    QuorumCertificate parent = vertexStore.highQC().highestQC();
    Pair<QuorumCertificate, VerifiedVertex> nextVertex = createNextVertex(parent, bftNode);
    Pair<QuorumCertificate, VerifiedVertex> nextNextVertex = createNextVertex(nextVertex.getFirst(), bftNode);
    HighQC unsyncedHighQC = HighQC.from(nextNextVertex.getFirst(), nextNextVertex.getFirst(), Optional.empty());
    bftSync.syncToQC(unsyncedHighQC, bftNode);
    // Act
    // FIXME: Remove when rate limit on send removed
    nothrowSleep(100);
    GetVerticesResponse response = new GetVerticesResponse(ImmutableList.of(nextNextVertex.getSecond()));
    bftSync.responseProcessor().process(bftNode, response);
    // Assert
    verify(requestSender, times(1)).dispatch(eq(bftNode), argThat(r -> r.getCount() == 1 && r.getVertexId().equals(nextVertex.getSecond().getId())));
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) Module(com.google.inject.Module) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) GetVerticesRequest(com.radixdlt.consensus.sync.GetVerticesRequest) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Inject(com.google.inject.Inject) PacemakerTimeout(com.radixdlt.consensus.bft.PacemakerTimeout) Hasher(com.radixdlt.crypto.Hasher) HashSigner(com.radixdlt.consensus.HashSigner) TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) VertexRequestTimeout(com.radixdlt.consensus.sync.VertexRequestTimeout) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) Map(java.util.Map) ViewQuorumReached(com.radixdlt.consensus.bft.ViewQuorumReached) LedgerProof(com.radixdlt.consensus.LedgerProof) View(com.radixdlt.consensus.bft.View) HashUtils(com.radixdlt.crypto.HashUtils) SystemCounters(com.radixdlt.counters.SystemCounters) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) PersistentSafetyStateStore(com.radixdlt.consensus.safety.PersistentSafetyStateStore) Sha256Hasher(com.radixdlt.consensus.Sha256Hasher) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) BFTRebuildUpdate(com.radixdlt.consensus.bft.BFTRebuildUpdate) LedgerHeader(com.radixdlt.consensus.LedgerHeader) List(java.util.List) Stream(java.util.stream.Stream) BFTHighQCUpdate(com.radixdlt.consensus.bft.BFTHighQCUpdate) PacemakerMaxExponent(com.radixdlt.consensus.bft.PacemakerMaxExponent) Optional(java.util.Optional) ECDSASignature.zeroSignature(com.radixdlt.crypto.ECDSASignature.zeroSignature) TypeLiteral(com.google.inject.TypeLiteral) BFTSyncPatienceMillis(com.radixdlt.consensus.sync.BFTSyncPatienceMillis) Mockito.mock(org.mockito.Mockito.mock) HighQC(com.radixdlt.consensus.HighQC) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) Proposal(com.radixdlt.consensus.Proposal) LocalTimeoutOccurrence(com.radixdlt.consensus.liveness.LocalTimeoutOccurrence) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) NextTxnsGenerator(com.radixdlt.consensus.liveness.NextTxnsGenerator) BFTSync(com.radixdlt.consensus.sync.BFTSync) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) VertexStore(com.radixdlt.consensus.bft.VertexStore) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) BFTValidator(com.radixdlt.consensus.bft.BFTValidator) ImmutableList(com.google.common.collect.ImmutableList) Vote(com.radixdlt.consensus.Vote) TimestampedECDSASignature(com.radixdlt.consensus.TimestampedECDSASignature) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) Ledger(com.radixdlt.consensus.Ledger) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) Txn(com.radixdlt.atom.Txn) Mockito.times(org.mockito.Mockito.times) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VerifiedVertexStoreState(com.radixdlt.consensus.bft.VerifiedVertexStoreState) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Mockito.verify(org.mockito.Mockito.verify) BFTHeader(com.radixdlt.consensus.BFTHeader) VoteData(com.radixdlt.consensus.VoteData) Provides(com.google.inject.Provides) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) ECKeyPair(com.radixdlt.crypto.ECKeyPair) NoVote(com.radixdlt.consensus.bft.NoVote) PacemakerRate(com.radixdlt.consensus.bft.PacemakerRate) Self(com.radixdlt.consensus.bft.Self) Guice(com.google.inject.Guice) BFTNode(com.radixdlt.consensus.bft.BFTNode) Pair(com.radixdlt.utils.Pair) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) LastProof(com.radixdlt.store.LastProof) GetVerticesErrorResponse(com.radixdlt.consensus.sync.GetVerticesErrorResponse) GetVerticesResponse(com.radixdlt.consensus.sync.GetVerticesResponse) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.consensus.bft.BFTNode) GetVerticesResponse(com.radixdlt.consensus.sync.GetVerticesResponse) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Test(org.junit.Test)

Example 9 with QuorumCertificate

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

the class ConsensusModuleTest method createNextVertex.

private Pair<QuorumCertificate, VerifiedVertex> createNextVertex(QuorumCertificate parent, BFTNode bftNode, Txn txn) {
    var unverifiedVertex = UnverifiedVertex.create(parent, View.of(1), List.of(txn), bftNode);
    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));
    var voteData = new VoteData(next, parent.getProposed(), parent.getParent());
    var unsyncedQC = new QuorumCertificate(voteData, new TimestampedECDSASignatures(Map.of(bftNode, TimestampedECDSASignature.from(1, zeroSignature()))));
    return Pair.of(unsyncedQC, verifiedVertex);
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) BFTHeader(com.radixdlt.consensus.BFTHeader) AccumulatorState(com.radixdlt.ledger.AccumulatorState) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) VoteData(com.radixdlt.consensus.VoteData)

Example 10 with QuorumCertificate

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

the class VertexStoreTest method adding_a_qc_which_has_not_been_inserted_should_return_false.

@Test
public void adding_a_qc_which_has_not_been_inserted_should_return_false() {
    // Arrange
    this.nextVertex.get();
    // Act
    QuorumCertificate qc = this.nextVertex.get().getQC();
    boolean success = sut.addQC(qc);
    // Assert
    assertThat(success).isFalse();
}
Also used : QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Test(org.junit.Test)

Aggregations

QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)16 Test (org.junit.Test)11 BFTHeader (com.radixdlt.consensus.BFTHeader)9 HighQC (com.radixdlt.consensus.HighQC)9 TimestampedECDSASignatures (com.radixdlt.consensus.TimestampedECDSASignatures)8 VoteData (com.radixdlt.consensus.VoteData)8 LedgerHeader (com.radixdlt.consensus.LedgerHeader)7 BFTNode (com.radixdlt.consensus.bft.BFTNode)5 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)5 ViewUpdate (com.radixdlt.consensus.bft.ViewUpdate)5 Before (org.junit.Before)5 Txn (com.radixdlt.atom.Txn)4 Ledger (com.radixdlt.consensus.Ledger)4 UnverifiedVertex (com.radixdlt.consensus.UnverifiedVertex)4 Vote (com.radixdlt.consensus.Vote)4 View (com.radixdlt.consensus.bft.View)4 EventDispatcher (com.radixdlt.environment.EventDispatcher)4 ImmutableList (com.google.common.collect.ImmutableList)3 HashCode (com.google.common.hash.HashCode)3 Sha256Hasher (com.radixdlt.consensus.Sha256Hasher)3