@Override
  public Optional<FastSyncState> selectNewPivotBlock() {

    final BftContext bftContext = protocolContext.getConsensusContext(BftContext.class);
    final ValidatorProvider validatorProvider = bftContext.getValidatorProvider();
    // See if we have a best peer
    Optional<EthPeer> bestPeer = selectBestPeer();

    if (bestPeer.isPresent()) {
      // For a recently created permissioned chain we can skip snap sync until we're past the
      // pivot distance
      if (bestPeer.get().chainState().getEstimatedHeight() <= syncConfig.getSyncPivotDistance()) {
        LOG.info(
            "Best peer for sync found but chain height hasn't reached minimum sync pivot distance {}, exiting sync process",
            syncConfig.getSyncPivotDistance());
        throw new NoSyncRequiredException();
      }

      return bestPeer.flatMap(this::fromBestPeer);
    } else {
      // Treat us being the only validator as a special case. We are the only node that can produce
      // blocks so we won't wait to sync with a non-validator node that may or may not exist
      if (weAreAValidator(validatorProvider)
          && validatorProvider.getValidatorsAtHead().size() == 1) {
        LOG.info("This node is the only BFT validator, exiting sync process");
        throw new NoSyncRequiredException();
      }

      // Treat the case where we are at block 0 and don't yet have any validator peers with a chain
      // height estimate as potentially a new QBFT chain. Check if any of the other peers have the
      // same block hash as our genesis block.
      if (blockHeader.getNumber() == 0) {
        final AtomicInteger peerValidatorCount = new AtomicInteger();
        final AtomicBoolean peerAtOurGenesisBlock = new AtomicBoolean();
        ethContext
            .getEthPeers()
            .streamAllPeers()
            .forEach(
                peer -> {
                  // If we are at block 0 and our block hash matches at least one of our peers we
                  // assume we're all at block 0 and therefore won't try to snap sync.
                  if (peer.chainState()
                      .getBestBlock()
                      .getHash()
                      .equals(blockHeader.getBlockHash())) {
                    peerAtOurGenesisBlock.set(true);
                  }
                  if (!peer.getConnection().isDisconnected()
                      && validatorProvider
                          .getValidatorsAtHead()
                          .contains(peer.getConnection().getPeerInfo().getAddress())) {
                    peerValidatorCount.getAndIncrement();
                  }
                });

        if (weAreAValidator(validatorProvider)
            && peerValidatorCount.get() >= syncConfig.getSyncMinimumPeerCount()
            && peerAtOurGenesisBlock.get()) {
          // We have sync-min-peers x validators connected, all of whom have no head estimate. We'll
          // assume this is a new chain and skip waiting for any more peers to sync with. The worst
          // case is this puts us into full sync mode.
          LOG.info(
              "Peered with {} validators but no best peer found to sync from and their current block hash matches our genesis block. Assuming new BFT chain, exiting snap-sync",
              peerValidatorCount.get());
          throw new NoSyncRequiredException();
        }
      }
    }

    return Optional.empty();
  }
Determine if our node is a BFT validator node

@param validatorProvider the validator provider
@return true if we are a validator
consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/BFTPivotSelectorFromPeers.java