Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Avoid recomputing the logs bloom filter when reading receipts from RLP (
Browse files Browse the repository at this point in the history
#1407)

Significantly reduces CPU usage during a fast sync.
  • Loading branch information
ajsutton authored May 7, 2019
1 parent f372f97 commit ae7d77a
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public class TransactionReceipt {
*/
public TransactionReceipt(
final Hash stateRoot, final long cumulativeGasUsed, final List<Log> logs) {
this(stateRoot, NONEXISTENT, cumulativeGasUsed, logs);
this(stateRoot, NONEXISTENT, cumulativeGasUsed, logs, LogsBloomFilter.compute(logs));
}

private TransactionReceipt(
final Hash stateRoot,
final long cumulativeGasUsed,
final List<Log> logs,
final LogsBloomFilter bloomFilter) {
this(stateRoot, NONEXISTENT, cumulativeGasUsed, logs, bloomFilter);
}

/**
Expand All @@ -63,16 +71,28 @@ public TransactionReceipt(
* @param logs the logs generated within the transaction
*/
public TransactionReceipt(final int status, final long cumulativeGasUsed, final List<Log> logs) {
this(null, status, cumulativeGasUsed, logs);
this(null, status, cumulativeGasUsed, logs, LogsBloomFilter.compute(logs));
}

private TransactionReceipt(
final int status,
final long cumulativeGasUsed,
final List<Log> logs,
final LogsBloomFilter bloomFilter) {
this(null, status, cumulativeGasUsed, logs, bloomFilter);
}

private TransactionReceipt(
final Hash stateRoot, final int status, final long cumulativeGasUsed, final List<Log> logs) {
final Hash stateRoot,
final int status,
final long cumulativeGasUsed,
final List<Log> logs,
final LogsBloomFilter bloomFilter) {
this.stateRoot = stateRoot;
this.cumulativeGasUsed = cumulativeGasUsed;
this.status = status;
this.logs = logs;
this.bloomFilter = LogsBloomFilter.compute(logs);
this.bloomFilter = bloomFilter;
transactionReceiptType =
stateRoot == null ? TransactionReceiptType.STATUS : TransactionReceiptType.ROOT;
}
Expand Down Expand Up @@ -115,17 +135,17 @@ public static TransactionReceipt readFrom(final RLPInput input) {
final long cumulativeGas = input.readLongScalar();
// The logs below will populate the bloom filter upon construction.
// TODO consider validating that the logs and bloom filter match.
input.skipNext();
final LogsBloomFilter bloomFilter = LogsBloomFilter.readFrom(input);
final List<Log> logs = input.readList(Log::readFrom);

// Status code-encoded transaction receipts have a single
// byte for success (0x01) or failure (0x80).
if (firstElement.raw().size() == 1) {
final int status = firstElement.readIntScalar();
return new TransactionReceipt(status, cumulativeGas, logs);
return new TransactionReceipt(status, cumulativeGas, logs, bloomFilter);
} else {
final Hash stateRoot = Hash.wrap(firstElement.readBytes32());
return new TransactionReceipt(stateRoot, cumulativeGas, logs);
return new TransactionReceipt(stateRoot, cumulativeGas, logs, bloomFilter);
}
} finally {
input.leaveList();
Expand Down

0 comments on commit ae7d77a

Please sign in to comment.