@Override
  protected void executeTask() {
    if (maximumPossibleCommonAncestorNumber == minimumPossibleCommonAncestorNumber) {
      // Bingo, we found our common ancestor.
      result.complete(commonAncestorCandidate);
      return;
    }
    if (maximumPossibleCommonAncestorNumber < BlockHeader.GENESIS_BLOCK_NUMBER
        && !result.isDone()) {
      result.completeExceptionally(new IllegalStateException("No common ancestor."));
      return;
    }

    if (synchronizerConfiguration.isPeerTaskSystemEnabled()) {
      ethContext
          .getScheduler()
          .scheduleServiceTask(
              () -> {
                do {
                  PeerTaskExecutorResult<List<BlockHeader>> taskResult =
                      requestHeadersUsingPeerTaskSystem();
                  if (taskResult.responseCode() == PeerTaskExecutorResponseCode.PEER_DISCONNECTED) {
                    result.completeExceptionally(new PeerDisconnectedException(peer));
                    continue;
                  } else if (taskResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS
                      || taskResult.result().isEmpty()) {
                    result.completeExceptionally(
                        new RuntimeException(
                            "Peer failed to successfully return requested block headers"));
                    continue;
                  }
                  taskResult.ethPeer().ifPresent((peer) -> taskResult.result().get().getFirst());
                  processHeaders(taskResult.result().get());
                  if (maximumPossibleCommonAncestorNumber == minimumPossibleCommonAncestorNumber) {
                    // Bingo, we found our common ancestor.
                    result.complete(commonAncestorCandidate);
                  } else if (maximumPossibleCommonAncestorNumber < BlockHeader.GENESIS_BLOCK_NUMBER
                      && !result.isDone()) {
                    result.completeExceptionally(new IllegalStateException("No common ancestor."));
                  }
                } while (!result.isDone());
              });

    } else {
      requestHeaders()
          .thenApply(AbstractPeerTask.PeerTaskResult::getResult)
          .thenCompose(this::processHeaders)
          .whenComplete(
              (peerResult, error) -> {
                if (error != null) {
                  result.completeExceptionally(error);
                } else if (!result.isDone()) {
                  executeTaskTimed();
                }
              });
    }
  }
Finds the common ancestor with the given peer. It is assumed that the peer will at least share
the same genesis block with this node. Running this task against a peer with a non-matching
genesis block will result in undefined behavior: the task may complete exceptionally or in some
cases this node's genesis block will be returned.
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTask.java