Search in sources :

Example 21 with View

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

the class PacemakerStateTest method when_process_qc_for_wrong_view__then_ignored.

@Test
public void when_process_qc_for_wrong_view__then_ignored() {
    HighQC highQC = mock(HighQC.class);
    when(highQC.getHighestView()).thenReturn(View.of(1));
    // Move ahead for a bit so we can send in a QC for a lower view
    this.pacemakerState.processQC(highQCFor(View.of(0)));
    this.pacemakerState.processQC(highQCFor(View.of(1)));
    this.pacemakerState.processQC(highQCFor(View.of(2)));
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(1))));
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(2))));
    verify(viewUpdateSender, times(1)).dispatch(argThat(v -> v.getCurrentView().equals(View.of(3))));
    this.pacemakerState.processQC(highQC);
    verifyNoMoreInteractions(viewUpdateSender);
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Mockito(org.mockito.Mockito) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) View(com.radixdlt.hotstuff.bft.View) EventDispatcher(com.radixdlt.environment.EventDispatcher) Mockito.times(org.mockito.Mockito.times) HighQC(com.radixdlt.hotstuff.HighQC) Test(org.junit.Test) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) Before(org.junit.Before) Test(org.junit.Test)

Example 22 with View

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

the class PacemakerTest method when_local_timeout__then_resend_previous_vote.

@Test
public void when_local_timeout__then_resend_previous_vote() {
    View view = View.of(0);
    Vote lastVote = mock(Vote.class);
    Vote lastVoteWithTimeout = mock(Vote.class);
    ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
    when(this.safetyRules.getLastVote(view)).thenReturn(Optional.of(lastVote));
    when(this.safetyRules.timeoutVote(lastVote)).thenReturn(lastVoteWithTimeout);
    when(this.validatorSet.nodes()).thenReturn(validators);
    ViewUpdate viewUpdate = ViewUpdate.create(View.of(0), mock(HighQC.class), mock(BFTNode.class), mock(BFTNode.class));
    this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(viewUpdate, 0L));
    verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(lastVoteWithTimeout));
    verifyNoMoreInteractions(this.vertexStore);
    verify(this.safetyRules, times(1)).getLastVote(view);
    verify(this.safetyRules, times(1)).timeoutVote(lastVote);
    verifyNoMoreInteractions(this.safetyRules);
}
Also used : ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) HighQC(com.radixdlt.hotstuff.HighQC) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

Example 23 with View

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

the class WeightedRotatingLeadersTest method when_validators_distributed_by_fibonacci__then_leaders_also_distributed_in_fibonacci.

@Test
public void when_validators_distributed_by_fibonacci__then_leaders_also_distributed_in_fibonacci() {
    // fibonacci sequence can quickly explode so keep sizes small
    final int validatorSetSize = 8;
    final int sizeOfCache = 4;
    final Supplier<IntStream> fibonacci = () -> Stream.iterate(new int[] { 1, 1 }, t -> new int[] { t[1], t[0] + t[1] }).mapToInt(t -> t[0]).limit(validatorSetSize);
    final int sumOfPower = fibonacci.get().sum();
    this.validatorsInOrder = fibonacci.get().mapToObj(p -> BFTValidator.from(BFTNode.random(), UInt256.from(p))).collect(ImmutableList.toImmutableList());
    BFTValidatorSet validatorSet = BFTValidatorSet.from(validatorsInOrder);
    this.weightedRotatingLeaders = new WeightedRotatingLeaders(validatorSet, sizeOfCache);
    Map<BFTNode, UInt256> proposerCounts = Stream.iterate(View.of(0), View::next).limit(sumOfPower).map(this.weightedRotatingLeaders::getProposer).collect(groupingBy(p -> p, collectingAndThen(counting(), UInt256::from)));
    Map<BFTNode, UInt256> expected = validatorsInOrder.stream().collect(toMap(BFTValidator::getNode, BFTValidator::getPower));
    assertThat(proposerCounts).isEqualTo(expected);
}
Also used : IntStream(java.util.stream.IntStream) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Test(org.junit.Test) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) Supplier(java.util.function.Supplier) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ECKeyPair(com.radixdlt.crypto.ECKeyPair) View(com.radixdlt.hotstuff.bft.View) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) ImmutableList(com.google.common.collect.ImmutableList) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Map(java.util.Map) KeyComparator(com.radixdlt.utils.KeyComparator) Comparator(java.util.Comparator) UInt256(com.radixdlt.utils.UInt256) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) IntStream(java.util.stream.IntStream) UInt256(com.radixdlt.utils.UInt256) Test(org.junit.Test)

Example 24 with View

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

the class BFTHeaderSerializeTest method get.

private static BFTHeader get() {
    View view = View.of(1234567890L);
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    return new BFTHeader(view, HashUtils.random256(), ledgerHeader);
}
Also used : LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTHeader(com.radixdlt.hotstuff.BFTHeader) View(com.radixdlt.hotstuff.bft.View)

Aggregations

View (com.radixdlt.hotstuff.bft.View)24 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)11 Test (org.junit.Test)10 HighQC (com.radixdlt.hotstuff.HighQC)8 BFTHeader (com.radixdlt.hotstuff.BFTHeader)7 HashCode (com.google.common.hash.HashCode)6 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)6 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)5 Vote (com.radixdlt.hotstuff.Vote)5 ViewUpdate (com.radixdlt.hotstuff.bft.ViewUpdate)5 Proposal (com.radixdlt.hotstuff.Proposal)4 VoteData (com.radixdlt.hotstuff.VoteData)4 SystemCounters (com.radixdlt.counters.SystemCounters)3 EventDispatcher (com.radixdlt.environment.EventDispatcher)3 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)3 BFTInsertUpdate (com.radixdlt.hotstuff.bft.BFTInsertUpdate)3 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)3 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)3 ScheduledLocalTimeout (com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout)3 Before (org.junit.Before)3