private CompletableFuture<BlockHeader> executePivotQueryWithPeerTaskSystem(
      final long blockNumber) {
    GetHeadersFromPeerTask task =
        new GetHeadersFromPeerTask(
            blockNumber, 1, 0, GetHeadersFromPeerTask.Direction.FORWARD, protocolSchedule);
    Optional<EthPeer> maybeEthPeer;
    final EthPeer ethPeer;
    try {
      do {
        if (isCancelled.get()) {
          return CompletableFuture.failedFuture(
              new CancellationException("Pivot block confirmation has been cancelled"));
        }
        maybeEthPeer =
            ethContext
                .getEthPeers()
                .getPeer(
                    (p) ->
                        task.getPeerRequirementFilter().test(p)
                            && !peerIdsUsed.contains(p.nodeId()));
      } while (maybeEthPeer.isEmpty() && waitForPeer());
      ethPeer = maybeEthPeer.get();
      peerIdsUsed.add(ethPeer.nodeId());
    } catch (InterruptedException e) {
      return CompletableFuture.failedFuture(e);
    }

    return ethContext
        .getScheduler()
        .scheduleServiceTask(
            () -> {
              PeerTaskExecutorResult<List<BlockHeader>> taskResult =
                  ethContext.getPeerTaskExecutor().executeAgainstPeer(task, ethPeer);
              if (taskResult.responseCode() == PeerTaskExecutorResponseCode.INTERNAL_SERVER_ERROR) {
                // something is probably wrong with the request, so we won't retry as below
                return CompletableFuture.failedFuture(
                    new RuntimeException("Unexpected internal issue"));
              } else if (taskResult.responseCode() != PeerTaskExecutorResponseCode.SUCCESS
                  || taskResult.result().isEmpty()) {
                // recursively call executePivotQueryWithPeerTaskSystem to retry with a different
                // peer.
                return executePivotQueryWithPeerTaskSystem(blockNumber);
              }
              return CompletableFuture.completedFuture(taskResult.result().get().getFirst());
            });
  }
This task will query {@code numberOfPeersToQuery} peers for a particular block number. If any
peers disagree on the block at this number, the task fails with a {@code
ContestedPivotBlockException}. The task will succeed only if {@code numberOfPeersToQuery}
distinct peers all return matching block headers for the specified block number.
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmer.java