Search in sources :

Example 16 with QuorumCertificate

use of com.radixdlt.hotstuff.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.hotstuff.HighQC) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Txn(com.radixdlt.atom.Txn) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex)

Example 17 with QuorumCertificate

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

the class MockedStateComputer method commit.

@Override
public void commit(VerifiedTxnsAndProof txnsAndProof, VerifiedVertexStoreState vertexStoreState) {
    var output = txnsAndProof.getProof().getNextValidatorSet().map(validatorSet -> {
        LedgerProof header = txnsAndProof.getProof();
        UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header.getRaw());
        VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
        LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
        QuorumCertificate genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
        final var initialState = VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher);
        var proposerElection = new WeightedRotatingLeaders(validatorSet);
        var bftConfiguration = new BFTConfiguration(proposerElection, validatorSet, initialState);
        return new EpochChange(header, bftConfiguration);
    }).map(e -> ImmutableClassToInstanceMap.<Object, EpochChange>of(EpochChange.class, e)).orElse(ImmutableClassToInstanceMap.of());
    var ledgerUpdate = new LedgerUpdate(txnsAndProof, output);
    ledgerUpdateDispatcher.dispatch(ledgerUpdate);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Inject(com.google.inject.Inject) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) MempoolAdd(com.radixdlt.mempool.MempoolAdd) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) View(com.radixdlt.hotstuff.bft.View) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) Map(java.util.Map) MockPrepared(com.radixdlt.ledger.MockPrepared) Nullable(javax.annotation.Nullable) EventDispatcher(com.radixdlt.environment.EventDispatcher) Txn(com.radixdlt.atom.Txn) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) EpochChange(com.radixdlt.hotstuff.epoch.EpochChange) Collectors(java.util.stream.Collectors) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) StateComputerLedger(com.radixdlt.ledger.StateComputerLedger) List(java.util.List) Optional(java.util.Optional) ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) EpochChange(com.radixdlt.hotstuff.epoch.EpochChange) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) LedgerProof(com.radixdlt.hotstuff.LedgerProof) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)

Example 18 with QuorumCertificate

use of com.radixdlt.hotstuff.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.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 19 with QuorumCertificate

use of com.radixdlt.hotstuff.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
    QuorumCertificate parent = vertexStore.highQC().highestQC();
    Pair<QuorumCertificate, VerifiedVertex> nextVertex = createNextVertex(parent, validatorKeyPair);
    HighQC unsyncedHighQC = HighQC.from(nextVertex.getFirst(), nextVertex.getFirst(), Optional.empty());
    bftSync.syncToQC(unsyncedHighQC, validatorBftNode);
    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(validatorBftNode), argThat(r -> r.getCount() == 1 && r.getVertexId().equals(nextVertex.getSecond().getId())));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) Module(com.google.inject.Module) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Inject(com.google.inject.Inject) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) Ledger(com.radixdlt.hotstuff.Ledger) Map(java.util.Map) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) HashUtils(com.radixdlt.crypto.HashUtils) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) SystemCounters(com.radixdlt.counters.SystemCounters) Vote(com.radixdlt.hotstuff.Vote) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) List(java.util.List) Stream(java.util.stream.Stream) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) Optional(java.util.Optional) TypeLiteral(com.google.inject.TypeLiteral) Proposal(com.radixdlt.hotstuff.Proposal) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) Mockito.mock(org.mockito.Mockito.mock) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) HashSigner(com.radixdlt.hotstuff.HashSigner) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) VertexStore(com.radixdlt.hotstuff.bft.VertexStore) View(com.radixdlt.hotstuff.bft.View) ImmutableList(com.google.common.collect.ImmutableList) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) BFTSync(com.radixdlt.hotstuff.sync.BFTSync) BFTHeader(com.radixdlt.hotstuff.BFTHeader) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) NoVote(com.radixdlt.hotstuff.bft.NoVote) Txn(com.radixdlt.atom.Txn) VoteData(com.radixdlt.hotstuff.VoteData) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) TimestampedECDSASignature(com.radixdlt.hotstuff.TimestampedECDSASignature) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) Pair(com.radixdlt.utils.Pair) LastProof(com.radixdlt.store.LastProof) AbstractModule(com.google.inject.AbstractModule) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) Test(org.junit.Test)

Example 20 with QuorumCertificate

use of com.radixdlt.hotstuff.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, validatorKeyPair);
    Pair<QuorumCertificate, VerifiedVertex> nextNextVertex = createNextVertex(nextVertex.getFirst(), validatorKeyPair);
    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.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) Module(com.google.inject.Module) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Inject(com.google.inject.Inject) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) Ledger(com.radixdlt.hotstuff.Ledger) Map(java.util.Map) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) HashUtils(com.radixdlt.crypto.HashUtils) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) SystemCounters(com.radixdlt.counters.SystemCounters) Vote(com.radixdlt.hotstuff.Vote) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) List(java.util.List) Stream(java.util.stream.Stream) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) Optional(java.util.Optional) TypeLiteral(com.google.inject.TypeLiteral) Proposal(com.radixdlt.hotstuff.Proposal) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) Mockito.mock(org.mockito.Mockito.mock) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.hotstuff.Sha256Hasher) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) HashSigner(com.radixdlt.hotstuff.HashSigner) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) VertexStore(com.radixdlt.hotstuff.bft.VertexStore) View(com.radixdlt.hotstuff.bft.View) ImmutableList(com.google.common.collect.ImmutableList) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) BFTSync(com.radixdlt.hotstuff.sync.BFTSync) BFTHeader(com.radixdlt.hotstuff.BFTHeader) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) NoVote(com.radixdlt.hotstuff.bft.NoVote) Txn(com.radixdlt.atom.Txn) VoteData(com.radixdlt.hotstuff.VoteData) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) TimestampedECDSASignature(com.radixdlt.hotstuff.TimestampedECDSASignature) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) Pair(com.radixdlt.utils.Pair) LastProof(com.radixdlt.store.LastProof) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) 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