class BetterSyncTargetEvaluator {

  public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) {
    final ChainState currentPeerChainState = currentSyncTarget.chainState();
    final Optional<EthPeer> maybeBestPeer = ethPeers.bestPeer();

    return maybeBestPeer
        .map(
            bestPeer -> {
              if (EthPeers.BEST_CHAIN.compare(bestPeer, currentSyncTarget) <= 0) {
                // Our current target is better or equal to the best peer
                return false;
              }
              // Require some threshold to be exceeded before switching targets to keep some
              // stability when multiple peers are in range of each other
              final ChainState bestPeerChainState = bestPeer.chainState();
              final Difficulty tdDifference =
                  bestPeerChainState
                      .getEstimatedTotalDifficulty()
                      .subtract(currentPeerChainState.getBestBlock().getTotalDifficulty());
              if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) {
                return true;
              }
              final long heightDifference =
                  bestPeerChainState.getEstimatedHeight()
                      - currentPeerChainState.getEstimatedHeight();
              return heightDifference > config.getDownloaderChangeTargetThresholdByHeight();
            })
        .orElse(false);
  }

  public  BetterSyncTargetEvaluator(
      final SynchronizerConfiguration config, final EthPeers ethPeers);

}