use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRangeIntegrationTest method shouldSendEmptyResponseWhenNoBlocksAreAvailable.
@Test
public void shouldSendEmptyResponseWhenNoBlocksAreAvailable() throws Exception {
final Eth2Peer peer = createPeer();
final List<SignedBeaconBlock> response = requestBlocks(peer);
assertThat(response).isEmpty();
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRangeIntegrationTest method requestBlockBySlotAfterPeerDisconnectedImmediately.
@Test
public void requestBlockBySlotAfterPeerDisconnectedImmediately() throws Exception {
final Eth2Peer peer = createPeer();
// Setup chain
peerStorage.chainUpdater().advanceChain();
final SignedBlockAndState block2 = peerStorage.chainUpdater().advanceChain();
peerStorage.chainUpdater().updateBestBlock(block2);
peer.disconnectImmediately(Optional.empty(), false);
final SafeFuture<Optional<SignedBeaconBlock>> res = peer.requestBlockBySlot(UInt64.ONE);
waitFor(() -> assertThat(res).isDone());
assertThat(res).isCompletedExceptionally();
assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRangeIntegrationTest method requestBlockBySlot_shouldReturnEmptyWhenBlockIsNotKnown.
@Test
void requestBlockBySlot_shouldReturnEmptyWhenBlockIsNotKnown() throws Exception {
final Eth2Peer peer = createPeer();
final Optional<SignedBeaconBlock> result = waitFor(peer.requestBlockBySlot(UInt64.valueOf(49382982)));
assertThat(result).isEmpty();
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class BeaconBlocksByRootMessageHandler method onIncomingMessage.
@Override
public void onIncomingMessage(final String protocolId, final Eth2Peer peer, final BeaconBlocksByRootRequestMessage message, final ResponseCallback<SignedBeaconBlock> callback) {
LOG.trace("Peer {} requested BeaconBlocks with roots: {}", peer.getId(), message);
if (storageClient.getStore() != null) {
SafeFuture<Void> future = SafeFuture.COMPLETE;
if (!peer.wantToMakeRequest() || !peer.wantToReceiveObjects(callback, message.size())) {
peer.disconnectCleanly(DisconnectReason.RATE_LIMITING).reportExceptions();
return;
}
for (SszBytes32 blockRoot : message) {
future = future.thenCompose(__ -> storageClient.getStore().retrieveSignedBlock(blockRoot.get()).thenCompose(block -> {
final Optional<RpcException> validationResult = block.flatMap(b -> validateResponse(protocolId, b));
if (validationResult.isPresent()) {
return SafeFuture.failedFuture(validationResult.get());
}
return block.map(callback::respond).orElse(SafeFuture.COMPLETE);
}));
}
future.finish(callback::completeSuccessfully, err -> handleError(callback, err));
} else {
callback.completeSuccessfully();
}
}
use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.
the class StatusMessageHandler method onIncomingMessage.
@Override
public void onIncomingMessage(final String protocolId, final Eth2Peer peer, final StatusMessage message, final ResponseCallback<StatusMessage> callback) {
LOG.trace("Peer {} sent status {}", peer.getId(), message);
if (!peer.wantToMakeRequest()) {
return;
}
final PeerStatus status = PeerStatus.fromStatusMessage(message);
peer.updateStatus(status);
final Optional<StatusMessage> localStatus = statusMessageFactory.createStatusMessage();
if (localStatus.isPresent()) {
callback.respondAndCompleteSuccessfully(localStatus.get());
} else {
LOG.warn("Node is not ready to receive p2p traffic. Responding to incoming status message with an error.");
callback.completeWithErrorResponse(NODE_NOT_READY);
}
}
Aggregations