From 3160a4d0af901b559072988a53ba9ed41c3942de Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Wed, 9 Mar 2022 13:57:34 +1000 Subject: [PATCH] Trace APIs: add revert reason (#3539) * added revertReason * added test file for trace_transaction with revertReason Signed-off-by: Sally MacFarlane --- CHANGELOG.md | 4 ++- .../methods/AbstractTraceByBlock.java | 3 -- .../jsonrpc/internal/methods/TraceCall.java | 4 --- .../internal/methods/TraceCallMany.java | 6 ---- .../jsonrpc/internal/methods/TraceGet.java | 17 +++------- .../trace-call/trace_call_12_1_trace.json | 3 +- .../trace_callMany_12_trace.json | 3 +- .../trace-get/trace_get_12_1_0_trace.json | 3 +- .../trace_rawTransaction_12_1_trace.json | 3 +- .../trace_transaction_12_1_trace.json | 33 +++++++++++++++++++ 10 files changed, 48 insertions(+), 31 deletions(-) create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-transaction/trace_transaction_12_1_trace.json diff --git a/CHANGELOG.md b/CHANGELOG.md index a137ef75e7..c3a677cd09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,9 @@ - Execution layer (The Merge): - Execution specific RPC endpoint [[#3378](https://github.com/hyperledger/besu/issues/3378) - Adds JWT authentication to Engine APIs -- Tracing APIs: trace_rawTransaction, trace_get, trace_callMany +- Tracing APIs + - new API methods: trace_rawTransaction, trace_get, trace_callMany + - added revertReason to trace APIs including: trace_transaction, trace_get, trace_call, trace_callMany, and trace_rawTransaction - Allow mining beneficiary to transition at specific blocks for ibft2 and qbft consensus mechanisms. [#3115](https://github.com/hyperledger/besu/issues/3115) ### Bug Fixes diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java index 6944fae518..f40e37d1f1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractTraceByBlock.java @@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.diff.S import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.diff.StateDiffTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.FlatTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.FlatTraceGenerator; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.MixInIgnoreRevertReason; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.vm.VmTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.vm.VmTraceGenerator; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; @@ -80,8 +79,6 @@ public abstract class AbstractTraceByBlock extends AbstractBlockParameterMethod final TransactionTrace transactionTrace, final Block block) { final TraceCallResult.Builder builder = TraceCallResult.builder(); - // The trace_call specification does not output the revert reason, so we have to remove it - mapper.addMixIn(FlatTrace.class, MixInIgnoreRevertReason.class); transactionTrace .getResult() 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 fcc2c67c33..1a0796a9fb 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 @@ -22,8 +22,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.FlatTrace; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.MixInIgnoreRevertReason; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -46,8 +44,6 @@ public class TraceCall extends AbstractTraceByBlock implements JsonRpcMethod { final ProtocolSchedule protocolSchedule, final TransactionSimulator transactionSimulator) { super(blockchainQueries, protocolSchedule, transactionSimulator); - // The trace_call specification does not output the revert reason, so we have to remove it - mapper.addMixIn(FlatTrace.class, MixInIgnoreRevertReason.class); } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java index 4a3f0d4c07..75f3c4a084 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java @@ -26,8 +26,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypePa import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.FlatTrace; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.MixInIgnoreRevertReason; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -44,22 +42,18 @@ import java.util.Optional; import java.util.Set; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class TraceCallMany extends TraceCall implements JsonRpcMethod { private static final Logger LOG = LoggerFactory.getLogger(TraceCallMany.class); - private static final ObjectMapper MAPPER_IGNORE_REVERT_REASON = new ObjectMapper(); public TraceCallMany( final BlockchainQueries blockchainQueries, final ProtocolSchedule protocolSchedule, final TransactionSimulator transactionSimulator) { super(blockchainQueries, protocolSchedule, transactionSimulator); - - MAPPER_IGNORE_REVERT_REASON.addMixIn(FlatTrace.class, MixInIgnoreRevertReason.class); } @Override diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java index ed74d0b42a..ec9c702d5c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java @@ -22,8 +22,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.FlatTrace; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.flat.MixInIgnoreRevertReason; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -31,19 +29,13 @@ import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; -import com.fasterxml.jackson.databind.ObjectMapper; - public class TraceGet extends AbstractTraceByHash implements JsonRpcMethod { - private static final ObjectMapper MAPPER_IGNORE_REVERT_REASON = new ObjectMapper(); public TraceGet( final Supplier blockTracerSupplier, final BlockchainQueries blockchainQueries, final ProtocolSchedule protocolSchedule) { super(blockTracerSupplier, blockchainQueries, protocolSchedule); - - // The trace_get specification does not output the revert reason, so we have to remove it - MAPPER_IGNORE_REVERT_REASON.addMixIn(FlatTrace.class, MixInIgnoreRevertReason.class); } @Override @@ -67,10 +59,9 @@ public class TraceGet extends AbstractTraceByHash implements JsonRpcMethod { return new JsonRpcSuccessResponse( requestContext.getRequest().getId(), - MAPPER_IGNORE_REVERT_REASON.valueToTree( - resultByTransactionHash(transactionHash) - .filter(trace -> trace.getTraceAddress().equals(traceNumbers)) - .findFirst() - .orElse(null))); + resultByTransactionHash(transactionHash) + .filter(trace -> trace.getTraceAddress().equals(traceNumbers)) + .findFirst() + .orElse(null)); } } diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-call/trace_call_12_1_trace.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-call/trace_call_12_1_trace.json index 8834d55f77..af59f0bd4a 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-call/trace_call_12_1_trace.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-call/trace_call_12_1_trace.json @@ -1,5 +1,5 @@ { - "comment" : "Revert.", + "comment" : "Revert. Note revertReason has been manually added to the response because OpenEthereum does not include it.", "request" : { "jsonrpc" : "2.0", "method" : "trace_call", @@ -28,6 +28,7 @@ "value" : "0x0" }, "error" : "Reverted", + "revertReason" : "0x7d88c1856cc95352", "subtraces" : 0, "traceAddress" : [ ], "type" : "call" diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-callMany/trace_callMany_12_trace.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-callMany/trace_callMany_12_trace.json index 0efaf44839..3f942c4601 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-callMany/trace_callMany_12_trace.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-callMany/trace_callMany_12_trace.json @@ -1,5 +1,5 @@ { - "comment" : "'Memory Read.', 'Revert.'", + "comment" : "'Memory Read.', 'Revert.' Note revertReason has been manually added to the response because OpenEthereum does not include it.", "request" : { "method" : "trace_callMany", "params" : [ [ [ { @@ -54,6 +54,7 @@ "value" : "0x0" }, "error" : "Reverted", + "revertReason" : "0x7d88c1856cc95352", "subtraces" : 0, "traceAddress" : [ ], "type" : "call" diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-get/trace_get_12_1_0_trace.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-get/trace_get_12_1_0_trace.json index 6783f2fc5a..93cab0be43 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-get/trace_get_12_1_0_trace.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-get/trace_get_12_1_0_trace.json @@ -1,5 +1,5 @@ { - "comment" : "Revert.", + "comment" : "Revert. Note revertReason has been manually added to the response because OpenEthereum does not include it.", "request" : { "jsonrpc" : "2.0", "method" : "trace_get", @@ -20,6 +20,7 @@ "blockHash" : "0x220bc13dc4f1ed38dcca927a5be15eca16497d279f4c40d7b8fe9704eadf1464", "blockNumber" : 18, "error" : "Reverted", + "revertReason" : "0x7d88c1856cc95352", "subtraces" : 0, "traceAddress" : [ ], "transactionHash" : "0xc388baa0e55e6b73e850b22dc7e9853700f6b995fd55d95dd6ccd5a13d63c566", diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-raw-transaction/trace_rawTransaction_12_1_trace.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-raw-transaction/trace_rawTransaction_12_1_trace.json index cb3ab514d6..faa638012f 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-raw-transaction/trace_rawTransaction_12_1_trace.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-raw-transaction/trace_rawTransaction_12_1_trace.json @@ -1,5 +1,5 @@ { - "comment" : "Revert.", + "comment" : "Revert. Note revertReason has been manually added to the response because OpenEthereum does not include it.", "request" : { "jsonrpc" : "2.0", "method" : "trace_rawTransaction", @@ -21,6 +21,7 @@ "value" : "0x0" }, "error" : "Reverted", + "revertReason" : "0x7d88c1856cc95352", "subtraces" : 0, "traceAddress" : [ ], "type" : "call" diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-transaction/trace_transaction_12_1_trace.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-transaction/trace_transaction_12_1_trace.json new file mode 100644 index 0000000000..77f2ae40f1 --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/trace-transaction/trace_transaction_12_1_trace.json @@ -0,0 +1,33 @@ +{ + "comment" : "Revert. Note revertReason has been manually added to the response because OpenEthereum does not include it.", + "request" : { + "jsonrpc" : "2.0", + "method" : "trace_transaction", + "params" : [ "0xc388baa0e55e6b73e850b22dc7e9853700f6b995fd55d95dd6ccd5a13d63c566" ], + "id" : 155 + }, + "response" : { + "jsonrpc" : "2.0", + "result" : [ { + "action" : { + "callType" : "call", + "from" : "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73", + "gas" : "0xffadea", + "input" : "0x", + "to" : "0x0110000000000000000000000000000000000000", + "value" : "0x0" + }, + "blockHash" : "0x220bc13dc4f1ed38dcca927a5be15eca16497d279f4c40d7b8fe9704eadf1464", + "blockNumber" : 18, + "error" : "Reverted", + "revertReason" : "0x7d88c1856cc95352", + "subtraces" : 0, + "traceAddress" : [ ], + "transactionHash" : "0xc388baa0e55e6b73e850b22dc7e9853700f6b995fd55d95dd6ccd5a13d63c566", + "transactionPosition" : 1, + "type" : "call" + } ], + "id" : 155 + }, + "statusCode" : 200 +}