use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException in project teku by ConsenSys.
the class PeerSync method handleFailedRequestToPeer.
private PeerSyncResult handleFailedRequestToPeer(Eth2Peer peer, final PeerStatus peerStatus, Throwable err) {
Throwable rootException = Throwables.getRootCause(err);
if (rootException instanceof FailedBlockImportException) {
final FailedBlockImportException importException = (FailedBlockImportException) rootException;
final FailureReason reason = importException.getResult().getFailureReason();
final SignedBeaconBlock block = importException.getBlock();
if (reason.equals(FailureReason.UNKNOWN_PARENT) && !hasPeerFinalizedBlock(block, peerStatus)) {
// We received a block that doesn't connect to our chain.
// This can happen if our peer is sending us blocks from the non-final portion of their
// chain. They may be sending us blocks from a stale fork that we have already pruned out of
// our Store.
LOG.debug("Failed to import non-final block from peer (err: {}) {}: {}", reason, block, peer);
return PeerSyncResult.IMPORT_FAILED;
} else if (BAD_BLOCK_FAILURE_REASONS.contains(reason)) {
LOG.warn("Failed to import block from peer (err: {}) {}: {}", reason, block, peer);
LOG.debug("Disconnecting from peer ({}) who sent invalid block ({}): {}", peer, reason.name(), block);
disconnectFromPeer(peer);
return PeerSyncResult.BAD_BLOCK;
} else {
LOG.warn("Failed to import block from peer (err: {}) {}: {}", reason, block, peer);
return PeerSyncResult.IMPORT_FAILED;
}
}
if (rootException instanceof CancellationException) {
return PeerSyncResult.CANCELLED;
}
if (rootException instanceof BlocksByRangeResponseInvalidResponseException || rootException instanceof RpcException) {
disconnectFromPeer(peer);
return PeerSyncResult.INVALID_RESPONSE;
}
if (err instanceof RuntimeException) {
throw (RuntimeException) err;
} else {
throw new RuntimeException("Unhandled error while syncing", err);
}
}
use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException in project teku by ConsenSys.
the class Eth2PeerManagerTest method onConnect_shouldDisconnectIfPeerReturnsErrorResponseToStatusMessage.
@Test
void onConnect_shouldDisconnectIfPeerReturnsErrorResponseToStatusMessage() {
final Peer peer = createPeer(1);
final Eth2Peer eth2Peer = getEth2Peer(peer);
when(peer.connectionInitiatedLocally()).thenReturn(true);
when(eth2Peer.sendStatus()).thenReturn(SafeFuture.failedFuture(new RpcException(RpcResponseStatus.SERVER_ERROR_CODE, "It went boom")));
peerManager.onConnect(peer);
verify(eth2Peer).disconnectImmediately(Optional.of(DisconnectReason.REMOTE_FAULT), true);
}
use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException in project teku by ConsenSys.
the class BeaconBlocksByRootMessageHandlerTest method validateResponse_altairSpec_v1RequestForPhase0Block.
@Test
public void validateResponse_altairSpec_v1RequestForPhase0Block() {
final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(UInt64.valueOf(4));
final BeaconBlocksByRootMessageHandler handler = new BeaconBlocksByRootMessageHandler(spec, recentChainData);
final Optional<RpcException> result = handler.validateResponse(V1_PROTOCOL_ID, chainUpdater.advanceChain(5).getBlock());
assertThat(result).isEmpty();
}
use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException in project teku by ConsenSys.
the class BeaconBlocksByRangeMessageHandlerTest method validateRequest_altairSpec_v2RequestForPhase0Block.
@Test
public void validateRequest_altairSpec_v2RequestForPhase0Block() {
final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(UInt64.valueOf(4));
final BeaconBlocksByRangeMessageHandler handler = new BeaconBlocksByRangeMessageHandler(spec, combinedChainDataClient, maxRequestSize);
final Optional<RpcException> result = handler.validateRequest(V2_PROTOCOL_ID, new BeaconBlocksByRangeRequestMessage(ZERO, ONE, ONE));
assertThat(result).isEmpty();
}
use of tech.pegasys.teku.networking.eth2.rpc.core.RpcException in project teku by ConsenSys.
the class BeaconBlocksByRangeMessageHandlerTest method validateRequest_altairSpec_v2RequestForRangeOfBlocksAcrossForkBoundary.
@Test
public void validateRequest_altairSpec_v2RequestForRangeOfBlocksAcrossForkBoundary() {
final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(UInt64.valueOf(4));
final BeaconBlocksByRangeMessageHandler handler = new BeaconBlocksByRangeMessageHandler(spec, combinedChainDataClient, maxRequestSize);
final Optional<RpcException> result = handler.validateRequest(V2_PROTOCOL_ID, new BeaconBlocksByRangeRequestMessage(UInt64.valueOf(30), UInt64.valueOf(10), ONE));
assertThat(result).isEmpty();
}
Aggregations