Search in sources :

Example 1 with TraceTypeParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter in project besu by hyperledger.

the class TraceReplayBlockTransactions method resultByBlockNumber.

@Override
protected Object resultByBlockNumber(final JsonRpcRequestContext request, final long blockNumber) {
    final TraceTypeParameter traceTypeParameter = request.getRequiredParameter(1, TraceTypeParameter.class);
    LOG.trace("Received RPC rpcName={} block={} traceType={}", getName(), blockNumber, traceTypeParameter);
    if (blockNumber == BlockHeader.GENESIS_BLOCK_NUMBER) {
        // Nothing to trace for the genesis block
        return emptyResult();
    }
    return getBlockchainQueries().getBlockchain().getBlockByNumber(blockNumber).map((block) -> traceBlock(block, traceTypeParameter)).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) TraceTypeParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter)

Example 2 with TraceTypeParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter 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 3 with TraceTypeParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter 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 4 with TraceTypeParameter

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter in project besu by hyperledger.

the class TraceCall method resultByBlockNumber.

@Override
protected Object resultByBlockNumber(final JsonRpcRequestContext requestContext, final long blockNumber) {
    final JsonCallParameter callParams = JsonCallParameterUtil.validateAndGetCallParams(requestContext);
    final TraceTypeParameter traceTypeParameter = requestContext.getRequiredParameter(1, TraceTypeParameter.class);
    final String blockNumberString = String.valueOf(blockNumber);
    traceLambda(LOG, "Received RPC rpcName={} callParams={} block={} traceTypes={}", this::getName, callParams::toString, blockNumberString::toString, traceTypeParameter::toString);
    final Optional<BlockHeader> maybeBlockHeader = blockchainQueriesSupplier.get().getBlockHeaderByNumber(blockNumber);
    if (maybeBlockHeader.isEmpty()) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), BLOCK_NOT_FOUND);
    }
    final Set<TraceTypeParameter.TraceType> traceTypes = traceTypeParameter.getTraceTypes();
    final DebugOperationTracer tracer = new DebugOperationTracer(buildTraceOptions(traceTypes));
    final Optional<TransactionSimulatorResult> maybeSimulatorResult = transactionSimulator.process(callParams, buildTransactionValidationParams(), tracer, maybeBlockHeader.get());
    if (maybeSimulatorResult.isEmpty()) {
        LOG.error("Empty simulator result. call params: {}, blockHeader: {} ", callParams, maybeBlockHeader.get());
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), INTERNAL_ERROR);
    }
    final TransactionSimulatorResult simulatorResult = maybeSimulatorResult.get();
    if (simulatorResult.isInvalid()) {
        LOG.error(String.format("Invalid simulator result %s", maybeSimulatorResult));
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), INTERNAL_ERROR);
    }
    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 : DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) JsonCallParameter(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter) TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) 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) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Aggregations

TraceTypeParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter)4 TransactionTrace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace)4 Block (org.hyperledger.besu.ethereum.core.Block)4 DebugOperationTracer (org.hyperledger.besu.ethereum.vm.DebugOperationTracer)4 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Suppliers (com.google.common.base.Suppliers)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Supplier (java.util.function.Supplier)2 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)2 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)2 BlockParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter)2 TraceType (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter.TraceType)2