public <U> Optional<U> getAndMapWorldState(
      final Hash blockHash, final Function<MutableWorldState, ? extends Optional<U>> mapper) {

    return blockchain
        .getBlockHeader(blockHash)
        .flatMap(
            blockHeader -> {
              try (var ws =
                  worldStateArchive
                      .getWorldState(withBlockHeaderAndNoUpdateNodeHead(blockHeader))
                      .orElse(null)) {
                if (ws != null) {
                  return mapper.apply(ws);
                }
              } catch (Exception ex) {
                LOG.error("failed worldstate query for " + blockHash.toShortHexString(), ex);
              }
              LOG.atDebug()
                  .setMessage("Failed to find worldstate for {}")
                  .addArgument(blockHeader.toLogString())
                  .log();
              return Optional.empty();
            });
  }
Wraps an operation on MutableWorldState with try-with-resources the corresponding block hash.
This method provides access to the worldstate via a mapper function in order to ensure all uses
of the MutableWorldState are subsequently closed, via the try-with-resources block.

@param <U> return type of the operation on the MutableWorldState
@param blockHash the block hash
@param mapper Function which performs an operation on a MutableWorldState
@return the world state at the block number
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java