use of com.radixdlt.consensus.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())).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());
}
use of com.radixdlt.consensus.bft.BFTNode in project radixdlt by radixdlt.
the class TimestampedECDSASignatures method fromJSON.
public static TimestampedECDSASignatures fromJSON(JSONArray json) throws DeserializeException {
var builder = ImmutableMap.<BFTNode, TimestampedECDSASignature>builder();
for (int i = 0; i < json.length(); i++) {
var signatureJson = json.getJSONObject(i);
try {
var key = ECPublicKey.fromHex(signatureJson.getString("key"));
var bytes = Bytes.fromHexString(signatureJson.getString("signature"));
var signature = REFieldSerialization.deserializeSignature(ByteBuffer.wrap(bytes));
var timestamp = signatureJson.getLong("timestamp");
builder.put(BFTNode.create(key), TimestampedECDSASignature.from(timestamp, signature));
} catch (PublicKeyException e) {
throw new DeserializeException(e.getMessage());
}
}
return new TimestampedECDSASignatures(builder.build());
}
use of com.radixdlt.consensus.bft.BFTNode in project radixdlt by radixdlt.
the class PendingVotes method processVoteForQC.
private Optional<QuorumCertificate> processVoteForQC(Vote vote, BFTValidatorSet validatorSet) {
final VoteData voteData = vote.getVoteData();
final HashCode voteDataHash = this.hasher.hash(voteData);
final BFTNode node = vote.getAuthor();
final ValidationState validationState = this.voteState.computeIfAbsent(voteDataHash, k -> validatorSet.newValidationState());
final boolean signatureAdded = validationState.addSignature(node, vote.getTimestamp(), vote.getSignature());
if (signatureAdded && validationState.complete()) {
return Optional.of(new QuorumCertificate(voteData, validationState.signatures()));
} else {
return Optional.empty();
}
}
use of com.radixdlt.consensus.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);
});
}
use of com.radixdlt.consensus.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);
}
Aggregations