Search in sources :

Example 11 with VerifiedVertex

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

the class SafetyRulesTest method when_vote_with_qc_on_different_locked_view__then_exception_is_thrown.

@Test
public void when_vote_with_qc_on_different_locked_view__then_exception_is_thrown() {
    Hasher hasher = mock(Hasher.class);
    when(hasher.hash(any())).thenReturn(mock(HashCode.class));
    HashSigner hashSigner = mock(HashSigner.class);
    when(hashSigner.sign(any(HashCode.class))).thenReturn(ECDSASignature.zeroSignature());
    Vote lastVote = mock(Vote.class);
    when(lastVote.getView()).thenReturn(View.of(1));
    final var hashVerifier = mock(HashVerifier.class);
    final var validatorSet = mock(BFTValidatorSet.class);
    final var safetyRules = new SafetyRules(BFTNode.random(), new SafetyState(View.of(2), Optional.of(lastVote)), mock(PersistentSafetyStateStore.class), hasher, hashSigner, hashVerifier, validatorSet);
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.getView()).thenReturn(View.of(3));
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(0));
    when(vertex.getParentHeader()).thenReturn(parent);
    assertThat(safetyRules.voteFor(vertex, mock(BFTHeader.class), 0L, mock(HighQC.class))).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) Hasher(com.radixdlt.crypto.Hasher) Vote(com.radixdlt.hotstuff.Vote) HashCode(com.google.common.hash.HashCode) HashSigner(com.radixdlt.hotstuff.HashSigner) Test(org.junit.Test)

Example 12 with VerifiedVertex

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

the class SafetyRulesTest method when_vote_on_same_view__then_exception_is_thrown.

@Test
public void when_vote_on_same_view__then_exception_is_thrown() {
    View view = mock(View.class);
    when(view.lte(view)).thenReturn(true);
    when(safetyState.getLastVotedView()).thenReturn(view);
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.getView()).thenReturn(view);
    assertThat(this.safetyRules.voteFor(vertex, mock(BFTHeader.class), 0L, mock(HighQC.class))).isEmpty();
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) BFTHeader(com.radixdlt.hotstuff.BFTHeader) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

Example 13 with VerifiedVertex

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

the class StateComputerLedgerTest method genesisIsEndOfEpoch.

public void genesisIsEndOfEpoch(boolean endOfEpoch) {
    this.ledgerHeader = LedgerHeader.create(genesisEpoch, View.of(5), new AccumulatorState(genesisStateVersion, HashUtils.zero256()), 12345, endOfEpoch ? BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE))) : null);
    this.genesis = UnverifiedVertex.createGenesis(ledgerHeader);
    this.genesisVertex = new VerifiedVertex(genesis, hasher.hash(genesis));
    this.genesisQC = QuorumCertificate.ofGenesis(genesisVertex, ledgerHeader);
    this.currentLedgerHeader = this.genesisQC.getCommittedAndLedgerStateProof(hasher).map(Pair::getSecond).orElseThrow();
    this.sut = new StateComputerLedger(mock(TimeSupplier.class), currentLedgerHeader, headerComparator, stateComputer, accumulator, accumulatorVerifier, counters);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Pair(com.radixdlt.utils.Pair)

Example 14 with VerifiedVertex

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

the class StateComputerLedgerTest method should_not_change_header_when_past_end_of_epoch_even_with_command.

@Test
public void should_not_change_header_when_past_end_of_epoch_even_with_command() {
    // Arrange
    genesisIsEndOfEpoch(true);
    when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(successfulNextCommand), ImmutableMap.of()));
    var unverifiedVertex = UnverifiedVertex.create(genesisQC, View.of(1), List.of(nextTxn), BFTNode.random());
    var proposedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
    // Act
    Optional<PreparedVertex> nextPrepared = sut.prepare(new LinkedList<>(), proposedVertex);
    // Assert
    assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().isEndOfEpoch()).isTrue());
    assertThat(nextPrepared).hasValueSatisfying(x -> assertThat(x.getLedgerHeader().getAccumulatorState()).isEqualTo(ledgerHeader.getAccumulatorState()));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) PreparedVertex(com.radixdlt.hotstuff.bft.PreparedVertex) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Example 15 with VerifiedVertex

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

the class GetVerticesErrorResponseMessageSerializeTest method get.

private static GetVerticesErrorResponseMessage get() {
    var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    VerifiedVertex verifiedVertex = new VerifiedVertex(UnverifiedVertex.createGenesis(ledgerHeader), HashUtils.zero256());
    QuorumCertificate qc = QuorumCertificate.ofGenesis(verifiedVertex, ledgerHeader);
    HighQC highQC = HighQC.from(qc, qc, Optional.empty());
    final var request = new GetVerticesRequestMessage(HashUtils.random256(), 3);
    return new GetVerticesErrorResponseMessage(highQC, request);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) AccumulatorState(com.radixdlt.ledger.AccumulatorState) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate)

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