Search in sources :

Example 1 with BFTValidatorSet

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

the class PendingVotesTest method when_voting_again__previous_vote_is_removed.

@Test
public void when_voting_again__previous_vote_is_removed() {
    BFTNode author = mock(BFTNode.class);
    Vote vote = makeSignedVoteFor(author, View.genesis(), HashUtils.random256());
    BFTValidatorSet validatorSet = mock(BFTValidatorSet.class);
    ValidationState validationState = mock(ValidationState.class);
    TimestampedECDSASignatures signatures = mock(TimestampedECDSASignatures.class);
    when(validationState.signatures()).thenReturn(signatures);
    when(validationState.isEmpty()).thenReturn(true);
    when(validatorSet.newValidationState()).thenReturn(validationState);
    when(validatorSet.containsNode(any(BFTNode.class))).thenReturn(true);
    VoteData voteData = mock(VoteData.class);
    BFTHeader proposed = vote.getVoteData().getProposed();
    when(voteData.getProposed()).thenReturn(proposed);
    // Preconditions
    assertEquals(VoteProcessingResult.accepted(), this.pendingVotes.insertVote(vote, validatorSet));
    assertEquals(1, this.pendingVotes.voteStateSize());
    assertEquals(1, this.pendingVotes.previousVotesSize());
    Vote vote2 = makeSignedVoteFor(author, View.of(1), HashUtils.random256());
    // Need a different hash for this (different) vote
    assertEquals(VoteProcessingResult.accepted(), this.pendingVotes.insertVote(vote2, validatorSet));
    assertEquals(1, this.pendingVotes.voteStateSize());
    assertEquals(1, this.pendingVotes.previousVotesSize());
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ValidationState(com.radixdlt.hotstuff.bft.ValidationState) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) Test(org.junit.Test)

Example 2 with BFTValidatorSet

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

the class PendingVotesTest method when_inserting_valid_but_unaccepted_votes__then_no_qc_is_returned.

@Test
public void when_inserting_valid_but_unaccepted_votes__then_no_qc_is_returned() {
    HashCode vertexId = HashUtils.random256();
    Vote vote1 = makeSignedVoteFor(mock(BFTNode.class), View.genesis(), vertexId);
    Vote vote2 = makeSignedVoteFor(mock(BFTNode.class), View.genesis(), vertexId);
    BFTValidatorSet validatorSet = BFTValidatorSet.from(Collections.singleton(BFTValidator.from(vote1.getAuthor(), UInt256.ONE)));
    VoteData voteData = mock(VoteData.class);
    BFTHeader proposed = vote1.getVoteData().getProposed();
    when(voteData.getProposed()).thenReturn(proposed);
    assertEquals(VoteProcessingResult.rejected(VoteRejectedReason.INVALID_AUTHOR), this.pendingVotes.insertVote(vote2, validatorSet));
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) HashCode(com.google.common.hash.HashCode) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) Test(org.junit.Test)

Example 3 with BFTValidatorSet

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

the class PendingVotesTest method when_inserting_valid_and_accepted_votes__then_qc_is_formed.

@Test
public void when_inserting_valid_and_accepted_votes__then_qc_is_formed() {
    BFTNode author = mock(BFTNode.class);
    Vote vote = makeSignedVoteFor(author, View.genesis(), HashUtils.random256());
    BFTValidatorSet validatorSet = mock(BFTValidatorSet.class);
    ValidationState validationState = mock(ValidationState.class);
    TimestampedECDSASignatures signatures = mock(TimestampedECDSASignatures.class);
    when(validationState.addSignature(any(), anyLong(), any())).thenReturn(true);
    when(validationState.complete()).thenReturn(true);
    when(validationState.signatures()).thenReturn(signatures);
    when(validatorSet.newValidationState()).thenReturn(validationState);
    when(validatorSet.containsNode(any(BFTNode.class))).thenReturn(true);
    VoteData voteData = mock(VoteData.class);
    BFTHeader proposed = vote.getVoteData().getProposed();
    when(voteData.getProposed()).thenReturn(proposed);
    assertTrue(this.pendingVotes.insertVote(vote, validatorSet) instanceof VoteProcessingResult.QuorumReached);
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ValidationState(com.radixdlt.hotstuff.bft.ValidationState) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) VoteProcessingResult(com.radixdlt.hotstuff.bft.VoteProcessingResult) Test(org.junit.Test)

Example 4 with BFTValidatorSet

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

the class PendingVotesTest method when_voting_again__previous_timeoutvote_is_removed.

