use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams in project besu by hyperledger.
the class DebugStandardTraceBadBlockToFile method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Hash blockHash = requestContext.getRequiredParameter(0, Hash.class);
final Optional<TransactionTraceParams> transactionTraceParams = requestContext.getOptionalParameter(1, TransactionTraceParams.class);
final Blockchain blockchain = blockchainQueries.get().getBlockchain();
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockchain.getChainHeadHeader().getNumber());
final BadBlockManager badBlockManager = protocolSpec.getBadBlocksManager();
return badBlockManager.getBadBlock(blockHash).map(block -> (JsonRpcResponse) new JsonRpcSuccessResponse(requestContext.getRequest().getId(), traceBlock(block, transactionTraceParams))).orElse(new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.BLOCK_NOT_FOUND));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams in project besu by hyperledger.
the class DebugStandardTraceBlockToFile method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Hash blockHash = requestContext.getRequiredParameter(0, Hash.class);
final Optional<TransactionTraceParams> transactionTraceParams = requestContext.getOptionalParameter(1, TransactionTraceParams.class);
return blockchainQueries.get().getBlockchain().getBlockByHash(blockHash).map(block -> (JsonRpcResponse) new JsonRpcSuccessResponse(requestContext.getRequest().getId(), traceBlock(block, transactionTraceParams))).orElse(new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.BLOCK_NOT_FOUND));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams in project besu by hyperledger.
the class DebugTraceBlockByNumber method resultByBlockNumber.
@Override
protected Object resultByBlockNumber(final JsonRpcRequestContext request, final long blockNumber) {
final Optional<Hash> blockHash = getBlockchainQueries().getBlockHashByNumber(blockNumber);
final TraceOptions traceOptions = request.getOptionalParameter(1, TransactionTraceParams.class).map(TransactionTraceParams::traceOptions).orElse(TraceOptions.DEFAULT);
return blockHash.flatMap(hash -> blockTracerSupplier.get().trace(hash, new DebugOperationTracer(traceOptions)).map(BlockTrace::getTransactionTraces).map(DebugTraceTransactionResult::of)).orElse(null);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams in project besu by hyperledger.
the class TransactionTracer method traceTransactionToFile.
public List<String> traceTransactionToFile(final Hash blockHash, final Optional<TransactionTraceParams> transactionTraceParams, final Path traceDir) {
final Optional<Hash> selectedHash = transactionTraceParams.map(TransactionTraceParams::getTransactionHash).map(Hash::fromHexString);
final boolean showMemory = transactionTraceParams.map(TransactionTraceParams::traceOptions).map(TraceOptions::isMemoryEnabled).orElse(true);
if (!Files.isDirectory(traceDir) && !traceDir.toFile().mkdirs()) {
throw new RuntimeException(String.format("Trace directory '%s' does not exist and could not be made.", traceDir));
}
return blockReplay.performActionWithBlock(blockHash, (body, header, blockchain, worldState, transactionProcessor) -> {
WorldUpdater stackedUpdater = worldState.updater().updater();
final List<String> traces = new ArrayList<>();
for (int i = 0; i < body.getTransactions().size(); i++) {
((StackedUpdater<?, ?>) stackedUpdater).markTransactionBoundary();
final Transaction transaction = body.getTransactions().get(i);
if (selectedHash.isEmpty() || selectedHash.filter(isEqual(transaction.getHash())).isPresent()) {
final File traceFile = generateTraceFile(traceDir, blockHash, i, transaction);
try (PrintStream out = new PrintStream(new FileOutputStream(traceFile))) {
final Stopwatch timer = Stopwatch.createStarted();
final TransactionProcessingResult result = processTransaction(header, blockchain, stackedUpdater, transaction, transactionProcessor, new StandardJsonTracer(out, showMemory));
out.println(summaryTrace(transaction, timer.stop().elapsed(TimeUnit.NANOSECONDS), result));
traces.add(traceFile.getPath());
} catch (FileNotFoundException e) {
throw new RuntimeException("Unable to create transaction trace : " + e.getMessage());
}
} else {
processTransaction(header, blockchain, stackedUpdater, transaction, transactionProcessor, OperationTracer.NO_TRACING);
}
}
return Optional.of(traces);
}).orElse(new ArrayList<>());
}
Aggregations