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);
}
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);
}
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);
}
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);
}
Aggregations