Search in sources :

Example 1 with RespondingEth2Peer

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

the class HistoricalBlockSyncServiceTest method shouldRetrieveGenesisWhenMissing.

@Test
public void shouldRetrieveGenesisWhenMissing() {
    currentSyncState.set(SyncState.IN_SYNC);
    // Setup chain
    final int epochHeight = 10;
    final SignedBlockAndState genesis = storageSystem.chainBuilder().generateGenesis();
    storageSystem.chainBuilder().generateBlocksUpToSlot(6);
    initializeChainAtEpoch(UInt64.ZERO);
    final List<SignedBeaconBlock> expectedBlocks = List.of(genesis.getBlock());
    // Set up a peer to respond
    final RespondingEth2Peer peer = RespondingEth2Peer.create(spec, storageSystem.chainBuilder());
    peer.updateStatus(new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO), new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO));
    when(network.streamPeers()).thenAnswer(i -> Stream.of(peer));
    startService();
    // We should start sending requests to pull data
    assertThat(peer.getOutstandingRequests()).isEqualTo(1);
    finishSyncing(peer, expectedBlocks);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) RespondingEth2Peer(tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer) Test(org.junit.jupiter.api.Test)

Example 2 with RespondingEth2Peer

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

the class HistoricalBlockSyncServiceTest method shouldOnlySendOneRequestAtATime.

@Test
public void shouldOnlySendOneRequestAtATime() {
    currentSyncState.set(SyncState.IN_SYNC);
    // Setup chain
    final long epochHeight = 10;
    storageSystem.chainBuilder().generateGenesis();
    storageSystem.chainBuilder().generateBlocksUpToSlot(slotsPerEpoch * epochHeight + 3);
    final AnchorPoint anchor = initializeChainAtEpoch(storageSystem.chainBuilder().getLatestEpoch());
    final List<SignedBeaconBlock> expectedBlocks = storageSystem.chainBuilder().streamBlocksAndStates(0, anchor.getBlockSlot().longValue()).map(SignedBlockAndState::getBlock).collect(Collectors.toList());
    // Set up a peer to respond
    final RespondingEth2Peer peer = RespondingEth2Peer.create(spec, storageSystem.chainBuilder());
    peer.updateStatus(new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO), new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO));
    when(network.streamPeers()).thenAnswer(i -> Stream.of(peer));
    startService();
    final int maxRequests = storageSystem.chainBuilder().getLatestSlot().dividedBy(batchSize).plus(1).intValue();
    int requestCount = 0;
    while (service.isRunning() && requestCount <= maxRequests) {
        // Trigger some sync events
        updateSyncState(SyncState.SYNCING);
        updateSyncState(SyncState.IN_SYNC);
        // Peer should only have 1 outstanding request
        assertThat(peer.getOutstandingRequests()).isEqualTo(1);
        assertThat(asyncRunner.countDelayedActions()).isEqualTo(0);
        peer.completePendingRequests();
        requestCount++;
    }
    assertServiceFinished();
    assertBlocksSaved(expectedBlocks);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) RespondingEth2Peer(tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer) Test(org.junit.jupiter.api.Test)

Example 3 with RespondingEth2Peer

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

the class HistoricalBlockSyncServiceTest method assertServiceNotActive.

private void assertServiceNotActive(final RespondingEth2Peer... peers) {
    assertThat(service.isRunning()).isTrue();
    assertThat(syncStateSubscribers.getSubscriberCount()).isEqualTo(1);
    for (RespondingEth2Peer peer : peers) {
        assertThat(peer.getOutstandingRequests()).isEqualTo(0);
    }
    assertThat(asyncRunner.countDelayedActions()).isEqualTo(0);
}
Also used : RespondingEth2Peer(tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer)

Example 4 with RespondingEth2Peer

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

the class HistoricalBlockSyncServiceTest method shouldWaitToRunTillNodeIsInSync.

@Test
public void shouldWaitToRunTillNodeIsInSync() {
    currentSyncState.set(SyncState.SYNCING);
    // Setup chain
    final long epochHeight = 10;
    storageSystem.chainBuilder().generateGenesis();
    storageSystem.chainBuilder().generateBlocksUpToSlot(slotsPerEpoch * epochHeight + 3);
    final AnchorPoint anchor = initializeChainAtEpoch(storageSystem.chainBuilder().getLatestEpoch());
    final List<SignedBeaconBlock> expectedBlocks = storageSystem.chainBuilder().streamBlocksAndStates(0, anchor.getBlockSlot().longValue()).map(SignedBlockAndState::getBlock).collect(Collectors.toList());
    // Set up a peer to respond
    final RespondingEth2Peer peer = RespondingEth2Peer.create(spec, storageSystem.chainBuilder());
    peer.updateStatus(new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO), new Checkpoint(UInt64.valueOf(epochHeight * 2), Bytes32.ZERO));
    when(network.streamPeers()).thenAnswer(i -> Stream.of(peer));
    startService();
    // We should be waiting to actually start the historic sync
    assertServiceNotActive(peer);
    verify(storageUpdateChannel, never()).onFinalizedBlocks(any());
    // When we switch to in sync, the service should run and complete
    updateSyncState(SyncState.IN_SYNC);
    // We should start sending requests to pull data
    assertThat(peer.getOutstandingRequests()).isEqualTo(1);
    finishSyncing(peer, expectedBlocks);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) RespondingEth2Peer(tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer) Test(org.junit.jupiter.api.Test)

Example 5 with RespondingEth2Peer

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

the class HistoricalBlockSyncServiceTest method assertServiceIsWaitingForPeers.

private void assertServiceIsWaitingForPeers(final RespondingEth2Peer... peers) {
    assertThat(service.isRunning()).isTrue();
    assertThat(syncStateSubscribers.getSubscriberCount()).isEqualTo(1);
    for (RespondingEth2Peer peer : peers) {
        assertThat(peer.getOutstandingRequests()).isEqualTo(0);
    }
    assertThat(asyncRunner.countDelayedActions()).isEqualTo(1);
}
Also used : RespondingEth2Peer(tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer)

Aggregations

RespondingEth2Peer (tech.pegasys.teku.networking.eth2.peers.RespondingEth2Peer)7 Test (org.junit.jupiter.api.Test)5 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)5 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)5 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)5 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1