Search in sources :

Example 6 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex 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 7 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.

the class EpochManagerTest method getExternalModule.

private Module getExternalModule() {
    BFTNode self = BFTNode.create(ecKeyPair.getPublicKey());
    return new AbstractModule() {

        @Override
        protected void configure() {
            bind(HashSigner.class).toInstance(ecKeyPair::sign);
            bind(BFTNode.class).annotatedWith(Self.class).toInstance(self);
            bind(new TypeLiteral<EventDispatcher<LocalTimeoutOccurrence>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTInsertUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTRebuildUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTHighQCUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTCommittedUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<EpochLocalTimeoutOccurrence>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<EpochView>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LocalSyncRequest>>() {
            }).toInstance(syncLedgerRequestSender);
            bind(new TypeLiteral<EventDispatcher<ViewQuorumReached>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<EpochViewUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<ViewUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<NoVote>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(timeoutScheduler);
            bind(new TypeLiteral<ScheduledEventDispatcher<ScheduledLocalTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<Epoched<ScheduledLocalTimeout>>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<VertexRequestTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<Proposal>>() {
            }).toInstance(proposalDispatcher);
            bind(new TypeLiteral<RemoteEventDispatcher<Vote>>() {
            }).toInstance(voteDispatcher);
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesResponse>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesErrorResponse>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<LedgerStatusUpdate>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(PersistentSafetyStateStore.class).toInstance(mock(PersistentSafetyStateStore.class));
            bind(NextTxnsGenerator.class).toInstance(nextTxnsGenerator);
            bind(SystemCounters.class).toInstance(new SystemCountersImpl());
            bind(Mempool.class).toInstance(mempool);
            bind(StateComputer.class).toInstance(stateComputer);
            bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
            bind(RateLimiter.class).annotatedWith(GetVerticesRequestRateLimit.class).toInstance(RateLimiter.create(Double.MAX_VALUE));
            bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(50);
            bindConstant().annotatedWith(PacemakerTimeout.class).to(10L);
            bindConstant().annotatedWith(PacemakerRate.class).to(2.0);
            bindConstant().annotatedWith(PacemakerMaxExponent.class).to(0);
            bind(TimeSupplier.class).toInstance(System::currentTimeMillis);
            bind(new TypeLiteral<Consumer<EpochViewUpdate>>() {
            }).toInstance(rmock(Consumer.class));
        }

        @Provides
        private ViewUpdate view(BFTConfiguration bftConfiguration) {
            HighQC highQC = bftConfiguration.getVertexStoreState().getHighQC();
            View view = highQC.highestQC().getView().next();
            return ViewUpdate.create(view, highQC, self, self);
        }

        @Provides
        BFTValidatorSet validatorSet() {
            return BFTValidatorSet.from(Stream.of(BFTValidator.from(self, UInt256.ONE)));
        }

        @Provides
        @LastProof
        LedgerProof verifiedLedgerHeaderAndProof(BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            return LedgerProof.genesis(accumulatorState, validatorSet, 0);
        }

        @Provides
        @LastEpochProof
        LedgerProof lastEpochProof(BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            return LedgerProof.genesis(accumulatorState, validatorSet, 0);
        }

        @Provides
        BFTConfiguration bftConfiguration(@Self BFTNode self, Hasher hasher, BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            var unverifiedVertex = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, validatorSet, 0));
            var verifiedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
            var qc = QuorumCertificate.ofGenesis(verifiedVertex, LedgerHeader.genesis(accumulatorState, validatorSet, 0));
            var proposerElection = new WeightedRotatingLeaders(validatorSet);
            return new BFTConfiguration(proposerElection, validatorSet, VerifiedVertexStoreState.create(HighQC.from(qc), verifiedVertex, Optional.empty(), hasher));
        }
    };
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Consumer(java.util.function.Consumer) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) Mempool(com.radixdlt.mempool.Mempool) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) NoVote(com.radixdlt.hotstuff.bft.NoVote) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) HashSigner(com.radixdlt.hotstuff.HashSigner) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) Hasher(com.radixdlt.crypto.Hasher) NoVote(com.radixdlt.hotstuff.bft.NoVote) Proposal(com.radixdlt.hotstuff.Proposal) LedgerStatusUpdate(com.radixdlt.sync.messages.remote.LedgerStatusUpdate) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) EpochLocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.EpochLocalTimeoutOccurrence) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Self(com.radixdlt.hotstuff.bft.Self) TimeSupplier(com.radixdlt.utils.TimeSupplier) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) EpochLocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.EpochLocalTimeoutOccurrence) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) EventDispatcher(com.radixdlt.environment.EventDispatcher) TypeLiteral(com.google.inject.TypeLiteral) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) SystemCounters(com.radixdlt.counters.SystemCounters) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) View(com.radixdlt.hotstuff.bft.View) AbstractModule(com.google.inject.AbstractModule) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore)

