Search in sources :

Example 21 with Eth2Peer

use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.

the class BeaconBlocksByRangeIntegrationTest method requestBlockBySlot_withDisparateVersionsEnabled_requestAltairBlocks.

@ParameterizedTest(name = "enableAltairLocally={0}, enableAltairRemotely={1}")
@MethodSource("altairVersioningOptions")
public void requestBlockBySlot_withDisparateVersionsEnabled_requestAltairBlocks(final boolean enableAltairLocally, final boolean enableAltairRemotely) throws Exception {
    setupPeerStorage(true);
    final Eth2Peer peer = createPeer(enableAltairLocally, enableAltairRemotely);
    // Setup chain
    peerStorage.chainUpdater().advanceChain(altairSlot.minus(1));
    // Create altair blocks
    final SignedBlockAndState block1 = peerStorage.chainUpdater().advanceChain();
    final SignedBlockAndState block2 = peerStorage.chainUpdater().advanceChain();
    peerStorage.chainUpdater().updateBestBlock(block2);
    assertThat(block1.getBlock().getMessage().getBody()).isInstanceOf(BeaconBlockBodyAltair.class);
    assertThat(block2.getBlock().getMessage().getBody()).isInstanceOf(BeaconBlockBodyAltair.class);
    peerStorage.chainUpdater().updateBestBlock(block2);
    final List<SignedBeaconBlock> blocks = new ArrayList<>();
    final SafeFuture<Void> res = peer.requestBlocksByRange(block1.getSlot(), UInt64.valueOf(2), UInt64.ONE, RpcResponseListener.from(blocks::add));
    waitFor(() -> assertThat(res).isDone());
    assertThat(peer.getOutstandingRequests()).isEqualTo(0);
    if (enableAltairLocally && enableAltairRemotely) {
        // We should receive a successful response
        assertThat(res).isCompleted();
        assertThat(blocks).containsExactly(block1.getBlock(), block2.getBlock());
    } else if (!enableAltairLocally && enableAltairRemotely) {
        // The peer should refuse to return any results because we're asking for altair blocks using
        // a v1 request
        assertThat(res).isCompletedExceptionally();
        assertThatThrownBy(res::get).hasCauseInstanceOf(RpcException.class).hasMessageContaining("[Code 1] Must request altair blocks using v2 protocol");
    } else {
        // Remote only supports v1, we should get a v1 response back and error out trying to
        // decode these blocks with a phase0 decoder
        assertThat(res).isCompletedExceptionally();
        assertThatThrownBy(res::get).hasCauseInstanceOf(DeserializationFailedException.class);
    }
}
Also used : DeserializationFailedException(tech.pegasys.teku.networking.eth2.rpc.core.RpcException.DeserializationFailedException) ArrayList(java.util.ArrayList) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 22 with Eth2Peer

use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.

the class BeaconBlocksByRangeIntegrationTest method requestBlocksByRangeAfterPeerDisconnected.

@Test
public void requestBlocksByRangeAfterPeerDisconnected() throws Exception {
    final Eth2Peer peer = createPeer();
    // Setup chain
    peerStorage.chainUpdater().advanceChain();
    final SignedBlockAndState block2 = peerStorage.chainUpdater().advanceChain();
    peerStorage.chainUpdater().updateBestBlock(block2);
    Waiter.waitFor(peer.disconnectCleanly(DisconnectReason.TOO_MANY_PEERS));
    final List<SignedBeaconBlock> blocks = new ArrayList<>();
    final SafeFuture<Void> res = peer.requestBlocksByRange(UInt64.ONE, UInt64.valueOf(10), UInt64.ONE, RpcResponseListener.from(blocks::add));
    waitFor(() -> assertThat(res).isDone());
    assertThat(res).isCompletedExceptionally();
    assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
    assertThat(blocks).isEmpty();
}
Also used : ArrayList(java.util.ArrayList) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with Eth2Peer

use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.

the class BeaconBlocksByRangeIntegrationTest method requestBlocksByRangeAfterPeerDisconnectedImmediately.

@Test
public void requestBlocksByRangeAfterPeerDisconnectedImmediately() 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 List<SignedBeaconBlock> blocks = new ArrayList<>();
    final SafeFuture<Void> res = peer.requestBlocksByRange(UInt64.ONE, UInt64.valueOf(10), UInt64.ONE, RpcResponseListener.from(blocks::add));
    waitFor(() -> assertThat(res).isDone());
    assertThat(res).isCompletedExceptionally();
    assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
    assertThat(blocks).isEmpty();
}
Also used : ArrayList(java.util.ArrayList) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with Eth2Peer

use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.

the class BeaconBlocksByRootIntegrationTest method requestBlocksByRootAfterPeerDisconnectedImmediately.

@Test
public void requestBlocksByRootAfterPeerDisconnectedImmediately() throws RpcException {
    final Eth2Peer peer = createPeer();
    final SignedBeaconBlock block = addBlock();
    final Bytes32 blockHash = block.getMessage().hashTreeRoot();
    peer.disconnectImmediately(Optional.empty(), false);
    final List<SignedBeaconBlock> blocks = new ArrayList<>();
    final SafeFuture<Void> res = peer.requestBlocksByRoot(List.of(blockHash), RpcResponseListener.from(blocks::add));
    waitFor(() -> assertThat(res).isDone());
    assertThat(res).isCompletedExceptionally();
    assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
    assertThat(blocks).isEmpty();
}
Also used : ArrayList(java.util.ArrayList) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with Eth2Peer

use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer in project teku by ConsenSys.

the class BeaconBlocksByRootIntegrationTest method shouldReturnMultipleLargeBlocksWhenAllRequestsMatch.

@Test
public void shouldReturnMultipleLargeBlocksWhenAllRequestsMatch() throws Exception {
    final Eth2Peer peer = createPeer();
    final List<SignedBeaconBlock> blocks = largeBlockSequence(3);
    final List<Bytes32> blockRoots = blocks.stream().map(SignedBeaconBlock::getRoot).collect(toList());
    final List<SignedBeaconBlock> response = requestBlocks(peer, blockRoots);
    assertThat(response).containsExactlyElementsOf(blocks);
}
Also used : Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Eth2Peer (tech.pegasys.teku.networking.eth2.peers.Eth2Peer)47 Test (org.junit.jupiter.api.Test)37 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Bytes32 (org.apache.tuweni.bytes.Bytes32)14 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)10 ArrayList (java.util.ArrayList)7 Optional (java.util.Optional)7 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)7 RpcException (tech.pegasys.teku.networking.eth2.rpc.core.RpcException)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)6 FetchBlockResult (tech.pegasys.teku.beacon.sync.gossip.FetchBlockTask.FetchBlockResult)5 StorageSystem (tech.pegasys.teku.storage.storageSystem.StorageSystem)5 MetadataMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage)4 LogManager (org.apache.logging.log4j.LogManager)3 PeerStatus (tech.pegasys.teku.networking.eth2.peers.PeerStatus)3 Spec (tech.pegasys.teku.spec.Spec)3 Throwables (com.google.common.base.Throwables)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2