Search in sources :

Example 1 with BFTNode

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

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

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

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

the class RadixEngineStateComputerTest method executing_epoch_high_view_with_register_should_not_return_new_next_validator_set.

@Test
public void executing_epoch_high_view_with_register_should_not_return_new_next_validator_set() throws Exception {
    // Arrange
    ECKeyPair keyPair = ECKeyPair.generateNew();
    var txn = registerCommand(keyPair);
    BFTNode node = BFTNode.create(keyPair.getPublicKey());
    var qc = mock(QuorumCertificate.class);
    var parentHeader = mock(BFTHeader.class);
    when(parentHeader.getView()).thenReturn(View.of(0));
    when(qc.getProposed()).thenReturn(parentHeader);
    var v = UnverifiedVertex.create(qc, View.of(11), List.of(txn), BFTNode.random());
    var vertex = new VerifiedVertex(v, mock(HashCode.class));
    // Act
    StateComputerResult result = sut.prepare(List.of(), vertex, 0);
    // Assert
    assertThat(result.getSuccessfulCommands()).hasSize(// since high view, command is not executed
    1);
    assertThat(result.getNextValidatorSet()).hasValueSatisfying(s -> {
        assertThat(s.getValidators()).hasSize(2);
        assertThat(s.getValidators()).extracting(BFTValidator::getNode).doesNotContain(node);
    });
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) HashCode(com.google.common.hash.HashCode) ECKeyPair(com.radixdlt.crypto.ECKeyPair) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Example 5 with BFTNode

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

the class LocalSyncServiceTest method when_status_response_received_at_non_sync_check__then_should_be_ignored.

@Test
public void when_status_response_received_at_non_sync_check__then_should_be_ignored() {
    final LedgerProof currentHeader = mock(LedgerProof.class);
    final LedgerProof statusHeader = mock(LedgerProof.class);
    final BFTNode sender = createPeer();
    this.setupSyncServiceWithState(SyncState.IdleState.init(currentHeader));
    this.localSyncService.statusResponseEventProcessor().process(sender, StatusResponse.create(statusHeader));
    this.setupSyncServiceWithState(SyncState.SyncingState.init(currentHeader, ImmutableList.of(), currentHeader));
    this.localSyncService.statusResponseEventProcessor().process(sender, StatusResponse.create(statusHeader));
    verifyNoMoreInteractions(peersView);
    verifyNoMoreInteractions(statusRequestDispatcher);
    verifyNoMoreInteractions(syncRequestDispatcher);
    verifyNoMoreInteractions(syncRequestTimeoutDispatcher);
}
Also used : BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerProof(com.radixdlt.hotstuff.LedgerProof) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) Test(org.junit.Test)

Aggregations

BFTNode (com.radixdlt.hotstuff.bft.BFTNode)40 Test (org.junit.Test)22 View (com.radixdlt.hotstuff.bft.View)14 LedgerProof (com.radixdlt.hotstuff.LedgerProof)9 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)9 HashCode (com.google.common.hash.HashCode)8 ECKeyPair (com.radixdlt.crypto.ECKeyPair)8 HighQC (com.radixdlt.hotstuff.HighQC)8 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)8 Vote (com.radixdlt.hotstuff.Vote)7 ImmutableList (com.google.common.collect.ImmutableList)6 AbstractModule (com.google.inject.AbstractModule)6 TypeLiteral (com.google.inject.TypeLiteral)6 BFTHeader (com.radixdlt.hotstuff.BFTHeader)6 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)6 Proposal (com.radixdlt.hotstuff.Proposal)5 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)5 BFTCommittedUpdate (com.radixdlt.hotstuff.bft.BFTCommittedUpdate)5 Self (com.radixdlt.hotstuff.bft.Self)5 Inject (com.google.inject.Inject)4