private CompletableFuture<List<BlockHeader>> downloadHeaderUsingPeerTaskSystem() {
    GetHeadersFromPeerTask task =
        hash.map(
                (h) ->
                    new GetHeadersFromPeerTask(
                        h, blockNumber, 1, 0, Direction.FORWARD, protocolSchedule))
            .orElseGet(
                () ->
                    new GetHeadersFromPeerTask(
                        blockNumber, 1, 0, Direction.FORWARD, protocolSchedule));
    PeerTaskExecutorResult<List<BlockHeader>> taskResult;
    if (assignedPeer.isPresent()) {
      taskResult = ethContext.getPeerTaskExecutor().executeAgainstPeer(task, assignedPeer.get());
    } else {
      taskResult = ethContext.getPeerTaskExecutor().execute(task);
    }

    CompletableFuture<List<BlockHeader>> returnValue = new CompletableFuture<List<BlockHeader>>();
    if (taskResult.responseCode() == PeerTaskExecutorResponseCode.PEER_DISCONNECTED
        && taskResult.ethPeer().isPresent()) {
      returnValue.completeExceptionally(new PeerDisconnectedException(taskResult.ethPeer().get()));
    } else if (taskResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS
        || taskResult.result().isEmpty()) {
      String logMessage =
          "Peer "
              + taskResult.ethPeer().map(EthPeer::getLoggableId).orElse("UNKNOWN")
              + " failed to successfully return requested block headers. Response code was "
              + taskResult.responseCode();
      returnValue.completeExceptionally(new RuntimeException(logMessage));
      LOG.debug(logMessage);
    } else {
      returnValue.complete(taskResult.result().get());
    }
    return returnValue;
  }
Downloads a block from a peer. Will complete exceptionally if block cannot be downloaded.
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java