use of com.radixdlt.consensus.sync.GetVerticesRequest in project radixdlt by radixdlt.
the class MessageCentralValidatorSyncTest method when_send_error_response__then_message_central_will_send_error_response.
@Test
public void when_send_error_response__then_message_central_will_send_error_response() {
QuorumCertificate qc = mock(QuorumCertificate.class);
HighQC highQC = mock(HighQC.class);
when(highQC.highestQC()).thenReturn(qc);
when(highQC.highestCommittedQC()).thenReturn(qc);
BFTNode node = mock(BFTNode.class);
ECPublicKey ecPublicKey = mock(ECPublicKey.class);
when(node.getKey()).thenReturn(ecPublicKey);
final var request = new GetVerticesRequest(HashUtils.random256(), 3);
sync.verticesErrorResponseDispatcher().dispatch(node, new GetVerticesErrorResponse(highQC, request));
verify(messageCentral, times(1)).send(eq(NodeId.fromPublicKey(ecPublicKey)), any(GetVerticesErrorResponseMessage.class));
}
use of com.radixdlt.consensus.sync.GetVerticesRequest in project radixdlt by radixdlt.
the class MessageCentralValidatorSyncTest method when_subscribed_to_rpc_requests__then_should_receive_requests.
@Test
public void when_subscribed_to_rpc_requests__then_should_receive_requests() {
HashCode vertexId0 = mock(HashCode.class);
HashCode vertexId1 = mock(HashCode.class);
final var peer = NodeId.fromPublicKey(ECKeyPair.generateNew().getPublicKey());
TestSubscriber<GetVerticesRequest> testObserver = sync.requests().map(RemoteEvent::getEvent).test();
messageCentral.send(peer, new GetVerticesRequestMessage(vertexId0, 1));
messageCentral.send(peer, new GetVerticesRequestMessage(vertexId1, 1));
testObserver.awaitCount(2);
testObserver.assertValueAt(0, v -> v.getVertexId().equals(vertexId0));
testObserver.assertValueAt(1, v -> v.getVertexId().equals(vertexId1));
}
use of com.radixdlt.consensus.sync.GetVerticesRequest in project radixdlt by radixdlt.
the class ConsensusModuleTest method on_sync_request_timeout_should_retry.
@Test
public void on_sync_request_timeout_should_retry() {
// Arrange
BFTNode bftNode = BFTNode.random();
QuorumCertificate parent = vertexStore.highQC().highestQC();
Pair<QuorumCertificate, VerifiedVertex> nextVertex = createNextVertex(parent, bftNode);
HighQC unsyncedHighQC = HighQC.from(nextVertex.getFirst(), nextVertex.getFirst(), Optional.empty());
bftSync.syncToQC(unsyncedHighQC, bftNode);
GetVerticesRequest request = new GetVerticesRequest(nextVertex.getSecond().getId(), 1);
VertexRequestTimeout timeout = VertexRequestTimeout.create(request);
// Act
// FIXME: Remove when rate limit on send removed
nothrowSleep(100);
bftSync.vertexRequestTimeoutEventProcessor().process(timeout);
// Assert
verify(requestSender, times(2)).dispatch(eq(bftNode), argThat(r -> r.getCount() == 1 && r.getVertexId().equals(nextVertex.getSecond().getId())));
}
use of com.radixdlt.consensus.sync.GetVerticesRequest in project radixdlt by radixdlt.
the class OneNodeAlwaysAliveSafetyTest method setup.
@Before
public void setup() {
var allNodes = nodeKeys.stream().map(k -> BFTNode.create(k.getPublicKey())).toList();
this.network = new DeterministicNetwork(allNodes, MessageSelector.firstSelector(), (message, queue) -> message.message() instanceof GetVerticesRequest || message.message() instanceof LocalSyncRequest);
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(new TypeLiteral<List<BFTNode>>() {
}).toInstance(allNodes);
}
@ProvidesIntoSet
public NodeEventProcessor<?> updateChecker() {
return new NodeEventProcessor<>(ViewQuorumReached.class, (node, viewQuorumReached) -> {
if (viewQuorumReached.votingResult() instanceof FormedQC && ((FormedQC) viewQuorumReached.votingResult()).getQC().getCommitted().isPresent()) {
lastNodeToCommit = network.lookup(node);
}
});
}
}, new SafetyCheckerModule(), new NodeEventsModule()).injectMembers(this);
this.nodeCreators = nodeKeys.stream().<Supplier<Injector>>map(k -> () -> createRunner(k, allNodes)).toList();
for (var nodeCreator : nodeCreators) {
this.nodes.add(nodeCreator.get());
}
}
use of com.radixdlt.consensus.sync.GetVerticesRequest 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);
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