@Override
  public void trace(
      final long fromBlockNumber,
      final long toBlockNumber,
      final Consumer<WorldUpdater> beforeTracing,
      final Consumer<WorldUpdater> afterTracing,
      final BlockAwareOperationTracer tracer) {
    checkArgument(tracer != null);
    LOG.debug("Tracing from block {} to block {}", fromBlockNumber, toBlockNumber);
    final Blockchain blockchain = blockchainQueries.getBlockchain();
    final List<Block> blocks =
        LongStream.rangeClosed(fromBlockNumber, toBlockNumber)
            .mapToObj(
                number ->
                    blockchain
                        .getBlockByNumber(number)
                        .orElseThrow(() -> new RuntimeException("Block not found " + number)))
            .toList();
    Tracer.processTracing(
        blockchainQueries,
        blocks.getFirst().getHash(),
        traceableState -> {
          final WorldUpdater worldStateUpdater = traceableState.updater();
          final ChainUpdater chainUpdater = new ChainUpdater(traceableState, worldStateUpdater);
          beforeTracing.accept(worldStateUpdater);
          final List<TransactionProcessingResult> results = new ArrayList<>();
          blocks.forEach(block -> results.addAll(trace(blockchain, block, chainUpdater, tracer)));
          afterTracing.accept(chainUpdater.getNextUpdater());
          return Optional.of(results);
        });
  }
Traces range of blocks

@param fromBlockNumber the beginning of the range (inclusive)
@param toBlockNumber the end of the range (inclusive)
@param beforeTracing Function which performs an operation on a MutableWorldState before tracing
@param afterTracing Function which performs an operation on a MutableWorldState after tracing
@param tracer an instance of OperationTracer
app/src/main/java/org/hyperledger/besu/services/TraceServiceImpl.java