diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java index 4b49d760e8e..a918f9f13ca 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java @@ -590,6 +590,7 @@ private List matchingLogsCached( try { raf.readFully(bloomBuff); } catch (final EOFException e) { + results.addAll(matchingLogsUncached(segmentStart + pos, segmentStart + endOffset, query)); break; } final LogsBloomFilter logsBloom = new LogsBloomFilter(bytesValue); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java index 94317544c72..d4d399bc2f9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java @@ -175,12 +175,14 @@ private boolean populateLatestSegment() { try { final File currentFile = calculateCacheFileName(CURRENT, cacheDir); - final long segmentNumber = blockchain.getChainHeadBlockNumber() / BLOCKS_PER_BLOOM_CACHE; - long blockNumber = segmentNumber / BLOCKS_PER_BLOOM_CACHE; + final long chainHeadBlockNumber = blockchain.getChainHeadBlockNumber(); + final long segmentNumber = chainHeadBlockNumber / BLOCKS_PER_BLOOM_CACHE; + long blockNumber = + Math.min((segmentNumber + 1) * BLOCKS_PER_BLOOM_CACHE - 1, chainHeadBlockNumber); try (final OutputStream out = new FileOutputStream(currentFile)) { fillCacheFile(segmentNumber * BLOCKS_PER_BLOOM_CACHE, blockNumber, out); } - while (blockNumber <= blockchain.getChainHeadBlockNumber() + while (blockNumber <= chainHeadBlockNumber && (blockNumber % BLOCKS_PER_BLOOM_CACHE != 0)) { cacheSingleBlock(blockchain.getBlockHeader(blockNumber).orElseThrow(), currentFile); blockNumber++;