Search in sources :

Example 1 with DebugOperationTracer

use of org.hyperledger.besu.ethereum.vm.DebugOperationTracer 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 2 with DebugOperationTracer

use of org.hyperledger.besu.ethereum.vm.DebugOperationTracer in project besu by hyperledger.

the class TraceCallMany method getSingleCallResult.

private JsonNode getSingleCallResult(final JsonCallParameter callParameter, final TraceTypeParameter traceTypeParameter, final BlockHeader header, final WorldUpdater worldUpdater) {
    final Set<TraceTypeParameter.TraceType> traceTypes = traceTypeParameter.getTraceTypes();
    final DebugOperationTracer tracer = new DebugOperationTracer(buildTraceOptions(traceTypes));
    final Optional<TransactionSimulatorResult> maybeSimulatorResult = transactionSimulator.processWithWorldUpdater(callParameter, buildTransactionValidationParams(), tracer, header, worldUpdater);
    LOG.trace("Executing {} call for transaction {}", traceTypeParameter, callParameter);
    if (maybeSimulatorResult.isEmpty()) {
        throw new EmptySimulatorResultException();
    }
    final TransactionSimulatorResult simulatorResult = maybeSimulatorResult.get();
    if (simulatorResult.isInvalid()) {
        throw new TransactionInvalidException();
    }
    final TransactionTrace transactionTrace = new TransactionTrace(simulatorResult.getTransaction(), simulatorResult.getResult(), tracer.getTraceFrames());
    final Block block = blockchainQueriesSupplier.get().getBlockchain().getChainHeadBlock();
    return getTraceCallResult(protocolSchedule, traceTypes, maybeSimulatorResult, transactionTrace, block);
}
Also used : TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Block(org.hyperledger.besu.ethereum.core.Block)

Example 3 with DebugOperationTracer

use of org.hyperledger.besu.ethereum.vm.DebugOperationTracer in project besu by hyperledger.

the class TraceRawTransaction method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    if (requestContext.getRequest().getParamLength() != 2) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
    }
    final var rawTransaction = requestContext.getRequiredParameter(0, String.class);
    final TraceTypeParameter traceTypeParameter = requestContext.getRequiredParameter(1, TraceTypeParameter.class);
    LOG.trace("Received RPC rpcName={} rawTx={} traceType={}", getName(), rawTransaction, traceTypeParameter);
    final Transaction transaction;
    try {
        transaction = DomainObjectDecodeUtils.decodeRawTransaction(rawTransaction);
        LOG.trace("rawTx decoded to transaction {}", transaction);
    } catch (final RLPException | IllegalArgumentException e) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
    }
    final Set<TraceTypeParameter.TraceType> traceTypes = traceTypeParameter.getTraceTypes();
    final DebugOperationTracer tracer = new DebugOperationTracer(buildTraceOptions(traceTypes));
    final long headBlockNumber = blockchainQueriesSupplier.get().headBlockNumber();
    final Optional<TransactionSimulatorResult> maybeSimulatorResult = transactionSimulator.process(CallParameter.fromTransaction(transaction), buildTransactionValidationParams(), tracer, headBlockNumber);
    if (maybeSimulatorResult.isEmpty()) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), INTERNAL_ERROR);
    }
    final TransactionTrace transactionTrace = new TransactionTrace(maybeSimulatorResult.get().getTransaction(), maybeSimulatorResult.get().getResult(), tracer.getTraceFrames());
    final Optional<Block> maybeBlock = blockchainQueriesSupplier.get().getBlockchain().getBlockByNumber(headBlockNumber);
    if (maybeBlock.isEmpty()) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), INTERNAL_ERROR);
    }
    final Block block = maybeBlock.get();
    final Object response = getTraceCallResult(protocolSchedule, traceTypes, maybeSimulatorResult, transactionTrace, block);
    return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response);
}
Also used : DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) Transaction(org.hyperledger.besu.ethereum.core.Transaction) TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) RLPException(org.hyperledger.besu.ethereum.rlp.RLPException) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Block(org.hyperledger.besu.ethereum.core.Block) TraceTypeParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 4 with DebugOperationTracer

use of org.hyperledger.besu.ethereum.vm.DebugOperationTracer in project besu by hyperledger.

the class TraceReplayBlockTransactions method traceBlock.

private Object traceBlock(final Block block, final TraceTypeParameter traceTypeParameter) {
    if (block == null || block.getBody().getTransactions().isEmpty()) {
        return emptyResult();
    }
    final Set<TraceTypeParameter.TraceType> traceTypes = traceTypeParameter.getTraceTypes();
    final TraceOptions traceOptions = new TraceOptions(false, false, traceTypes.contains(VM_TRACE) || traceTypes.contains(TRACE));
    return blockTracerSupplier.get().trace(block, new DebugOperationTracer(traceOptions)).map(BlockTrace::getTransactionTraces).map((traces) -> generateTracesFromTransactionTrace(traces, block, traceTypes)).orElse(null);
}
Also used : TRACE(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter.TraceType.TRACE) TraceType(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter.TraceType) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) Arrays(java.util.Arrays) TraceTypeParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter) LoggerFactory(org.slf4j.LoggerFactory) TraceFormatter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.TraceFormatter) Supplier(java.util.function.Supplier) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Suppliers(com.google.common.base.Suppliers) JsonNode(com.fasterxml.jackson.databind.JsonNode) Block(org.hyperledger.besu.ethereum.core.Block) FlatTraceGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.FlatTraceGenerator) TraceWriter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.TraceWriter) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Logger(org.slf4j.Logger) VmTraceGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.vm.VmTraceGenerator) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) Optional(java.util.Optional) StateDiffGenerator(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.diff.StateDiffGenerator) VM_TRACE(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter.TraceType.VM_TRACE) BlockTracer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer) TraceType(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter.TraceType) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace)

Example 5 with DebugOperationTracer

use of org.hyperledger.besu.ethereum.vm.DebugOperationTracer in project besu by hyperledger.

the class TraceBlock method traceBlock.

protected ArrayNodeWrapper traceBlock(final Block block, final Optional<FilterParameter> filterParameter) {
    if (block == null) {
        return emptyResult();
    }
    final ArrayNodeWrapper resultArrayNode = new ArrayNodeWrapper(MAPPER.createArrayNode());
    blockTracerSupplier.get().trace(block, new DebugOperationTracer(new TraceOptions(false, false, true))).ifPresent(blockTrace -> generateTracesFromTransactionTraceAndBlock(filterParameter, blockTrace.getTransactionTraces(), block, resultArrayNode));
    generateRewardsFromBlock(filterParameter, block, resultArrayNode);
    return resultArrayNode;
}
Also used : ArrayNodeWrapper(org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions)

Aggregations

DebugOperationTracer (org.hyperledger.besu.ethereum.vm.DebugOperationTracer)10 TraceOptions (org.hyperledger.besu.ethereum.debug.TraceOptions)6 BlockTrace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace)5 TransactionTrace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace)5 Block (org.hyperledger.besu.ethereum.core.Block)5 Hash (org.hyperledger.besu.datatypes.Hash)4 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)4 Optional (java.util.Optional)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 TraceTypeParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter)3 BlockTracer (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer)3 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)3 DebugTraceTransactionResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult)3 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)3 TransactionSimulatorResult (org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult)3 List (java.util.List)2 BlockParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter)2 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)2