use of com.radixdlt.consensus.safety.SafetyState.Builder in project radixdlt by radixdlt.
the class SafetyRulesTest method when_timeout_a_vote_than_it_has_a_timeout_signature.
@Test
public void when_timeout_a_vote_than_it_has_a_timeout_signature() {
Vote vote = mock(Vote.class);
Vote voteWithTimeout = mock(Vote.class);
when(vote.getView()).thenReturn(View.of(1));
when(vote.getEpoch()).thenReturn(1L);
when(vote.withTimeoutSignature(any())).thenReturn(voteWithTimeout);
when(vote.isTimeout()).thenReturn(false);
Builder builder = mock(Builder.class);
when(builder.lastVote(any())).thenReturn(builder);
when(builder.build()).thenReturn(this.safetyState);
when(safetyState.toBuilder()).thenReturn(builder);
Vote resultVote = safetyRules.timeoutVote(vote);
verify(vote, times(1)).withTimeoutSignature(any());
assertEquals(voteWithTimeout, resultVote);
}
use of com.radixdlt.consensus.safety.SafetyState.Builder in project radixdlt by radixdlt.
the class SafetyRules method signProposal.
/**
* Create a signed proposal from a vertex
*
* @param proposedVertex vertex to sign
* @param highestCommittedQC highest known committed QC
* @param highestTC highest known TC
* @return signed proposal object for consensus
*/
public Optional<Proposal> signProposal(VerifiedVertex proposedVertex, QuorumCertificate highestCommittedQC, Optional<TimeoutCertificate> highestTC) {
final Builder safetyStateBuilder = this.state.toBuilder();
if (!checkLocked(proposedVertex, safetyStateBuilder)) {
return Optional.empty();
}
this.state = safetyStateBuilder.build();
final ECDSASignature signature = this.signer.sign(proposedVertex.getId());
return Optional.of(new Proposal(proposedVertex.toSerializable(), highestCommittedQC, signature, highestTC));
}
use of com.radixdlt.consensus.safety.SafetyState.Builder in project radixdlt by radixdlt.
the class SafetyRules method voteFor.
/**
* Vote for a proposed vertex while ensuring that safety invariants are upheld.
*
* @param proposedVertex The proposed vertex
* @param proposedHeader results of vertex execution
* @param timestamp timestamp to use for the vote in milliseconds since epoch
* @param highQC our current sync state
* @return A vote result containing the vote and any committed vertices
*/
public Optional<Vote> voteFor(VerifiedVertex proposedVertex, BFTHeader proposedHeader, long timestamp, HighQC highQC) {
Builder safetyStateBuilder = this.state.toBuilder();
if (!checkLastVoted(proposedVertex)) {
return Optional.empty();
}
if (!checkLocked(proposedVertex, safetyStateBuilder)) {
return Optional.empty();
}
final Vote vote = createVote(proposedVertex, proposedHeader, timestamp, highQC);
safetyStateBuilder.lastVote(vote);
this.state = safetyStateBuilder.build();
this.persistentSafetyStateStore.commitState(this.state);
return Optional.of(vote);
}
use of com.radixdlt.consensus.safety.SafetyState.Builder in project radixdlt by radixdlt.
the class SafetyStateTest method when_build_with_no_new_views__then_should_return_the_same_object.
@Test
public void when_build_with_no_new_views__then_should_return_the_same_object() {
SafetyState safetyState = SafetyState.initialState();
Builder builder = safetyState.toBuilder();
assertThat(builder.build()).isSameAs(safetyState);
}
use of com.radixdlt.consensus.safety.SafetyState.Builder in project radixdlt by radixdlt.
the class SafetyStateTest method when_build_with_new_last_vote__then_should_build_with_new_last_vote.
@Test
public void when_build_with_new_last_vote__then_should_build_with_new_last_vote() {
SafetyState safetyState = SafetyState.initialState();
Builder builder = safetyState.toBuilder();
Vote vote = mock(Vote.class);
builder.lastVote(vote);
SafetyState nextSafetyState = builder.build();
assertThat(nextSafetyState.getLastVote()).isEqualTo(Optional.of(vote));
assertThat(nextSafetyState.getLockedView()).isEqualTo(safetyState.getLockedView());
}
Aggregations