use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.
the class BFTEventVerifierTest method when_process_bad_author_proposal_then_should_not_be_forwarded.
@Test
public void when_process_bad_author_proposal_then_should_not_be_forwarded() {
Proposal proposal = mock(Proposal.class);
BFTNode author = mock(BFTNode.class);
when(proposal.getAuthor()).thenReturn(author);
when(proposal.getSignature()).thenReturn(mock(ECDSASignature.class));
when(validatorSet.containsNode(eq(author))).thenReturn(false);
when(verifier.verify(any(), any(), any())).thenReturn(true);
eventVerifier.processProposal(proposal);
verify(forwardTo, never()).processProposal(any());
}
use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.
the class BFTEventVerifierTest method when_process_correct_proposal_then_should_be_forwarded.
@Test
public void when_process_correct_proposal_then_should_be_forwarded() {
Proposal proposal = mock(Proposal.class);
BFTNode author = mock(BFTNode.class);
when(proposal.getAuthor()).thenReturn(author);
when(proposal.getSignature()).thenReturn(mock(ECDSASignature.class));
when(validatorSet.containsNode(eq(author))).thenReturn(true);
when(verifier.verify(any(), any(), any())).thenReturn(true);
when(safetyRules.verifyHighQcAgainstTheValidatorSet(any())).thenReturn(true);
eventVerifier.processProposal(proposal);
verify(forwardTo, times(1)).processProposal(eq(proposal));
}
use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.
the class FProposalsPerViewDropper method test.
@Override
public boolean test(SimulationNetwork.MessageInTransit msg) {
if (msg.getContent() instanceof Proposal) {
final Proposal proposal = (Proposal) msg.getContent();
final View view = proposal.getVertex().getView();
final Set<BFTNode> nodesToDrop = proposalToDrop.computeIfAbsent(view, v -> {
final List<BFTNode> nodes = Lists.newArrayList(validatorSet);
if (random != null) {
Collections.shuffle(nodes, random);
}
return ImmutableSet.copyOf(nodes.subList(0, faultySize));
});
if (proposalCount.merge(view, 1, Integer::sum).equals(validatorSet.size())) {
proposalToDrop.remove(view);
proposalCount.remove(view);
}
return nodesToDrop.contains(msg.getReceiver());
}
return false;
}
use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.
the class ProposalSerializeTest method get.
private static Proposal get() {
View view = View.of(1234567891L);
HashCode id = HashUtils.random256();
LedgerHeader ledgerHeader = LedgerHeaderMock.get();
BFTHeader header = new BFTHeader(view, id, ledgerHeader);
BFTHeader parent = new BFTHeader(View.of(1234567890L), HashUtils.random256(), ledgerHeader);
VoteData voteData = new VoteData(header, parent, null);
QuorumCertificate qc = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
var txn = Txn.create(new byte[] { 0, 1, 2, 3 });
// add a particle to ensure atom is valid and has at least one shard
BFTNode author = BFTNode.create(ECKeyPair.generateNew().getPublicKey());
UnverifiedVertex vertex = UnverifiedVertex.create(qc, view, List.of(txn), author);
return new Proposal(vertex, qc, ECDSASignature.zeroSignature(), Optional.empty());
}
use of com.radixdlt.hotstuff.Proposal in project radixdlt by radixdlt.
the class ConsensusModuleTest method getExternalModule.
private Module getExternalModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(Ledger.class).toInstance(mock(Ledger.class));
bind(new TypeLiteral<EventDispatcher<LocalTimeoutOccurrence>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<ViewUpdate>>() {
}).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<LocalSyncRequest>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<GetVerticesRequest>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<ScheduledLocalTimeout>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<ViewQuorumReached>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<Vote>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<Proposal>>() {
}).toInstance(rmock(RemoteEventDispatcher.class));
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesRequest>>() {
}).toInstance(requestSender);
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesResponse>>() {
}).toInstance(responseSender);
bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesErrorResponse>>() {
}).toInstance(errorResponseSender);
bind(new TypeLiteral<EventDispatcher<NoVote>>() {
}).toInstance(rmock(EventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<View>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(new TypeLiteral<ScheduledEventDispatcher<VertexRequestTimeout>>() {
}).toInstance(rmock(ScheduledEventDispatcher.class));
bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
bind(PersistentSafetyStateStore.class).toInstance(mock(PersistentSafetyStateStore.class));
bind(NextTxnsGenerator.class).toInstance(mock(NextTxnsGenerator.class));
bind(SystemCounters.class).toInstance(mock(SystemCounters.class));
bind(TimeSupplier.class).toInstance(mock(TimeSupplier.class));
bind(BFTConfiguration.class).toInstance(bftConfiguration);
bind(BFTValidatorSet.class).toInstance(bftConfiguration.getValidatorSet());
LedgerProof proof = mock(LedgerProof.class);
when(proof.getView()).thenReturn(View.genesis());
bind(LedgerProof.class).annotatedWith(LastProof.class).toInstance(proof);
bind(RateLimiter.class).annotatedWith(GetVerticesRequestRateLimit.class).toInstance(RateLimiter.create(Double.MAX_VALUE));
bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(200);
bindConstant().annotatedWith(PacemakerTimeout.class).to(1000L);
bindConstant().annotatedWith(PacemakerRate.class).to(2.0);
bindConstant().annotatedWith(PacemakerMaxExponent.class).to(6);
ECKeyPair ecKeyPair = ECKeyPair.generateNew();
bind(HashSigner.class).toInstance(ecKeyPair::sign);
}
@Provides
ViewUpdate viewUpdate(@Self BFTNode node) {
return ViewUpdate.create(View.of(1), mock(HighQC.class), node, node);
}
@Provides
@Self
private BFTNode bftNode() {
return BFTNode.create(ecKeyPair.getPublicKey());
}
};
}
Aggregations