use of com.radixdlt.hotstuff.bft.VerifiedVertexStoreState in project radixdlt by radixdlt.
the class PacemakerTest method when_local_timeout__then_send_empty_vote_if_no_previous.
@Test
public void when_local_timeout__then_send_empty_vote_if_no_previous() {
HighQC viewUpdateHighQc = mock(HighQC.class);
QuorumCertificate committedQc = mock(QuorumCertificate.class);
QuorumCertificate highestQc = mock(QuorumCertificate.class);
when(viewUpdateHighQc.highestCommittedQC()).thenReturn(committedQc);
when(viewUpdateHighQc.highestQC()).thenReturn(highestQc);
BFTHeader highestQcProposed = mock(BFTHeader.class);
HashCode highQcParentVertexId = mock(HashCode.class);
when(highestQcProposed.getVertexId()).thenReturn(highQcParentVertexId);
when(highestQc.getProposed()).thenReturn(highestQcProposed);
when(committedQc.getView()).thenReturn(View.of(0));
ViewUpdate viewUpdate = ViewUpdate.create(View.of(1), viewUpdateHighQc, mock(BFTNode.class), mock(BFTNode.class));
this.pacemaker.processViewUpdate(viewUpdate);
View view = View.of(1);
Vote emptyVote = mock(Vote.class);
Vote emptyVoteWithTimeout = mock(Vote.class);
ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
BFTHeader bftHeader = mock(BFTHeader.class);
HighQC highQC = mock(HighQC.class);
BFTInsertUpdate bftInsertUpdate = mock(BFTInsertUpdate.class);
when(bftInsertUpdate.getHeader()).thenReturn(bftHeader);
PreparedVertex preparedVertex = mock(PreparedVertex.class);
when(preparedVertex.getView()).thenReturn(view);
when(preparedVertex.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
VerifiedVertexStoreState vertexStoreState = mock(VerifiedVertexStoreState.class);
when(vertexStoreState.getHighQC()).thenReturn(highQC);
when(bftInsertUpdate.getInserted()).thenReturn(preparedVertex);
when(bftInsertUpdate.getVertexStoreState()).thenReturn(vertexStoreState);
var node = BFTNode.random();
when(preparedVertex.getId()).thenReturn(hasher.hash(UnverifiedVertex.createTimeout(highestQc, view, node)));
when(this.safetyRules.getLastVote(view)).thenReturn(Optional.empty());
when(this.safetyRules.createVote(any(), any(), anyLong(), any())).thenReturn(emptyVote);
when(this.safetyRules.timeoutVote(emptyVote)).thenReturn(emptyVoteWithTimeout);
when(this.validatorSet.nodes()).thenReturn(validators);
when(this.vertexStore.getPreparedVertex(any())).thenReturn(Optional.empty());
this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(ViewUpdate.create(View.of(1), mock(HighQC.class), node, BFTNode.random()), 0L));
this.pacemaker.processBFTUpdate(bftInsertUpdate);
verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(emptyVoteWithTimeout));
verify(this.safetyRules, times(1)).getLastVote(view);
verify(this.safetyRules, times(1)).createVote(any(), any(), anyLong(), any());
verify(this.safetyRules, times(1)).timeoutVote(emptyVote);
verifyNoMoreInteractions(this.safetyRules);
verify(this.vertexStore, times(1)).getPreparedVertex(any());
ArgumentCaptor<VerifiedVertex> insertVertexCaptor = ArgumentCaptor.forClass(VerifiedVertex.class);
verify(this.vertexStore, times(1)).insertVertex(insertVertexCaptor.capture());
assertEquals(insertVertexCaptor.getValue().getParentId(), highQcParentVertexId);
verifyNoMoreInteractions(this.vertexStore);
}
use of com.radixdlt.hotstuff.bft.VerifiedVertexStoreState in project radixdlt by radixdlt.
the class MockedStateComputer method commit.
@Override
public void commit(VerifiedTxnsAndProof txnsAndProof, VerifiedVertexStoreState vertexStoreState) {
var output = txnsAndProof.getProof().getNextValidatorSet().map(validatorSet -> {
LedgerProof header = txnsAndProof.getProof();
UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header.getRaw());
VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
QuorumCertificate genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
final var initialState = VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher);
var proposerElection = new WeightedRotatingLeaders(validatorSet);
var bftConfiguration = new BFTConfiguration(proposerElection, validatorSet, initialState);
return new EpochChange(header, bftConfiguration);
}).map(e -> ImmutableClassToInstanceMap.<Object, EpochChange>of(EpochChange.class, e)).orElse(ImmutableClassToInstanceMap.of());
var ledgerUpdate = new LedgerUpdate(txnsAndProof, output);
ledgerUpdateDispatcher.dispatch(ledgerUpdate);
}
Aggregations