Example 8 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.

the class PacemakerTest method when_local_timeout__then_send_empty_vote_if_no_previous.

@Test
public void when_local_timeout__then_send_empty_vote_if_no_previous() {
    HighQC viewUpdateHighQc = mock(HighQC.class);
    QuorumCertificate committedQc = mock(QuorumCertificate.class);
    QuorumCertificate highestQc = mock(QuorumCertificate.class);
    when(viewUpdateHighQc.highestCommittedQC()).thenReturn(committedQc);
    when(viewUpdateHighQc.highestQC()).thenReturn(highestQc);
    BFTHeader highestQcProposed = mock(BFTHeader.class);
    HashCode highQcParentVertexId = mock(HashCode.class);
    when(highestQcProposed.getVertexId()).thenReturn(highQcParentVertexId);
    when(highestQc.getProposed()).thenReturn(highestQcProposed);
    when(committedQc.getView()).thenReturn(View.of(0));
    ViewUpdate viewUpdate = ViewUpdate.create(View.of(1), viewUpdateHighQc, mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker.processViewUpdate(viewUpdate);
    View view = View.of(1);
    Vote emptyVote = mock(Vote.class);
    Vote emptyVoteWithTimeout = mock(Vote.class);
    ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
    BFTHeader bftHeader = mock(BFTHeader.class);
    HighQC highQC = mock(HighQC.class);
    BFTInsertUpdate bftInsertUpdate = mock(BFTInsertUpdate.class);
    when(bftInsertUpdate.getHeader()).thenReturn(bftHeader);
    PreparedVertex preparedVertex = mock(PreparedVertex.class);
    when(preparedVertex.getView()).thenReturn(view);
    when(preparedVertex.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
    VerifiedVertexStoreState vertexStoreState = mock(VerifiedVertexStoreState.class);
    when(vertexStoreState.getHighQC()).thenReturn(highQC);
    when(bftInsertUpdate.getInserted()).thenReturn(preparedVertex);
    when(bftInsertUpdate.getVertexStoreState()).thenReturn(vertexStoreState);
    var node = BFTNode.random();
    when(preparedVertex.getId()).thenReturn(hasher.hash(UnverifiedVertex.createTimeout(highestQc, view, node)));
    when(this.safetyRules.getLastVote(view)).thenReturn(Optional.empty());
    when(this.safetyRules.createVote(any(), any(), anyLong(), any())).thenReturn(emptyVote);
    when(this.safetyRules.timeoutVote(emptyVote)).thenReturn(emptyVoteWithTimeout);
    when(this.validatorSet.nodes()).thenReturn(validators);
    when(this.vertexStore.getPreparedVertex(any())).thenReturn(Optional.empty());
    this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(ViewUpdate.create(View.of(1), mock(HighQC.class), node, BFTNode.random()), 0L));
    this.pacemaker.processBFTUpdate(bftInsertUpdate);
    verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(emptyVoteWithTimeout));
    verify(this.safetyRules, times(1)).getLastVote(view);
    verify(this.safetyRules, times(1)).createVote(any(), any(), anyLong(), any());
    verify(this.safetyRules, times(1)).timeoutVote(emptyVote);
    verifyNoMoreInteractions(this.safetyRules);
    verify(this.vertexStore, times(1)).getPreparedVertex(any());
    ArgumentCaptor<VerifiedVertex> insertVertexCaptor = ArgumentCaptor.forClass(VerifiedVertex.class);
    verify(this.vertexStore, times(1)).insertVertex(insertVertexCaptor.capture());
    assertEquals(insertVertexCaptor.getValue().getParentId(), highQcParentVertexId);
    verifyNoMoreInteractions(this.vertexStore);
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) View(com.radixdlt.hotstuff.bft.View) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) HashCode(com.google.common.hash.HashCode) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) Test(org.junit.Test)

