use of com.radixdlt.consensus.bft.BFTNode in project radixdlt by radixdlt.
the class PendingVotesTest method when_inserting_valid_and_accepted_votes__then_qc_is_formed.
@Test
public void when_inserting_valid_and_accepted_votes__then_qc_is_formed() {
BFTNode author = mock(BFTNode.class);
Vote vote = makeSignedVoteFor(author, View.genesis(), HashUtils.random256());
BFTValidatorSet validatorSet = mock(BFTValidatorSet.class);
ValidationState validationState = mock(ValidationState.class);
TimestampedECDSASignatures signatures = mock(TimestampedECDSASignatures.class);
when(validationState.addSignature(any(), anyLong(), any())).thenReturn(true);
when(validationState.complete()).thenReturn(true);
when(validationState.signatures()).thenReturn(signatures);
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);
assertTrue(this.pendingVotes.insertVote(vote, validatorSet) instanceof VoteProcessingResult.QuorumReached);
}
use of com.radixdlt.consensus.bft.BFTNode in project radixdlt by radixdlt.
the class PendingVotesTest method when_voting_again__previous_vote_is_removed.
@Test
public void when_voting_again__previous_vote_is_removed() {
BFTNode author = mock(BFTNode.class);
Vote vote = makeSignedVoteFor(author, View.genesis(), HashUtils.random256());
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.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(1, this.pendingVotes.previousVotesSize());
}
use of com.radixdlt.consensus.bft.BFTNode in project radixdlt by radixdlt.
the class EpochManagerTest method getExternalModule.
private Module getExternalModule() {
BFTNode self = BFTNode.create(ecKeyPair.getPublicKey());
return new AbstractModule() {
@Override
protected void configure() {
bind(HashSigner.class).toInstance(ecKeyPair::sign);
bind(BFTNode.class).annotatedWith(Self.class).toInstance(self);
bind(new TypeLiteral<EventDispatcher<LocalTimeoutOccurrence>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<BFTInsertUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<BFTRebuildUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<BFTHighQCUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<BFTCommittedUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<EpochLocalTimeoutOccurrence>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<EpochView>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<LocalSyncRequest>>() {
}).toInstance(syncLedgerRequestSender);
bind(new TypeLiteral<EventDispatcher<ViewQuorumReached>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<EpochViewUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<ViewUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<NoVote>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<GetVerticesRequest>>() {
}).toInstance(timeoutScheduler);
bind(new TypeLiteral<ScheduledEventDispatcher<ScheduledLocalTimeout>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<Epoched<ScheduledLocalTimeout>>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<VertexRequestTimeout>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<Proposal>>() {
}).toInstance(proposalDispatcher);
bind(new TypeLiteral<RemoteEventDispatcher<Vote>>() {
}).toInstance(voteDispatcher);
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesRequest>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesResponse>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesErrorResponse>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<LedgerStatusUpdate>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(PersistentSafetyStateStore.class).toInstance(mock(PersistentSafetyStateStore.class));
bind(NextTxnsGenerator.class).toInstance(nextTxnsGenerator);
bind(SystemCounters.class).toInstance(new SystemCountersImpl());
bind(Mempool.class).toInstance(mempool);
bind(StateComputer.class).toInstance(stateComputer);
bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
bind(RateLimiter.class).annotatedWith(GetVerticesRequestRateLimit.class).toInstance(RateLimiter.create(Double.MAX_VALUE));
bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(50);
bindConstant().annotatedWith(PacemakerTimeout.class).to(10L);
bindConstant().annotatedWith(PacemakerRate.class).to(2.0);
bindConstant().annotatedWith(PacemakerMaxExponent.class).to(0);
bind(TimeSupplier.class).toInstance(System::currentTimeMillis);
bind(new TypeLiteral<Consumer<EpochViewUpdate>>() {
}).toInstance(rmock(Consumer.class));
}
@Provides
private ViewUpdate view(BFTConfiguration bftConfiguration) {
HighQC highQC = bftConfiguration.getVertexStoreState().getHighQC();
View view = highQC.highestQC().getView().next();
return ViewUpdate.create(view, highQC, self, self);
}
@Provides
BFTValidatorSet validatorSet() {
return BFTValidatorSet.from(Stream.of(BFTValidator.from(self, UInt256.ONE)));
}
@Provides
@LastProof
LedgerProof verifiedLedgerHeaderAndProof(BFTValidatorSet validatorSet) {
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
return LedgerProof.genesis(accumulatorState, validatorSet, 0);
}
@Provides
@LastEpochProof
LedgerProof lastEpochProof(BFTValidatorSet validatorSet) {
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
return LedgerProof.genesis(accumulatorState, validatorSet, 0);
}
@Provides
BFTConfiguration bftConfiguration(@Self BFTNode self, Hasher hasher, BFTValidatorSet validatorSet) {
var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
var unverifiedVertex = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, validatorSet, 0));
var verifiedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
var qc = QuorumCertificate.ofGenesis(verifiedVertex, LedgerHeader.genesis(accumulatorState, validatorSet, 0));
var proposerElection = new WeightedRotatingLeaders(validatorSet);
return new BFTConfiguration(proposerElection, validatorSet, VerifiedVertexStoreState.create(HighQC.from(qc), verifiedVertex, Optional.empty(), hasher));
}
};
}
use of com.radixdlt.consensus.bft.BFTNode in project radixdlt by radixdlt.
the class PacemakerTest method when_local_timeout__then_resend_previous_vote.
@Test
public void when_local_timeout__then_resend_previous_vote() {
View view = View.of(0);
Vote lastVote = mock(Vote.class);
Vote lastVoteWithTimeout = mock(Vote.class);
ImmutableSet<BFTNode> validators = rmock(ImmutableSet.class);
when(this.safetyRules.getLastVote(view)).thenReturn(Optional.of(lastVote));
when(this.safetyRules.timeoutVote(lastVote)).thenReturn(lastVoteWithTimeout);
when(this.validatorSet.nodes()).thenReturn(validators);
ViewUpdate viewUpdate = ViewUpdate.create(View.of(0), mock(HighQC.class), mock(BFTNode.class), mock(BFTNode.class));
this.pacemaker.processLocalTimeout(ScheduledLocalTimeout.create(viewUpdate, 0L));
verify(this.voteDispatcher, times(1)).dispatch(eq(validators), eq(lastVoteWithTimeout));
verifyNoMoreInteractions(this.vertexStore);
verify(this.safetyRules, times(1)).getLastVote(view);
verify(this.safetyRules, times(1)).timeoutVote(lastVote);
verifyNoMoreInteractions(this.safetyRules);
}
use of com.radixdlt.consensus.bft.BFTNode in project radixdlt by radixdlt.
the class WeightedRotatingLeadersTest method setUp.
private void setUp(int validatorSetSize, int sizeOfCache) {
this.validatorsInOrder = Stream.generate(() -> ECKeyPair.generateNew().getPublicKey()).limit(validatorSetSize).map(BFTNode::create).map(node -> BFTValidator.from(node, UInt256.ONE)).sorted(Comparator.comparing(v -> v.getNode().getKey(), KeyComparator.instance().reversed())).collect(ImmutableList.toImmutableList());
BFTValidatorSet validatorSet = BFTValidatorSet.from(validatorsInOrder);
this.weightedRotatingLeaders = new WeightedRotatingLeaders(validatorSet, sizeOfCache);
this.weightedRotatingLeaders2 = new WeightedRotatingLeaders(validatorSet, sizeOfCache);
}
Aggregations