@Test void sync_badAdvertisedFinalizedEpoch() { final SafeFuture<Void> requestFuture = new SafeFuture<>(); when(peer.requestBlocksByRange(any(), any(), any(), any())).thenReturn(requestFuture); final SafeFuture<PeerSyncResult> syncFuture = peerSync.sync(peer); assertThat(syncFuture).isNotDone(); verify(peer) .requestBlocksByRange( any(), any(), eq(UInt64.ONE), responseListenerArgumentCaptor.capture()); final ResponseStreamListener<SignedBeaconBlock> responseListener = responseListenerArgumentCaptor.getValue(); final List<SignedBeaconBlock> blocks = respondWithBlocksAtSlots(responseListener, UInt64.ONE, PEER_HEAD_SLOT); for (SignedBeaconBlock block : blocks) { verify(blockImporter).importBlock(block); } assertThat(syncFuture).isNotDone(); when(storageClient.getFinalizedEpoch()).thenReturn(PEER_FINALIZED_EPOCH.minus(UInt64.ONE)); requestFuture.complete(null); assertThat(syncFuture).isCompleted(); verify(peer).disconnectCleanly(DisconnectReason.REMOTE_FAULT); }
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();  }