protected void handleTaskError(final Throwable error) {
    final Throwable cause = ExceptionUtils.rootCause(error);
    if (!isRetryableError(cause)) {
      // Complete exceptionally
      result.completeExceptionally(cause);
      return;
    }

    if (cause instanceof NoAvailablePeersException) {
      LOG.debug(
          "No useful peer found, wait max 5 seconds for new peer to connect: current peers {}",
          ethContext.getEthPeers().peerCount());

      executeSubTask(
          () ->
              ethContext
                  .getEthPeers()
                  .waitForPeer(this::isSuitablePeer)
                  .orTimeout(5, TimeUnit.SECONDS)
                  // execute the task again
                  .whenComplete((r, t) -> executeTaskTimed()));
      return;
    }

    LOG.atDebug()
        .setMessage("Retrying after recoverable failure from peer task {}: {}")
        .addArgument(this.getClass().getSimpleName())
        .addArgument(cause.getMessage())
        .log();
    // Wait before retrying on failure
    executeSubTask(
        () ->
            ethContext
                .getScheduler()
                .scheduleFutureTask(this::executeTaskTimed, Duration.ofSeconds(1)));
  }
Assign the peer to be used for the task.

@param peer The peer to assign to the task.
@return True if the peer was assigned, false otherwise.
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractRetryingPeerTask.java