@Test
public void when_voting_again__previous_timeoutvote_is_removed() {
    BFTNode author = mock(BFTNode.class);
    Vote vote = makeSignedVoteFor(author, View.genesis(), HashUtils.random256());
    when(vote.getTimeoutSignature()).thenReturn(Optional.of(mock(ECDSASignature.class)));
    when(vote.isTimeout()).thenReturn(true);
    BFTValidatorSet validatorSet = mock(BFTValidatorSet.class);
    ValidationState validationState = mock(ValidationState.class);
    TimestampedECDSASignatures signatures = mock(TimestampedECDSASignatures.class);
    when(validationState.signatures()).thenReturn(signatures);
    when(validationState.isEmpty()).thenReturn(true);
    when(validatorSet.newValidationState()).thenReturn(validationState);
    when(validatorSet.containsNode(any(BFTNode.class))).thenReturn(true);
    VoteData voteData = mock(VoteData.class);
    BFTHeader proposed = vote.getVoteData().getProposed();
    when(voteData.getProposed()).thenReturn(proposed);
    // Preconditions
    assertEquals(VoteProcessingResult.accepted(), this.pendingVotes.insertVote(vote, validatorSet));
    assertEquals(1, this.pendingVotes.voteStateSize());
    assertEquals(1, this.pendingVotes.timeoutVoteStateSize());
    assertEquals(1, this.pendingVotes.previousVotesSize());
    Vote vote2 = makeSignedVoteFor(author, View.of(1), HashUtils.random256());
    // Need a different hash for this (different) vote
    assertEquals(VoteProcessingResult.accepted(), this.pendingVotes.insertVote(vote2, validatorSet));
    assertEquals(1, this.pendingVotes.voteStateSize());
    assertEquals(0, this.pendingVotes.timeoutVoteStateSize());
    assertEquals(1, this.pendingVotes.previousVotesSize());
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ValidationState(com.radixdlt.hotstuff.bft.ValidationState) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) Test(org.junit.Test)

Example 5 with BFTValidatorSet

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

the class PacemakerViewUpdateRaceConditionTest method test_pacemaker_view_update_race_condition.

@Test
public void test_pacemaker_view_update_race_condition() {
    final DeterministicTest test = DeterministicTest.builder().numNodes(numNodes).messageSelector(MessageSelector.randomSelector(random)).messageMutator(messUpMessagesForNodeUnderTest()).pacemakerTimeout(pacemakerTimeout).overrideWithIncorrectModule(new AbstractModule() {

        @ProvidesIntoSet
        @ProcessOnDispatch
        private EventProcessor<BFTInsertUpdate> bftInsertUpdateProcessor() {
            final Map<HashCode, PreparedVertex> insertedVertices = new HashMap<>();
            return bftInsertUpdate -> {
                final PreparedVertex inserted = bftInsertUpdate.getInserted();
                insertedVertices.putIfAbsent(inserted.getId(), inserted);
                final Optional<PreparedVertex> maybeParent = Optional.ofNullable(insertedVertices.get(inserted.getParentId()));
                maybeParent.ifPresent(parent -> {
                    if (parent.getView().equals(inserted.getView())) {
                        throw new IllegalStateException("Vertex can't have the same view as its parent.");
                    }
                });
            };
        }

        @Provides
        public ProposerElection proposerElection(BFTValidatorSet validatorSet) {
            final var sortedValidators = validatorSet.getValidators().stream().map(BFTValidator::getNode).sorted(Comparator.comparing(BFTNode::getKey, KeyComparator.instance().reversed())).toList();
            return view -> sortedValidators.get(((int) view.number() - 1) % sortedValidators.size());
        }
    }).buildWithoutEpochs().runUntil(nodeUnderTestReachesView(View.of(3)));
    final var counters = test.getSystemCounters(nodeUnderTestIndex);
    assertThat(counters.get(SystemCounters.CounterType.BFT_VOTE_QUORUMS)).isEqualTo(// ensure that quorum was formed
    2);
    assertThat(counters.get(SystemCounters.CounterType.BFT_PACEMAKER_TIMEOUTS_SENT)).isEqualTo(// ensure that timeouts were processed
    2);
}
Also used : PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) Provides(com.google.inject.Provides) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) ProvidesIntoSet(com.google.inject.multibindings.ProvidesIntoSet) AbstractModule(com.google.inject.AbstractModule) EventProcessor(com.radixdlt.environment.EventProcessor) ProcessOnDispatch(com.radixdlt.environment.ProcessOnDispatch) HashMap(java.util.HashMap) Map(java.util.Map) ProposerElection(com.radixdlt.hotstuff.liveness.ProposerElection) Test(org.junit.Test) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest)

Aggregations

BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)11 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)10 Test (org.junit.Test)10 View (com.radixdlt.hotstuff.bft.View)4 Map (java.util.Map)4 AbstractModule (com.google.inject.AbstractModule)3 ECKeyPair (com.radixdlt.crypto.ECKeyPair)3 BFTValidator (com.radixdlt.hotstuff.bft.BFTValidator)3 ValidationState (com.radixdlt.hotstuff.bft.ValidationState)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashCode (com.google.common.hash.HashCode)2 Provides (com.google.inject.Provides)2 TypeLiteral (com.google.inject.TypeLiteral)2 SystemCounters (com.radixdlt.counters.SystemCounters)2 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)2 Hasher (com.radixdlt.crypto.Hasher)2 EventDispatcher (com.radixdlt.environment.EventDispatcher)2 RemoteEventDispatcher (com.radixdlt.environment.RemoteEventDispatcher)2 ScheduledEventDispatcher (com.radixdlt.environment.ScheduledEventDispatcher)2 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)2