Search in sources :

Example 16 with Eth2Peer

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

the class BeaconBlocksByRootIntegrationTest method requestBlockByRootAfterPeerDisconnected.

@Test
public void requestBlockByRootAfterPeerDisconnected() throws InterruptedException, ExecutionException, TimeoutException {
    final Eth2Peer peer = createPeer();
    final SignedBeaconBlock block = addBlock();
    final Bytes32 blockHash = block.getMessage().hashTreeRoot();
    Waiter.waitFor(peer.disconnectCleanly(DisconnectReason.TOO_MANY_PEERS));
    final SafeFuture<Optional<SignedBeaconBlock>> res = peer.requestBlockByRoot(blockHash);
    waitFor(() -> assertThat(res).isDone());
    assertThat(res).isCompletedExceptionally();
    assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
}
Also used : Optional(java.util.Optional) 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 17 with Eth2Peer

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

the class GetMetadataIntegrationTest method requestMetadata_shouldSendLatestAttnets.

@Test
public void requestMetadata_shouldSendLatestAttnets() throws Exception {
    final PeerAndNetwork peerAndNetwork = createRemotePeerAndNetwork();
    final Eth2Peer peer = peerAndNetwork.getPeer();
    MetadataMessage md1 = peer.requestMetadata().get(10, TimeUnit.SECONDS);
    MetadataMessage md2 = peer.requestMetadata().get(10, TimeUnit.SECONDS);
    assertThat(md1.getSeqNumber()).isEqualTo(md2.getSeqNumber());
    assertThat(md1.getAttnets().getBitCount()).isEqualTo(0);
    peerAndNetwork.getNetwork().setLongTermAttestationSubnetSubscriptions(List.of(0, 1, 8));
    MetadataMessage md3 = peer.requestMetadata().get(10, TimeUnit.SECONDS);
    assertThat(md3.getSeqNumber()).isGreaterThan(md2.getSeqNumber());
    assertThat(md3.getAttnets().getBitCount()).isEqualTo(3);
    assertThat(md3.getAttnets().getBit(0)).isTrue();
    assertThat(md3.getAttnets().getBit(1)).isTrue();
    assertThat(md3.getAttnets().getBit(8)).isTrue();
}
Also used : MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with Eth2Peer

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

the class GetMetadataIntegrationTest method requestMetadata_shouldSendLatestSyncnets.

@Test
public void requestMetadata_shouldSendLatestSyncnets() throws Exception {
    final PeerAndNetwork peerAndNetwork = createRemotePeerAndNetwork(true, true);
    final Eth2Peer peer = peerAndNetwork.getPeer();
    MetadataMessage md1 = peer.requestMetadata().get(10, TimeUnit.SECONDS);
    MetadataMessage md2 = peer.requestMetadata().get(10, TimeUnit.SECONDS);
    assertThat(md1.getSeqNumber()).isEqualTo(md2.getSeqNumber());
    assertThat(md1.getAttnets().getBitCount()).isEqualTo(0);
    // Subscribe to some sync committee subnets
    peerAndNetwork.getNetwork().subscribeToSyncCommitteeSubnetId(1);
    peerAndNetwork.getNetwork().subscribeToSyncCommitteeSubnetId(2);
    MetadataMessage md3 = peer.requestMetadata().get(10, TimeUnit.SECONDS);
    assertThat(md3).isInstanceOf(MetadataMessageAltair.class);
    final MetadataMessageAltair altairMetadata = (MetadataMessageAltair) md3;
    // Check metadata
    assertThat(altairMetadata.getSeqNumber()).isGreaterThan(md2.getSeqNumber());
    assertThat(altairMetadata.getSyncnets().getBitCount()).isEqualTo(2);
    assertThat(altairMetadata.getSyncnets().getBit(1)).isTrue();
    assertThat(altairMetadata.getSyncnets().getBit(2)).isTrue();
    // Unsubscribe from sync committee subnet
    peerAndNetwork.getNetwork().unsubscribeFromSyncCommitteeSubnetId(2);
    MetadataMessage md4 = peer.requestMetadata().get(10, TimeUnit.SECONDS);
    assertThat(md4).isInstanceOf(MetadataMessageAltair.class);
    final MetadataMessageAltair altairMetadata2 = (MetadataMessageAltair) md4;
    // Check metadata
    assertThat(altairMetadata2.getSeqNumber()).isGreaterThan(altairMetadata.getSeqNumber());
    assertThat(altairMetadata2.getSyncnets().getBitCount()).isEqualTo(1);
    assertThat(altairMetadata2.getSyncnets().getBit(1)).isTrue();
}
Also used : MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) MetadataMessageAltair(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.altair.MetadataMessageAltair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with Eth2Peer

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

the class BeaconBlocksByRangeIntegrationTest method requestBlockByRootAfterPeerDisconnected.

@Test
public void requestBlockByRootAfterPeerDisconnected() 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 SafeFuture<Optional<SignedBeaconBlock>> res = peer.requestBlockBySlot(UInt64.ONE);
    waitFor(() -> assertThat(res).isDone());
    assertThat(res).isCompletedExceptionally();
    assertThatThrownBy(res::get).hasRootCauseInstanceOf(PeerDisconnectedException.class);
}
Also used : Optional(java.util.Optional) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with Eth2Peer

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

the class BeaconBlocksByRangeIntegrationTest method shouldSendEmptyResponsePreGenesisEvent.

@Test
public void shouldSendEmptyResponsePreGenesisEvent() throws Exception {
    final Eth2Peer peer = createPeer();
    final List<SignedBeaconBlock> response = requestBlocks(peer);
    assertThat(response).isEmpty();
}
Also used : Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) 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