Search in sources :

Example 1 with DebugTraceTransactionResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult 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 DebugTraceTransactionResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult in project besu by hyperledger.

the class DebugTraceTransaction method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    final Hash hash = requestContext.getRequiredParameter(0, Hash.class);
    final Optional<TransactionWithMetadata> transactionWithMetadata = blockchain.transactionByHash(hash);
    if (transactionWithMetadata.isPresent()) {
        final TraceOptions traceOptions = requestContext.getOptionalParameter(1, TransactionTraceParams.class).map(TransactionTraceParams::traceOptions).orElse(TraceOptions.DEFAULT);
        final DebugTraceTransactionResult debugTraceTransactionResult = debugTraceTransactionResult(hash, transactionWithMetadata.get(), traceOptions);
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), debugTraceTransactionResult);
    } else {
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), null);
    }
}
Also used : DebugTraceTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult) TransactionWithMetadata(org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) Hash(org.hyperledger.besu.datatypes.Hash) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)

Example 3 with DebugTraceTransactionResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult in project besu by hyperledger.

the class DebugTraceBlockByNumberTest method shouldReturnCorrectResponse.

@Test
public void shouldReturnCorrectResponse() {
    final long blockNumber = 1L;
    final Object[] params = new Object[] { Long.toHexString(blockNumber) };
    final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_traceBlockByNumber", params));
    final TraceFrame traceFrame = new TraceFrame(12, Optional.of("NONE"), 45L, OptionalLong.of(56L), 0L, 2, Optional.empty(), null, Wei.ZERO, Bytes.EMPTY, Bytes.EMPTY, Optional.empty(), Optional.empty(), Optional.empty(), null, Optional.empty(), Optional.empty(), Optional.empty(), 0, Optional.empty(), false, Optional.empty(), Optional.empty());
    final TransactionProcessingResult transaction1Result = mock(TransactionProcessingResult.class);
    final TransactionProcessingResult transaction2Result = mock(TransactionProcessingResult.class);
    final TransactionTrace transaction1Trace = mock(TransactionTrace.class);
    final TransactionTrace transaction2Trace = mock(TransactionTrace.class);
    final BlockTrace blockTrace = new BlockTrace(asList(transaction1Trace, transaction2Trace));
    when(transaction1Trace.getTraceFrames()).thenReturn(singletonList(traceFrame));
    when(transaction2Trace.getTraceFrames()).thenReturn(singletonList(traceFrame));
    when(transaction1Trace.getResult()).thenReturn(transaction1Result);
    when(transaction2Trace.getResult()).thenReturn(transaction2Result);
    when(transaction1Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
    when(transaction2Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
    when(blockchain.getBlockHashByNumber(blockNumber)).thenReturn(Optional.of(blockHash));
    when(blockTracer.trace(eq(blockHash), any())).thenReturn(Optional.of(blockTrace));
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) debugTraceBlockByNumber.response(request);
    final Collection<DebugTraceTransactionResult> result = getResult(response);
    assertThat(result).usingFieldByFieldElementComparator().isEqualTo(DebugTraceTransactionResult.of(blockTrace.getTransactionTraces()));
}
Also used : DebugTraceTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) TraceFrame(org.hyperledger.besu.ethereum.debug.TraceFrame) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Test(org.junit.Test)

Example 4 with DebugTraceTransactionResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult in project besu by hyperledger.

the class DebugTraceTransactionIntegrationTest method debugTraceTransactionSuccessTest.

@Test
public void debugTraceTransactionSuccessTest() {
    final Map<String, Boolean> map = Map.of("disableStorage", true);
    final Object[] params = new Object[] { Hash.fromHexString("0xcef53f2311d7c80e9086d661e69ac11a5f3d081e28e02a9ba9b66749407ac310"), map };
    final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", DEBUG_TRACE_TRANSACTION, params));
    final JsonRpcResponse response = method.response(request);
    assertThat(response.getType()).isEqualTo(JsonRpcResponseType.SUCCESS);
    DebugTraceTransactionResult debugTraceTransactionResult = (DebugTraceTransactionResult) ((JsonRpcSuccessResponse) response).getResult();
    assertThat(debugTraceTransactionResult.getGas()).isEqualTo(23705L);
    assertThat(debugTraceTransactionResult.getReturnValue()).isEmpty();
    assertThat(debugTraceTransactionResult.failed()).isFalse();
    assertThat(debugTraceTransactionResult.getStructLogs()).hasSize(106);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) DebugTraceTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) Test(org.junit.jupiter.api.Test)

Example 5 with DebugTraceTransactionResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult in project besu by hyperledger.

the class DebugTraceBlock method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    final String input = requestContext.getRequiredParameter(0, String.class);
    final Block block;
    try {
        block = Block.readFrom(RLP.input(Bytes.fromHexString(input)), this.blockHeaderFunctions);
    } catch (final RLPException e) {
        LOG.debug("Failed to parse block RLP", e);
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
    }
    final TraceOptions traceOptions = requestContext.getOptionalParameter(1, TransactionTraceParams.class).map(TransactionTraceParams::traceOptions).orElse(TraceOptions.DEFAULT);
    if (this.blockchain.blockByHash(block.getHeader().getParentHash()).isPresent()) {
        final Collection<DebugTraceTransactionResult> results = blockTracerSupplier.get().trace(block, new DebugOperationTracer(traceOptions)).map(BlockTrace::getTransactionTraces).map(DebugTraceTransactionResult::of).orElse(null);
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), results);
    } else {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.PARENT_BLOCK_NOT_FOUND);
    }
}
Also used : DebugTraceTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) RLPException(org.hyperledger.besu.ethereum.rlp.RLPException) Block(org.hyperledger.besu.ethereum.core.Block) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Aggregations

DebugTraceTransactionResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult)7 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)5 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)4 BlockTrace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace)4 TraceOptions (org.hyperledger.besu.ethereum.debug.TraceOptions)4 DebugOperationTracer (org.hyperledger.besu.ethereum.vm.DebugOperationTracer)4 Hash (org.hyperledger.besu.datatypes.Hash)3 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)3 TransactionTrace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace)2 TransactionWithMetadata (org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata)2 TraceFrame (org.hyperledger.besu.ethereum.debug.TraceFrame)2 TransactionProcessingResult (org.hyperledger.besu.ethereum.processing.TransactionProcessingResult)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)1 BlockParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter)1