@Test public void chainsAreCompatible_remoteChainIsBehind() { forksMatch(); remoteChainIsBehindOnSameChain(); final SafeFuture<Boolean> result = peerChainValidator.validate(peer, remoteStatus); assertPeerChainVerified(result); }
public SafeFuture<Boolean> validate(final Eth2Peer peer, final PeerStatus newStatus) { LOG.trace("Validate chain of peer: {}", peer.getId()); validationStartedCounter.inc(); return isRemoteChainValid(peer, newStatus) .thenApply( isValid -> { if (!isValid) { LOG.trace("Disconnecting peer on different chain: {}", peer.getId()); chainInvalidCounter.inc(); peer.disconnectCleanly(DisconnectReason.IRRELEVANT_NETWORK).reportExceptions(); } else { LOG.trace("Validated peer's chain: {}", peer.getId()); chainValidCounter.inc(); } return isValid; }) .exceptionally( err -> { LOG.debug("Unable to validate peer's chain, disconnecting {}", peer.getId(), err); validationErrorCounter.inc(); peer.disconnectCleanly(DisconnectReason.UNABLE_TO_VERIFY_NETWORK).reportExceptions(); return false; }); }
PeerChainValidator { public SafeFuture<Boolean> validate(final Eth2Peer peer, final PeerStatus newStatus) { LOG.trace("Validate chain of peer: {}", peer.getId()); validationStartedCounter.inc(); return isRemoteChainValid(peer, newStatus) .thenApply( isValid -> { if (!isValid) { LOG.trace("Disconnecting peer on different chain: {}", peer.getId()); chainInvalidCounter.inc(); peer.disconnectCleanly(DisconnectReason.IRRELEVANT_NETWORK).reportExceptions(); } else { LOG.trace("Validated peer's chain: {}", peer.getId()); chainValidCounter.inc(); } return isValid; }) .exceptionally( err -> { LOG.debug("Unable to validate peer's chain, disconnecting {}", peer.getId(), err); validationErrorCounter.inc(); peer.disconnectCleanly(DisconnectReason.UNABLE_TO_VERIFY_NETWORK).reportExceptions(); return false; }); } }
PeerChainValidator { public SafeFuture<Boolean> validate(final Eth2Peer peer, final PeerStatus newStatus) { LOG.trace("Validate chain of peer: {}", peer.getId()); validationStartedCounter.inc(); return isRemoteChainValid(peer, newStatus) .thenApply( isValid -> { if (!isValid) { LOG.trace("Disconnecting peer on different chain: {}", peer.getId()); chainInvalidCounter.inc(); peer.disconnectCleanly(DisconnectReason.IRRELEVANT_NETWORK).reportExceptions(); } else { LOG.trace("Validated peer's chain: {}", peer.getId()); chainValidCounter.inc(); } return isValid; }) .exceptionally( err -> { LOG.debug("Unable to validate peer's chain, disconnecting {}", peer.getId(), err); validationErrorCounter.inc(); peer.disconnectCleanly(DisconnectReason.UNABLE_TO_VERIFY_NETWORK).reportExceptions(); return false; }); } private  PeerChainValidator(
      final MetricsSystem metricsSystem,
      final CombinedChainDataClient chainDataClient,
      final Optional<Checkpoint> requiredCheckpoint); }
PeerChainValidator { public SafeFuture<Boolean> validate(final Eth2Peer peer, final PeerStatus newStatus) { LOG.trace("Validate chain of peer: {}", peer.getId()); validationStartedCounter.inc(); return isRemoteChainValid(peer, newStatus) .thenApply( isValid -> { if (!isValid) { LOG.trace("Disconnecting peer on different chain: {}", peer.getId()); chainInvalidCounter.inc(); peer.disconnectCleanly(DisconnectReason.IRRELEVANT_NETWORK).reportExceptions(); } else { LOG.trace("Validated peer's chain: {}", peer.getId()); chainValidCounter.inc(); } return isValid; }) .exceptionally( err -> { LOG.debug("Unable to validate peer's chain, disconnecting {}", peer.getId(), err); validationErrorCounter.inc(); peer.disconnectCleanly(DisconnectReason.UNABLE_TO_VERIFY_NETWORK).reportExceptions(); return false; }); } private  PeerChainValidator(
      final MetricsSystem metricsSystem,
      final CombinedChainDataClient chainDataClient,
      final Optional<Checkpoint> requiredCheckpoint); static PeerChainValidator create(
      final MetricsSystem metricsSystem,
      final CombinedChainDataClient chainDataClient,
      final Optional<Checkpoint> requiredCheckpoint); SafeFuture<Boolean> validate(final Eth2Peer peer, final PeerStatus newStatus); }
PeerChainValidator { public SafeFuture<Boolean> validate(final Eth2Peer peer, final PeerStatus newStatus) { LOG.trace("Validate chain of peer: {}", peer.getId()); validationStartedCounter.inc(); return isRemoteChainValid(peer, newStatus) .thenApply( isValid -> { if (!isValid) { LOG.trace("Disconnecting peer on different chain: {}", peer.getId()); chainInvalidCounter.inc(); peer.disconnectCleanly(DisconnectReason.IRRELEVANT_NETWORK).reportExceptions(); } else { LOG.trace("Validated peer's chain: {}", peer.getId()); chainValidCounter.inc(); } return isValid; }) .exceptionally( err -> { LOG.debug("Unable to validate peer's chain, disconnecting {}", peer.getId(), err); validationErrorCounter.inc(); peer.disconnectCleanly(DisconnectReason.UNABLE_TO_VERIFY_NETWORK).reportExceptions(); return false; }); } private  PeerChainValidator(
      final MetricsSystem metricsSystem,
      final CombinedChainDataClient chainDataClient,
      final Optional<Checkpoint> requiredCheckpoint); static PeerChainValidator create(
      final MetricsSystem metricsSystem,
      final CombinedChainDataClient chainDataClient,
      final Optional<Checkpoint> requiredCheckpoint); SafeFuture<Boolean> validate(final Eth2Peer peer, final PeerStatus newStatus);  }