LogBloomCache - Do uncached query if EOF is detected (#609)

If we detect an EOF for the cache file switch over to an uncached query.

This is typically seen when filling a log filter and the new block has
not yet written out the log bloom cache to disk.  Fixed #473

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
pull/610/head
Danno Ferrin 5 years ago committed by GitHub
parent 4fa78d61a3
commit 04044fdeba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java
  2. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/TransactionLogBloomCacher.java

@ -590,6 +590,7 @@ public class BlockchainQueries {
try { try {
raf.readFully(bloomBuff); raf.readFully(bloomBuff);
} catch (final EOFException e) { } catch (final EOFException e) {
results.addAll(matchingLogsUncached(segmentStart + pos, segmentStart + endOffset, query));
break; break;
} }
final LogsBloomFilter logsBloom = new LogsBloomFilter(bytesValue); final LogsBloomFilter logsBloom = new LogsBloomFilter(bytesValue);

@ -175,12 +175,14 @@ public class TransactionLogBloomCacher {
try { try {
final File currentFile = calculateCacheFileName(CURRENT, cacheDir); final File currentFile = calculateCacheFileName(CURRENT, cacheDir);
final long segmentNumber = blockchain.getChainHeadBlockNumber() / BLOCKS_PER_BLOOM_CACHE; final long chainHeadBlockNumber = blockchain.getChainHeadBlockNumber();
long blockNumber = segmentNumber / BLOCKS_PER_BLOOM_CACHE; 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)) { try (final OutputStream out = new FileOutputStream(currentFile)) {
fillCacheFile(segmentNumber * BLOCKS_PER_BLOOM_CACHE, blockNumber, out); fillCacheFile(segmentNumber * BLOCKS_PER_BLOOM_CACHE, blockNumber, out);
} }
while (blockNumber <= blockchain.getChainHeadBlockNumber() while (blockNumber <= chainHeadBlockNumber
&& (blockNumber % BLOCKS_PER_BLOOM_CACHE != 0)) { && (blockNumber % BLOCKS_PER_BLOOM_CACHE != 0)) {
cacheSingleBlock(blockchain.getBlockHeader(blockNumber).orElseThrow(), currentFile); cacheSingleBlock(blockchain.getBlockHeader(blockNumber).orElseThrow(), currentFile);
blockNumber++; blockNumber++;

Loading…
Cancel
Save