Example 9 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.

the class GetVerticesErrorResponseMessageTest method sensibleToString.

@Test
public void sensibleToString() {
    VerifiedVertex verifiedVertex = mock(VerifiedVertex.class);
    when(verifiedVertex.getView()).thenReturn(View.genesis());
    when(verifiedVertex.getId()).thenReturn(HashCode.fromInt(1));
    QuorumCertificate qc = QuorumCertificate.ofGenesis(verifiedVertex, mock(LedgerHeader.class));
    HighQC highQC = HighQC.from(qc, qc, Optional.empty());
    final var request = mock(GetVerticesRequestMessage.class);
    GetVerticesErrorResponseMessage msg1 = new GetVerticesErrorResponseMessage(highQC, request);
    String s1 = msg1.toString();
    assertThat(s1).contains(GetVerticesErrorResponseMessage.class.getSimpleName());
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Test(org.junit.Test)

Example 10 with VerifiedVertex

use of com.radixdlt.hotstuff.bft.VerifiedVertex in project radixdlt by radixdlt.

the class SafetyRulesTest method when_vote_on_proposal_three_after_genesis_with_skip__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_three_after_genesis_with_skip__then_returned_vote_has_no_commit() {
    when(safetyState.getLastVotedView()).thenReturn(View.of(1));
    when(safetyState.getLockedView()).thenReturn(View.of(0));
    when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
    VerifiedVertex proposal = mock(VerifiedVertex.class);
    when(proposal.touchesGenesis()).thenReturn(false);
    when(proposal.hasDirectParent()).thenReturn(false);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(2));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(4));
    BFTHeader grandParent = mock(BFTHeader.class);
    when(grandParent.getView()).thenReturn(mock(View.class));
    when(proposal.getGrandParentHeader()).thenReturn(grandParent);
    Optional<Vote> voteMaybe = safetyRules.voteFor(proposal, mock(BFTHeader.class), 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getCommitted()).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) Vote(com.radixdlt.hotstuff.Vote) Builder(com.radixdlt.hotstuff.safety.SafetyState.Builder) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

Aggregations

VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)31 Test (org.junit.Test)19 HighQC (com.radixdlt.hotstuff.HighQC)15 View (com.radixdlt.hotstuff.bft.View)15 BFTHeader (com.radixdlt.hotstuff.BFTHeader)13 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)13 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)12 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)12 Hasher (com.radixdlt.crypto.Hasher)10 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)10 Vote (com.radixdlt.hotstuff.Vote)10 AccumulatorState (com.radixdlt.ledger.AccumulatorState)10 WeightedRotatingLeaders (com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)9 Inject (com.google.inject.Inject)8 SystemCounters (com.radixdlt.counters.SystemCounters)8 ImmutableList (com.google.common.collect.ImmutableList)7 EventDispatcher (com.radixdlt.environment.EventDispatcher)7 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)7 PreparedVertex (com.radixdlt.hotstuff.bft.PreparedVertex)7 HashUtils (com.radixdlt.crypto.HashUtils)6