Search in sources :

Example 1 with TransactionTraceParams

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));
}
Also used : JsonRpcError(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError) BadBlockManager(org.hyperledger.besu.ethereum.chain.BadBlockManager) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) TransactionTracer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) Supplier(java.util.function.Supplier) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Optional(java.util.Optional) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) Path(java.nio.file.Path) Hash(org.hyperledger.besu.datatypes.Hash) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) BadBlockManager(org.hyperledger.besu.ethereum.chain.BadBlockManager) Hash(org.hyperledger.besu.datatypes.Hash) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 2 with TransactionTraceParams

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));
}
Also used : JsonRpcError(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) TransactionTracer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) Supplier(java.util.function.Supplier) List(java.util.List) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Optional(java.util.Optional) Suppliers(com.google.common.base.Suppliers) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) TRACE_PATH(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer.TRACE_PATH) Block(org.hyperledger.besu.ethereum.core.Block) Path(java.nio.file.Path) Hash(org.hyperledger.besu.datatypes.Hash) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) Hash(org.hyperledger.besu.datatypes.Hash) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 3 with TransactionTraceParams

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);
}
Also used : TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) Supplier(java.util.function.Supplier) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) BlockParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) DebugTraceTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult) Optional(java.util.Optional) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) Hash(org.hyperledger.besu.datatypes.Hash) BlockTracer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer) DebugTraceTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) Hash(org.hyperledger.besu.datatypes.Hash)

Example 4 with TransactionTraceParams

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<>());
}
Also used : TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) StackedUpdater(org.hyperledger.besu.evm.worldstate.StackedUpdater) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) Stopwatch(com.google.common.base.Stopwatch) OperationTracer(org.hyperledger.besu.evm.tracing.OperationTracer) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) UInt256(org.apache.tuweni.units.bigints.UInt256) Path(java.nio.file.Path) PrintStream(java.io.PrintStream) Files(java.nio.file.Files) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Predicate.isEqual(java.util.function.Predicate.isEqual) FileOutputStream(java.io.FileOutputStream) MainnetTransactionProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor) BlockHashLookup(org.hyperledger.besu.ethereum.vm.BlockHashLookup) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ImmutableTransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.ImmutableTransactionValidationParams) Optional(java.util.Optional) Transaction(org.hyperledger.besu.ethereum.core.Transaction) StandardJsonTracer(org.hyperledger.besu.evm.tracing.StandardJsonTracer) Hash(org.hyperledger.besu.datatypes.Hash) PrintStream(java.io.PrintStream) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) Stopwatch(com.google.common.base.Stopwatch) FileNotFoundException(java.io.FileNotFoundException) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) Hash(org.hyperledger.besu.datatypes.Hash) StandardJsonTracer(org.hyperledger.besu.evm.tracing.StandardJsonTracer) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Transaction(org.hyperledger.besu.ethereum.core.Transaction) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

Optional (java.util.Optional)4 Hash (org.hyperledger.besu.datatypes.Hash)4 TransactionTraceParams (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams)4 Path (java.nio.file.Path)3 Supplier (java.util.function.Supplier)3 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)3 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)3 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 List (java.util.List)2 TransactionTracer (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer)2 JsonRpcError (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError)2 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)2 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)2 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)2 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)2 TraceOptions (org.hyperledger.besu.ethereum.debug.TraceOptions)2 DebugOperationTracer (org.hyperledger.besu.ethereum.vm.DebugOperationTracer)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Stopwatch (com.google.common.base.Stopwatch)1