use of org.hyperledger.besu.evm.log.LogsBloomFilter in project besu by hyperledger.
the class LogsWrapper method readFrom.
/**
* Creates a transaction receipt for the given RLP
*
* @param rlpInput the RLP-encoded transaction receipt
* @param revertReasonAllowed whether the rlp input is allowed to have a revert reason
* @return the transaction receipt
*/
public static TransactionReceipt readFrom(final RLPInput rlpInput, final boolean revertReasonAllowed) {
RLPInput input = rlpInput;
TransactionType transactionType = TransactionType.FRONTIER;
if (!rlpInput.nextIsList()) {
final Bytes typedTransactionReceiptBytes = input.readBytes();
transactionType = TransactionType.of(typedTransactionReceiptBytes.get(0));
input = new BytesValueRLPInput(typedTransactionReceiptBytes.slice(1), false);
}
input.enterList();
// Get the first element to check later to determine the
// correct transaction receipt encoding to use.
final RLPInput firstElement = input.readAsRlp();
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.
final LogsBloomFilter bloomFilter = LogsBloomFilter.readFrom(input);
final List<Log> logs = input.readList(Log::readFrom);
final Optional<Bytes> revertReason;
if (input.isEndOfCurrentList()) {
revertReason = Optional.empty();
} else {
if (!revertReasonAllowed) {
throw new RLPException("Unexpected value at end of TransactionReceipt");
}
revertReason = Optional.of(input.readBytes());
}
// byte for success (0x01) or failure (0x80).
if (firstElement.raw().size() == 1) {
final int status = firstElement.readIntScalar();
input.leaveList();
return new TransactionReceipt(transactionType, status, cumulativeGas, logs, bloomFilter, revertReason);
} else {
final Hash stateRoot = Hash.wrap(firstElement.readBytes32());
input.leaveList();
return new TransactionReceipt(transactionType, stateRoot, cumulativeGas, logs, bloomFilter, revertReason);
}
}
use of org.hyperledger.besu.evm.log.LogsBloomFilter in project hedera-mirror-node by hashgraph.
the class LogsBloomAggregatorTest method topicsMustBeFoundInsideAggregatedBloom.
@Test
void topicsMustBeFoundInsideAggregatedBloom() {
LogsBloomAggregator bloomAggregator = new LogsBloomAggregator();
String bloom1 = "00000004000000001000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000100000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000004000000000000000000000000000000000000000000000040000000000000000000000000000000001000000000000000000000000000000000000000000000001000000000000100000080000000000000000000000000000000000000000000000000000000000000000000000000";
bloomAggregator.aggregate(ByteString.fromHex(bloom1).toByteArray());
String bloom2 = "00000004000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008004000000000000000000000000000000000000000000000040000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000100002080000000000000000000000000000000000000000000000400000000000000000000000000";
bloomAggregator.aggregate(ByteString.fromHex(bloom2).toByteArray());
String[] topics = { // topic0 from bloom1
"2F8788117E7EFF1D82E926EC794901D17C78024A50270940304540A733656F0D", // topic1 from bloom1
"9F2DF0FED2C77648DE5860A4CC508CD0818C85B8B8A1AB4CEEEF8D981C8956A6", // evm address from bloom1
"00000000000000000000000000000000000D98C7", // topic0 from bloom2
"2F8788117E7EFF1D82E926EC794901D17C78024A50270940304540A733656F0D", // topic1 from bloom2
"65D7A28E3265B37A6474929F336521B332C1681B933F6CB9F3376673440D862A", // evm address from bloom2
"00000000000000000000000000000000000D98C7" };
for (var topic : topics) {
LogsBloomFilter topicBloom = LogsBloomFilter.builder().insertBytes(Bytes.fromHexString(topic)).build();
assertTrue(bloomAggregator.couldContain(topicBloom.toArray()), topic);
}
String[] stringsNotPresentInAnyBloom = { "FF2F8788117E7EFF1D82E926EC794901D17C78024A50270940304540A733656F0D", "AA9F2DF0FED2C77648DE5860A4CC508CD0818C85B8B8A1AB4CEEEF8D981C8956A6" };
for (var str : stringsNotPresentInAnyBloom) {
LogsBloomFilter bloom = LogsBloomFilter.builder().insertBytes(Bytes.fromHexString(str)).build();
assertFalse(bloomAggregator.couldContain(bloom.toArray()), str);
}
}
use of org.hyperledger.besu.evm.log.LogsBloomFilter in project besu by hyperledger.
the class BlockHeader method readFrom.
public static BlockHeader readFrom(final RLPInput input, final BlockHeaderFunctions blockHeaderFunctions) {
input.enterList();
final Hash parentHash = Hash.wrap(input.readBytes32());
final Hash ommersHash = Hash.wrap(input.readBytes32());
final Address coinbase = Address.readFrom(input);
final Hash stateRoot = Hash.wrap(input.readBytes32());
final Hash transactionsRoot = Hash.wrap(input.readBytes32());
final Hash receiptsRoot = Hash.wrap(input.readBytes32());
final LogsBloomFilter logsBloom = LogsBloomFilter.readFrom(input);
final Difficulty difficulty = Difficulty.of(input.readUInt256Scalar());
final long number = input.readLongScalar();
final long gasLimit = input.readLongScalar();
final long gasUsed = input.readLongScalar();
final long timestamp = input.readLongScalar();
final Bytes extraData = input.readBytes();
final Bytes32 mixHashOrPrevRandao = input.readBytes32();
final long nonce = input.readLong();
final Wei baseFee = !input.isEndOfCurrentList() ? Wei.of(input.readUInt256Scalar()) : null;
input.leaveList();
return new BlockHeader(parentHash, ommersHash, coinbase, stateRoot, transactionsRoot, receiptsRoot, logsBloom, difficulty, number, gasLimit, gasUsed, timestamp, extraData, baseFee, mixHashOrPrevRandao, nonce, blockHeaderFunctions);
}
use of org.hyperledger.besu.evm.log.LogsBloomFilter in project besu by hyperledger.
the class JsonRpcResponseUtils method response.
/**
* @param values hex encoded values.
*/
public JsonRpcResponse response(final Map<JsonRpcResponseKey, String> values, final List<TransactionResult> transactions) {
final Hash mixHash = hash(values.get(MIX_HASH));
final Hash parentHash = hash(values.get(PARENT_HASH));
final Hash ommersHash = hash(values.get(OMMERS_HASH));
final Address coinbase = address(values.get(COINBASE));
final Hash stateRoot = hash(values.get(STATE_ROOT));
final Hash transactionsRoot = hash(values.get(TRANSACTION_ROOT));
final Hash receiptsRoot = hash(values.get(RECEIPTS_ROOT));
final LogsBloomFilter logsBloom = logsBloom(values.get(LOGS_BLOOM));
final Difficulty difficulty = Difficulty.of(unsignedInt256(values.get(DIFFICULTY)));
final Bytes extraData = bytes(values.get(EXTRA_DATA));
final BlockHeaderFunctions blockHeaderFunctions = new MainnetBlockHeaderFunctions();
final long number = unsignedLong(values.get(NUMBER));
final long gasLimit = unsignedLong(values.get(GAS_LIMIT));
final long gasUsed = unsignedLong(values.get(GAS_USED));
final long timestamp = unsignedLong(values.get(TIMESTAMP));
final long nonce = unsignedLong(values.get(NONCE));
final Wei baseFee = values.containsKey(BASEFEE) ? Wei.of(unsignedInt256(values.get(BASEFEE))) : null;
final Difficulty totalDifficulty = Difficulty.of(unsignedInt256(values.get(TOTAL_DIFFICULTY)));
final int size = unsignedInt(values.get(SIZE));
final List<JsonNode> ommers = new ArrayList<>();
final BlockHeader header = new BlockHeader(parentHash, ommersHash, coinbase, stateRoot, transactionsRoot, receiptsRoot, logsBloom, difficulty, number, gasLimit, gasUsed, timestamp, extraData, baseFee, mixHash, nonce, blockHeaderFunctions);
return new JsonRpcSuccessResponse(null, new BlockResult(header, transactions, ommers, totalDifficulty, size));
}
use of org.hyperledger.besu.evm.log.LogsBloomFilter in project besu by hyperledger.
the class BlockchainQueries method matchingLogsCached.
private List<LogWithMetadata> matchingLogsCached(final long segmentStart, final long offset, final long endOffset, final LogsQuery query, final Path cacheFile, final Supplier<Boolean> isQueryAlive) throws Exception {
final List<LogWithMetadata> results = new ArrayList<>();
try (final RandomAccessFile raf = new RandomAccessFile(cacheFile.toFile(), "r")) {
raf.seek(offset * 256);
final byte[] bloomBuff = new byte[256];
final Bytes bytesValue = Bytes.wrap(bloomBuff);
for (long pos = offset; pos <= endOffset; pos++) {
BackendQuery.stopIfExpired(isQueryAlive);
try {
raf.readFully(bloomBuff);
} catch (final EOFException e) {
results.addAll(matchingLogsUncached(segmentStart + pos, segmentStart + endOffset, query, isQueryAlive));
break;
}
final LogsBloomFilter logsBloom = new LogsBloomFilter(bytesValue);
if (query.couldMatch(logsBloom)) {
results.addAll(matchingLogs(blockchain.getBlockHashByNumber(segmentStart + pos).orElseThrow(), query, isQueryAlive));
}
}
} catch (final IOException e) {
e.printStackTrace(System.out);
LOG.error("Error reading cached log blooms", e);
}
return results;
}
Aggregations