public void switchToNewPivotBlock(final BiConsumer<BlockHeader, Boolean> onSwitchDone) {
    lastPivotBlockFound.ifPresentOrElse(
        blockHeader -> {
          if (syncState.getPivotBlockHeader().filter(blockHeader::equals).isEmpty()) {
            LOG.atDebug()
                .setMessage("Setting new pivot block {} with state root {}")
                .addArgument(blockHeader::toLogString)
                .addArgument(blockHeader.getStateRoot())
                .log();
            syncState.setCurrentHeader(blockHeader);
            lastPivotBlockFound = Optional.empty();
          }
          onSwitchDone.accept(blockHeader, true);
        },
        () -> onSwitchDone.accept(syncState.getPivotBlockHeader().orElseThrow(), false));
  }
DynamicPivotBlockSelector is responsible for dynamically selecting the pivot block for Snapsync.
It uses an algorithm to find the most suitable pivot block based on the current network
conditions.
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/DynamicPivotBlockSelector.java