Search in sources :

Example 26 with VerifiedVertex

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

the class StateComputerLedgerTest method setup.

@Before
public void setup() {
    this.mempool = TypedMocks.rmock(Mempool.class);
    // No type check issues with mocking generic here
    this.stateComputer = mock(StateComputer.class);
    this.counters = mock(SystemCounters.class);
    this.headerComparator = TypedMocks.rmock(Comparator.class);
    this.accumulator = new SimpleLedgerAccumulatorAndVerifier(hasher);
    this.accumulatorVerifier = new SimpleLedgerAccumulatorAndVerifier(hasher);
    var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
    this.ledgerHeader = LedgerHeader.genesis(accumulatorState, null, 0);
    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 : StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) SystemCounters(com.radixdlt.counters.SystemCounters) Mempool(com.radixdlt.mempool.Mempool) Comparator(java.util.Comparator) Pair(com.radixdlt.utils.Pair) Before(org.junit.Before)

Example 27 with VerifiedVertex

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

the class MessageCentralValidatorSyncTest method when_send_response__then_message_central_will_send_response.

@Test
public void when_send_response__then_message_central_will_send_response() {
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.toSerializable()).thenReturn(mock(UnverifiedVertex.class));
    ImmutableList<VerifiedVertex> vertices = ImmutableList.of(vertex);
    BFTNode node = mock(BFTNode.class);
    ECPublicKey ecPublicKey = mock(ECPublicKey.class);
    when(node.getKey()).thenReturn(ecPublicKey);
    sync.verticesResponseDispatcher().dispatch(node, new GetVerticesResponse(vertices));
    verify(messageCentral, times(1)).send(any(), any(GetVerticesResponseMessage.class));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) ECPublicKey(com.radixdlt.crypto.ECPublicKey) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) Test(org.junit.Test)

Example 28 with VerifiedVertex

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

the class SafetyRulesTest method when_vote_on_proposal_two_after_genesis__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_two_after_genesis__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(true);
    when(proposal.hasDirectParent()).thenReturn(true);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(1));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(2));
    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)

Example 29 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__then_returned_vote_has_commit.

@Test
public void when_vote_on_proposal_three_after_genesis__then_returned_vote_has_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(true);
    when(proposal.parentHasDirectParent()).thenReturn(true);
    BFTHeader grandparentHeader = mock(BFTHeader.class);
    when(grandparentHeader.getView()).thenReturn(mock(View.class));
    when(proposal.getGrandParentHeader()).thenReturn(grandparentHeader);
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(2));
    when(proposal.getParentHeader()).thenReturn(parent);
    when(proposal.getView()).thenReturn(View.of(3));
    Optional<Vote> voteMaybe = safetyRules.voteFor(proposal, mock(BFTHeader.class), 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getCommitted()).hasValue(grandparentHeader);
}
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)

Example 30 with VerifiedVertex

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

the class SafetyRulesTest method when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit.

@Test
public void when_vote_on_proposal_after_genesis__then_returned_vote_has_no_commit() {
    when(safetyState.getLastVotedView()).thenReturn(View.of(0));
    when(safetyState.getLockedView()).thenReturn(View.of(0));
    when(safetyState.toBuilder()).thenReturn(mock(Builder.class));
    VerifiedVertex vertex = mock(VerifiedVertex.class);
    when(vertex.hasDirectParent()).thenReturn(true);
    when(vertex.touchesGenesis()).thenReturn(true);
    when(vertex.parentHasDirectParent()).thenReturn(true);
    when(vertex.getView()).thenReturn(View.of(1));
    BFTHeader parent = mock(BFTHeader.class);
    when(parent.getView()).thenReturn(View.of(0));
    when(vertex.getParentHeader()).thenReturn(parent);
    BFTHeader grandParent = mock(BFTHeader.class);
    when(grandParent.getView()).thenReturn(mock(View.class));
    when(vertex.getGrandParentHeader()).thenReturn(grandParent);
    BFTHeader header = mock(BFTHeader.class);
    Optional<Vote> voteMaybe = safetyRules.voteFor(vertex, header, 1L, mock(HighQC.class));
    assertThat(voteMaybe).isNotEmpty();
    Vote vote = voteMaybe.get();
    assertThat(vote.getVoteData().getProposed()).isEqualTo(header);
    assertThat(vote.getVoteData().getParent()).isEqualTo(parent);
    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