Search in sources :

Example 11 with Eth2Peer

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

the class BeaconBlocksByRangeIntegrationTest method shouldRespondWithBlocksFromCanonicalChain.

@Test
public void shouldRespondWithBlocksFromCanonicalChain() throws Exception {
    final Eth2Peer peer = createPeer();
    final SignedBlockAndState block1 = peerStorage.chainUpdater().advanceChain();
    final SignedBlockAndState block2 = peerStorage.chainUpdater().advanceChain();
    peerStorage.chainUpdater().updateBestBlock(block2);
    final List<SignedBeaconBlock> response = requestBlocks(peer);
    assertThat(response).containsExactly(block1.getBlock(), block2.getBlock());
}
Also used : 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 12 with Eth2Peer

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

the class PeerStatusIntegrationTest method shouldExchangeStatusMessagesOnConnection.

@Test
public void shouldExchangeStatusMessagesOnConnection() throws Exception {
    final StorageSystem system2 = createStorageSystem();
    final RecentChainData recentChainData2 = system2.recentChainData();
    assertThat(recentChainData1.getBestBlockRoot()).isEqualTo(recentChainData2.getBestBlockRoot());
    final Eth2P2PNetwork network1 = networkFactory.builder().spec(spec).rpcEncoding(rpcEncoding).recentChainData(recentChainData1).startNetwork();
    final Eth2P2PNetwork network2 = networkFactory.builder().spec(spec).rpcEncoding(rpcEncoding).recentChainData(recentChainData2).startNetwork();
    waitFor(network1.connect(network1.createPeerAddress(network2.getNodeAddress())));
    waitFor(() -> {
        assertThat(network1.getPeerCount()).isEqualTo(1);
        assertThat(network2.getPeerCount()).isEqualTo(1);
    });
    final Eth2Peer network2ViewOfPeer1 = network2.getPeer(network1.getNodeId()).orElseThrow();
    assertStatusMatchesStorage(recentChainData1, network2ViewOfPeer1.getStatus());
    final Eth2Peer network1ViewOfPeer2 = network1.getPeer(network2.getNodeId()).orElseThrow();
    assertStatusMatchesStorage(recentChainData2, network1ViewOfPeer2.getStatus());
    // When the finalized epoch is genesis we should use a zero finalized root (from the state)
    // This differs from what recentChainData.getFinalizedCheckpoint will have at genesis
    assertThat(network1ViewOfPeer2.getStatus().getFinalizedRoot()).isEqualTo(Bytes32.ZERO);
}
Also used : RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) Test(org.junit.jupiter.api.Test)

Example 13 with Eth2Peer

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

the class PeerStatusIntegrationTest method shouldUpdatePeerStatus.

@Test
public void shouldUpdatePeerStatus() throws Exception {
    final Eth2P2PNetwork network1 = networkFactory.builder().spec(spec).rpcEncoding(rpcEncoding).recentChainData(recentChainData1).startNetwork();
    final StorageSystem storageSystem2 = createStorageSystem();
    final RecentChainData recentChainData2 = storageSystem2.recentChainData();
    final Eth2P2PNetwork network2 = networkFactory.builder().spec(spec).rpcEncoding(rpcEncoding).recentChainData(recentChainData2).peer(network1).startNetwork();
    final Eth2Peer network2ViewOfPeer1 = network2.getPeer(network1.getNodeId()).orElseThrow();
    assertStatusMatchesStorage(recentChainData1, network2ViewOfPeer1.getStatus());
    // Peer 1 advances
    this.storageSystem.chainUpdater().advanceChain(10);
    final PeerStatus updatedStatusData = waitFor(network2ViewOfPeer1.sendStatus());
    assertStatusMatchesStorage(recentChainData1, updatedStatusData);
    assertStatusMatchesStorage(recentChainData1, network2ViewOfPeer1.getStatus());
}
Also used : RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) PeerStatus(tech.pegasys.teku.networking.eth2.peers.PeerStatus) Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) Test(org.junit.jupiter.api.Test)

Example 14 with Eth2Peer

use of tech.pegasys.teku.networking.eth2.peers.Eth2Peer 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 15 with Eth2Peer

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

the class NetworkDataProviderTest method getPeerCount_shouldReturnTotalPeers.

@Test
void getPeerCount_shouldReturnTotalPeers() {
    final NetworkDataProvider network = new NetworkDataProvider(p2pNetwork);
    final Eth2Peer peer1 = mock(Eth2Peer.class);
    final Eth2Peer peer2 = mock(Eth2Peer.class);
    when(p2pNetwork.streamPeers()).thenReturn(Stream.of(peer1, peer2));
    assertThat(network.getPeerCount()).isEqualTo(2);
    verify(p2pNetwork).streamPeers();
}
Also used : Eth2Peer(tech.pegasys.teku.networking.eth2.peers.Eth2Peer) Test(org.junit.jupiter.api.Test)

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