Search in sources :

Example 1 with RpcException

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);
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) FailureReason(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason) RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) BlocksByRangeResponseInvalidResponseException(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BlocksByRangeResponseInvalidResponseException) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)

Example 2 with RpcException

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);
}
Also used : Peer(tech.pegasys.teku.networking.p2p.peer.Peer) RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) Test(org.junit.jupiter.api.Test)

Example 3 with RpcException

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();
}
Also used : RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) Spec(tech.pegasys.teku.spec.Spec) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with RpcException

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();
}
Also used : RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) Spec(tech.pegasys.teku.spec.Spec) BeaconBlocksByRangeRequestMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage) Test(org.junit.jupiter.api.Test)

Example 5 with RpcException

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();
}
Also used : RpcException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException) Spec(tech.pegasys.teku.spec.Spec) BeaconBlocksByRangeRequestMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage) Test(org.junit.jupiter.api.Test)

Aggregations

RpcException (tech.pegasys.teku.networking.eth2.rpc.core.RpcException)20 Test (org.junit.jupiter.api.Test)18 Spec (tech.pegasys.teku.spec.Spec)9 BeaconBlocksByRangeRequestMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRangeRequestMessage)9 InvalidRpcMethodVersion (tech.pegasys.teku.networking.eth2.rpc.core.RpcException.InvalidRpcMethodVersion)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)5 ArrayList (java.util.ArrayList)4 Eth2Peer (tech.pegasys.teku.networking.eth2.peers.Eth2Peer)4 Bytes (org.apache.tuweni.bytes.Bytes)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 SpecMilestone (tech.pegasys.teku.spec.SpecMilestone)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ByteBuf (io.netty.buffer.ByteBuf)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 Optional (java.util.Optional)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 LengthOutOfBoundsException (tech.pegasys.teku.networking.eth2.rpc.core.RpcException.LengthOutOfBoundsException)2 PayloadTruncatedException (tech.pegasys.teku.networking.eth2.rpc.core.RpcException.PayloadTruncatedException)2