private List<LogWithMetadata> matchingLogsUncached(
      final long fromBlockNumber,
      final long toBlockNumber,
      final LogsQuery query,
      final Supplier<Boolean> isQueryAlive) {
    // rangeClosed handles the inverted from/to situations automatically with zero results.
    return LongStream.rangeClosed(fromBlockNumber, toBlockNumber)
        .mapToObj(blockchain::getBlockHeader)
        // Use takeWhile instead of clamping on toBlockNumber/headBlockNumber because it may get an
        // extra block or two for a query that has a toBlockNumber past chain head.  Similarly this
        // handles the case when fromBlockNumber is past chain head.
        .takeWhile(Optional::isPresent)
        .map(Optional::get)
        .filter(header -> query.couldMatch(header.getLogsBloom()))
        .flatMap(header -> matchingLogs(header.getHash(), query, isQueryAlive).stream())
        .collect(Collectors.toList());
  }
Retrieve logs from the range of blocks with optional filtering based on logger address and log
topics.

@param fromBlockNumber The block number defining the first block in the search range
    (inclusive).
@param toBlockNumber The block number defining the last block in the search range (inclusive).
@param query Constraints on required topics by topic index. For a given index if the set of
    topics is non-empty, the topic at this index must match one of the values in the set.
@param isQueryAlive Whether the backend query should stay alive.
@return The set of logs matching the given constraints.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java