Search in sources :

Example 1 with RemoteEvent

use of com.radixdlt.environment.rx.RemoteEvent in project radixdlt by radixdlt.

the class MessageCentralValidatorSync method responses.

public Flowable<RemoteEvent<GetVerticesResponse>> responses() {
    return this.createFlowable(GetVerticesResponseMessage.class, (src, msg) -> {
        BFTNode node = BFTNode.create(src.getPublicKey());
        // TODO: Move hasher to a more appropriate place
        ImmutableList<VerifiedVertex> hashedVertices = msg.getVertices().stream().map(v -> new VerifiedVertex(v, hasher.hash(v))).collect(ImmutableList.toImmutableList());
        return RemoteEvent.create(node, new GetVerticesResponse(hashedVertices));
    });
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Flowable(io.reactivex.rxjava3.core.Flowable) Message(org.radix.network.messaging.Message) Inject(com.google.inject.Inject) BiFunction(java.util.function.BiFunction) Hasher(com.radixdlt.crypto.Hasher) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) RemoteEvent(com.radixdlt.environment.rx.RemoteEvent) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Objects(java.util.Objects) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) ImmutableList(com.google.common.collect.ImmutableList) NodeId(com.radixdlt.network.p2p.NodeId) BackpressureStrategy(io.reactivex.rxjava3.core.BackpressureStrategy) MessageCentral(com.radixdlt.network.messaging.MessageCentral) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse)

Example 2 with RemoteEvent

use of com.radixdlt.environment.rx.RemoteEvent in project radixdlt by radixdlt.

the class MessageCentralLedgerSyncTest method when_receive_sync_response__then_should_receive_it.

@Test
public void when_receive_sync_response__then_should_receive_it() {
    TestSubscriber<RemoteEvent<SyncResponse>> testObserver = this.messageCentralLedgerSync.syncResponses().test();
    final var peer = createPeer();
    SyncResponseMessage syncResponseMessage = mock(SyncResponseMessage.class);
    DtoTxnsAndProof commands = mock(DtoTxnsAndProof.class);
    when(syncResponseMessage.getCommands()).thenReturn(commands);
    messageCentral.send(peer, syncResponseMessage);
    testObserver.awaitCount(1);
    testObserver.assertValue(resp -> resp.getEvent().getTxnsAndProof().equals(commands));
}
Also used : RemoteEvent(com.radixdlt.environment.rx.RemoteEvent) DtoTxnsAndProof(com.radixdlt.ledger.DtoTxnsAndProof) Test(org.junit.Test)

Example 3 with RemoteEvent

use of com.radixdlt.environment.rx.RemoteEvent in project radixdlt by radixdlt.

the class MessageCentralLedgerSyncTest method when_receive_sync_request__then_should_receive_it.

@Test
public void when_receive_sync_request__then_should_receive_it() {
    TestSubscriber<RemoteEvent<SyncRequest>> testObserver = this.messageCentralLedgerSync.syncRequests().test();
    final var peer = createPeer();
    SyncRequestMessage syncRequestMessage = mock(SyncRequestMessage.class);
    DtoLedgerProof header = mock(DtoLedgerProof.class);
    when(syncRequestMessage.getCurrentHeader()).thenReturn(header);
    messageCentral.send(peer, syncRequestMessage);
    testObserver.awaitCount(1);
    testObserver.assertValue(syncRequest -> syncRequest.getEvent().getHeader().equals(header) && syncRequest.getOrigin().getKey().equals(peer.getPublicKey()));
}
Also used : DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) RemoteEvent(com.radixdlt.environment.rx.RemoteEvent) Test(org.junit.Test)

Example 4 with RemoteEvent

use of com.radixdlt.environment.rx.RemoteEvent in project radixdlt by radixdlt.

the class SimulationNetworkTest method when_send_get_vertex_request_to_another_node__then_should_receive_it.

@Test
public void when_send_get_vertex_request_to_another_node__then_should_receive_it() {
    HashCode vertexId = mock(HashCode.class);
    TestObserver<RemoteEvent<GetVerticesRequest>> rpcRequestListener = network.getNetwork(node2).remoteEvents(GetVerticesRequest.class).toObservable().test();
    network.getNetwork(node1).remoteEventDispatcher(GetVerticesRequest.class).dispatch(node2, new GetVerticesRequest(vertexId, 1));
    rpcRequestListener.awaitCount(1);
    rpcRequestListener.assertValueAt(0, r -> r.getEvent().getVertexId().equals(vertexId));
}
Also used : HashCode(com.google.common.hash.HashCode) GetVerticesRequest(com.radixdlt.consensus.sync.GetVerticesRequest) RemoteEvent(com.radixdlt.environment.rx.RemoteEvent) Test(org.junit.Test)

Aggregations

RemoteEvent (com.radixdlt.environment.rx.RemoteEvent)4 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)1 HashCode (com.google.common.hash.HashCode)1 Inject (com.google.inject.Inject)1 GetVerticesRequest (com.radixdlt.consensus.sync.GetVerticesRequest)1 Hasher (com.radixdlt.crypto.Hasher)1 RemoteEventDispatcher (com.radixdlt.environment.RemoteEventDispatcher)1 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)1 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)1 GetVerticesErrorResponse (com.radixdlt.hotstuff.sync.GetVerticesErrorResponse)1 GetVerticesRequest (com.radixdlt.hotstuff.sync.GetVerticesRequest)1 GetVerticesResponse (com.radixdlt.hotstuff.sync.GetVerticesResponse)1 DtoLedgerProof (com.radixdlt.ledger.DtoLedgerProof)1 DtoTxnsAndProof (com.radixdlt.ledger.DtoTxnsAndProof)1 MessageCentral (com.radixdlt.network.messaging.MessageCentral)1 NodeId (com.radixdlt.network.p2p.NodeId)1 BackpressureStrategy (io.reactivex.rxjava3.core.BackpressureStrategy)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 Objects (java.util.Objects)1