From f774c4473e2f6e48a2ba186bcdd9b33960c403e6 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Fri, 15 Sep 2023 11:09:27 +1000 Subject: [PATCH] Add debug trace call method Signed-off-by: Gabriel-Trintinalia --- .../besu/ethereum/api/jsonrpc/RpcMethod.java | 1 + .../api/jsonrpc/internal/methods/TraceCall.java | 15 +++++++++++---- .../api/jsonrpc/methods/DebugJsonRpcMethods.java | 11 ++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java index 979ff433688..76b42e9b3e3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java @@ -44,6 +44,7 @@ public enum RpcMethod { DEBUG_STANDARD_TRACE_BLOCK_TO_FILE("debug_standardTraceBlockToFile"), DEBUG_STANDARD_TRACE_BAD_BLOCK_TO_FILE("debug_standardTraceBadBlockToFile"), DEBUG_TRACE_TRANSACTION("debug_traceTransaction"), + DEBUG_TRACE_CALL("debug_traceCall"), DEBUG_BATCH_RAW_TRANSACTION("debug_batchSendRawTransaction"), DEBUG_GET_BAD_BLOCKS("debug_getBadBlocks"), DEBUG_GET_RAW_HEADER("debug_getRawHeader"), diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java index c6f7f24052f..2c6497fd063 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCall.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; +import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult; import org.hyperledger.besu.ethereum.vm.DebugOperationTracer; import java.util.Optional; @@ -95,13 +96,19 @@ protected Object resultByBlockNumber( new TransactionTrace( result.getTransaction(), result.getResult(), tracer.getTraceFrames()); - final Block block = - blockchainQueriesSupplier.get().getBlockchain().getChainHeadBlock(); - return getTraceCallResult( - protocolSchedule, traceTypes, result, transactionTrace, block); + protocolSchedule, traceTypes, result, transactionTrace); }), maybeBlockHeader.get()) .orElse(new JsonRpcErrorResponse(requestContext.getRequest().getId(), INTERNAL_ERROR)); } + + protected Object getTraceCallResult( + final ProtocolSchedule protocolSchedule, + final Set traceTypes, + final TransactionSimulatorResult result, + final TransactionTrace transactionTrace) { + final Block block = blockchainQueriesSupplier.get().getBlockchain().getChainHeadBlock(); + return getTraceCallResult(protocolSchedule, traceTypes, result, transactionTrace, block); + } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java index b34af183693..b70e7720a0d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlock; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlockByHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceBlockByNumber; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceCall; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugTraceTransaction; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay; @@ -45,6 +46,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; +import org.hyperledger.besu.ethereum.transaction.TransactionSimulator; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import java.nio.file.Path; @@ -113,6 +115,13 @@ protected Map create() { new DebugGetRawHeader(blockchainQueries), new DebugGetRawBlock(blockchainQueries), new DebugGetRawReceipts(blockchainQueries), - new DebugGetRawTransaction(blockchainQueries)); + new DebugGetRawTransaction(blockchainQueries), + new DebugTraceCall( + blockchainQueries, + protocolSchedule, + new TransactionSimulator( + blockchainQueries.getBlockchain(), + blockchainQueries.getWorldStateArchive(), + protocolSchedule))); } }