@Test void sync_withPeerStatusUpdatedWhileSyncing() { final UInt64 initialPeerHeadSlot = PEER_HEAD_SLOT; final SafeFuture<Void> requestFuture1 = new SafeFuture<>(); final SafeFuture<Void> requestFuture2 = new SafeFuture<>(); when(peer.requestBlocksByRange(any(), any(), any(), any())) .thenReturn(requestFuture1) .thenReturn(requestFuture2); final SafeFuture<PeerSyncResult> syncFuture = peerSync.sync(peer); assertThat(syncFuture).isNotDone(); final UInt64 startSlot = UInt64.ONE; verify(peer) .requestBlocksByRange( eq(startSlot), eq(initialPeerHeadSlot), eq(UInt64.ONE), responseListenerArgumentCaptor.capture()); final UInt64 secondRequestSize = UInt64.valueOf(5); UInt64 updatedPeerHeadSlot = initialPeerHeadSlot.plus(secondRequestSize); withPeerHeadSlot(updatedPeerHeadSlot); final int lastReceivedBlockSlot = initialPeerHeadSlot.intValue(); completeRequestWithBlockAtSlot(requestFuture1, lastReceivedBlockSlot); final UInt64 nextSlotStart = UInt64.valueOf(lastReceivedBlockSlot + 1); verify(peer) .requestBlocksByRange( eq(nextSlotStart), eq(secondRequestSize), eq(UInt64.ONE), responseListenerArgumentCaptor.capture()); when(storageClient.getFinalizedEpoch()).thenReturn(PEER_FINALIZED_EPOCH); completeRequestWithBlockAtSlot(requestFuture2, updatedPeerHeadSlot); assertThat(syncFuture).isCompleted(); verify(peer, never()).disconnectCleanly(any()); }
public SafeFuture<PeerSyncResult> sync(final Eth2Peer peer) { LOG.debug("Start syncing to peer {}", peer); final UInt64 finalizedEpoch = storageClient.getFinalizedEpoch(); final UInt64 latestFinalizedSlot = compute_start_slot_at_epoch(finalizedEpoch); final UInt64 firstNonFinalSlot = latestFinalizedSlot.plus(UInt64.ONE); this.startingSlot = firstNonFinalSlot; return executeSync(peer, firstNonFinalSlot, SafeFuture.COMPLETE, true) .whenComplete( (res, err) -> { if (err != null) { LOG.debug("Failed to sync with peer {}: {}", peer, err); } else { LOG.debug("Finished syncing (with status {}) to peer {}", res.name(), peer); } }); }
PeerSync { public SafeFuture<PeerSyncResult> sync(final Eth2Peer peer) { LOG.debug("Start syncing to peer {}", peer); final UInt64 finalizedEpoch = storageClient.getFinalizedEpoch(); final UInt64 latestFinalizedSlot = compute_start_slot_at_epoch(finalizedEpoch); final UInt64 firstNonFinalSlot = latestFinalizedSlot.plus(UInt64.ONE); this.startingSlot = firstNonFinalSlot; return executeSync(peer, firstNonFinalSlot, SafeFuture.COMPLETE, true) .whenComplete( (res, err) -> { if (err != null) { LOG.debug("Failed to sync with peer {}: {}", peer, err); } else { LOG.debug("Finished syncing (with status {}) to peer {}", res.name(), peer); } }); } }
PeerSync { public SafeFuture<PeerSyncResult> sync(final Eth2Peer peer) { LOG.debug("Start syncing to peer {}", peer); final UInt64 finalizedEpoch = storageClient.getFinalizedEpoch(); final UInt64 latestFinalizedSlot = compute_start_slot_at_epoch(finalizedEpoch); final UInt64 firstNonFinalSlot = latestFinalizedSlot.plus(UInt64.ONE); this.startingSlot = firstNonFinalSlot; return executeSync(peer, firstNonFinalSlot, SafeFuture.COMPLETE, true) .whenComplete( (res, err) -> { if (err != null) { LOG.debug("Failed to sync with peer {}: {}", peer, err); } else { LOG.debug("Finished syncing (with status {}) to peer {}", res.name(), peer); } }); } PeerSync(
      final AsyncRunner asyncRunner,
      final RecentChainData storageClient,
      final BlockImporter blockImporter,
      final MetricsSystem metricsSystem); }
PeerSync { public SafeFuture<PeerSyncResult> sync(final Eth2Peer peer) { LOG.debug("Start syncing to peer {}", peer); final UInt64 finalizedEpoch = storageClient.getFinalizedEpoch(); final UInt64 latestFinalizedSlot = compute_start_slot_at_epoch(finalizedEpoch); final UInt64 firstNonFinalSlot = latestFinalizedSlot.plus(UInt64.ONE); this.startingSlot = firstNonFinalSlot; return executeSync(peer, firstNonFinalSlot, SafeFuture.COMPLETE, true) .whenComplete( (res, err) -> { if (err != null) { LOG.debug("Failed to sync with peer {}: {}", peer, err); } else { LOG.debug("Finished syncing (with status {}) to peer {}", res.name(), peer); } }); } PeerSync(
      final AsyncRunner asyncRunner,
      final RecentChainData storageClient,
      final BlockImporter blockImporter,
      final MetricsSystem metricsSystem); SafeFuture<PeerSyncResult> sync(final Eth2Peer peer); void stop(); UInt64 getStartingSlot(); }
PeerSync { public SafeFuture<PeerSyncResult> sync(final Eth2Peer peer) { LOG.debug("Start syncing to peer {}", peer); final UInt64 finalizedEpoch = storageClient.getFinalizedEpoch(); final UInt64 latestFinalizedSlot = compute_start_slot_at_epoch(finalizedEpoch); final UInt64 firstNonFinalSlot = latestFinalizedSlot.plus(UInt64.ONE); this.startingSlot = firstNonFinalSlot; return executeSync(peer, firstNonFinalSlot, SafeFuture.COMPLETE, true) .whenComplete( (res, err) -> { if (err != null) { LOG.debug("Failed to sync with peer {}: {}", peer, err); } else { LOG.debug("Finished syncing (with status {}) to peer {}", res.name(), peer); } }); } PeerSync(
      final AsyncRunner asyncRunner,
      final RecentChainData storageClient,
      final BlockImporter blockImporter,
      final MetricsSystem metricsSystem); SafeFuture<PeerSyncResult> sync(final Eth2Peer peer); void stop(); UInt64 getStartingSlot();  }