-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trace_rawTransaction #3459
Merged
Merged
trace_rawTransaction #3459
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
dc14214
test files from parity
macfarla 178b024
some WIP code for trace_rawTransaction
macfarla f81868a
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla ae62142
added test dirs to specs; handle empty optionals
macfarla 20f0949
handle null
macfarla 4b66fa1
headers
macfarla 9000863
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla 8cebba7
cleanup
macfarla 692aa82
payload
macfarla 9293b36
comment
macfarla 5ab6ba6
error response
macfarla d326deb
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla 159c311
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla 4355d5e
PR review
macfarla 7b8dbd5
changelog
macfarla a0bf437
merge main changes
frankisawesome 1ee657f
merge main
macfarla 9b46f20
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla a3ddbad
Merge branch 'trace-raw-transaction' of github.com:macfarla/besu into…
macfarla 5857359
comment
macfarla 9897f8f
code smells
macfarla df642e8
merge
macfarla c56c5d8
code smells
macfarla cc7a10b
changelog
macfarla 341c18d
Merge branch 'main' into trace-raw-transaction
MadelineMurray 7d227ab
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla 4bb3920
cache the block number to make sure we are using the same block
macfarla f19c781
Merge branch 'trace-raw-transaction' of github.com:macfarla/besu into…
macfarla eb45609
check optional
macfarla dd5877f
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla 4f58529
Merge branch 'main' into trace-raw-transaction
macfarla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
.../java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright contributors to Hyperledger Besu. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; | ||
|
||
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INTERNAL_ERROR; | ||
|
||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; | ||
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.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.query.BlockchainQueries; | ||
import org.hyperledger.besu.ethereum.api.util.DomainObjectDecodeUtils; | ||
import org.hyperledger.besu.ethereum.core.Block; | ||
import org.hyperledger.besu.ethereum.core.Transaction; | ||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; | ||
import org.hyperledger.besu.ethereum.rlp.RLPException; | ||
import org.hyperledger.besu.ethereum.transaction.CallParameter; | ||
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; | ||
import java.util.Set; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TraceRawTransaction extends AbstractTraceByBlock implements JsonRpcMethod { | ||
private static final Logger LOG = LoggerFactory.getLogger(TraceRawTransaction.class); | ||
|
||
public TraceRawTransaction( | ||
final ProtocolSchedule protocolSchedule, | ||
final BlockchainQueries blockchainQueries, | ||
final TransactionSimulator transactionSimulator) { | ||
super(blockchainQueries, protocolSchedule, transactionSimulator); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return transactionSimulator != null ? RpcMethod.TRACE_RAW_TRANSACTION.getMethodName() : null; | ||
} | ||
|
||
@Override | ||
protected Object resultByBlockNumber( | ||
final JsonRpcRequestContext request, final long blockNumber) { | ||
// this method does not get called because response() does the work | ||
return null; | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { | ||
if (requestContext.getRequest().getParamLength() != 2) { | ||
return new JsonRpcErrorResponse( | ||
requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS); | ||
} | ||
|
||
final String rawTransaction = requestContext.getRequiredParameter(0, String.class); | ||
|
||
final Transaction transaction; | ||
try { | ||
transaction = DomainObjectDecodeUtils.decodeRawTransaction(rawTransaction); | ||
LOG.trace("Received raw transaction {}", transaction); | ||
} catch (final RLPException | IllegalArgumentException e) { | ||
return new JsonRpcErrorResponse( | ||
requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS); | ||
} | ||
|
||
final TraceTypeParameter traceTypeParameter = | ||
requestContext.getRequiredParameter(1, TraceTypeParameter.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do get an invalid parameter here, do we return a meaningful error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll see this message at DEBUG level
|
||
|
||
final Set<TraceTypeParameter.TraceType> traceTypes = traceTypeParameter.getTraceTypes(); | ||
final DebugOperationTracer tracer = new DebugOperationTracer(buildTraceOptions(traceTypes)); | ||
final long headBlockNumber = blockchainQueries.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 = | ||
blockchainQueries.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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...um/api/jsonrpc/trace/specs/trace-raw-transaction/trace_rawTransaction_02_0_stateDiff.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"comment" : "Simple value transfer", | ||
"request" : { | ||
"jsonrpc" : "2.0", | ||
"method" : "trace_rawTransaction", | ||
"params" : [ "0xf8618081ef83fffff294000000000000000000000000000000000000099901801ca06aeaaaac3375bb814d36f8c5fb941dae51b55dffc22a6fd3b5b3dd30a9a489d6a05a07dd9d31a1b78fed59812496306fd9e17446cbb456e4e68f1d15b186567302", [ "stateDiff" ] ], | ||
"id" : 0 | ||
}, | ||
"response" : { | ||
"jsonrpc" : "2.0", | ||
"result" : { | ||
"output" : "0x", | ||
"stateDiff" : { | ||
"0x0000000000000000000000000000000000000000" : { | ||
"balance" : { | ||
"*" : { | ||
"from" : "0x393f0f18385c0b29e", | ||
"to" : "0x393f0f183860d4816" | ||
} | ||
}, | ||
"code" : "=", | ||
"nonce" : "=", | ||
"storage" : { } | ||
}, | ||
"0x0000000000000000000000000000000000000999" : { | ||
"balance" : { | ||
"*" : { | ||
"from" : "0x1", | ||
"to" : "0x2" | ||
} | ||
}, | ||
"code" : "=", | ||
"nonce" : "=", | ||
"storage" : { } | ||
}, | ||
"0x627306090abab3a6e1400e9345bc60c78a8bef57" : { | ||
"balance" : { | ||
"*" : { | ||
"from" : "0xefffffffffffe28d07a0be63b", | ||
"to" : "0xefffffffffffe28d079bf50c2" | ||
} | ||
}, | ||
"code" : "=", | ||
"nonce" : { | ||
"*" : { | ||
"from" : "0x17", | ||
"to" : "0x18" | ||
} | ||
}, | ||
"storage" : { } | ||
} | ||
}, | ||
"trace" : [ ], | ||
"vmTrace" : null | ||
}, | ||
"id" : 0 | ||
}, | ||
"statusCode" : 200 | ||
} |
36 changes: 36 additions & 0 deletions
36
...hereum/api/jsonrpc/trace/specs/trace-raw-transaction/trace_rawTransaction_02_0_trace.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"comment" : "Simple value transfer", | ||
"request" : { | ||
"jsonrpc" : "2.0", | ||
"method" : "trace_rawTransaction", | ||
"params" : [ "0xf8618081ef83fffff294000000000000000000000000000000000000099901801ca06aeaaaac3375bb814d36f8c5fb941dae51b55dffc22a6fd3b5b3dd30a9a489d6a05a07dd9d31a1b78fed59812496306fd9e17446cbb456e4e68f1d15b186567302", [ "trace" ] ], | ||
"id" : 53 | ||
}, | ||
"response" : { | ||
"jsonrpc" : "2.0", | ||
"result" : { | ||
"output" : "0x", | ||
"stateDiff" : null, | ||
"trace" : [ { | ||
"action" : { | ||
"callType" : "call", | ||
"from" : "0x627306090abab3a6e1400e9345bc60c78a8bef57", | ||
"gas" : "0xffadea", | ||
"input" : "0x", | ||
"to" : "0x0000000000000000000000000000000000000999", | ||
"value" : "0x1" | ||
}, | ||
"result" : { | ||
"gasUsed" : "0x0", | ||
"output" : "0x" | ||
}, | ||
"subtraces" : 0, | ||
"traceAddress" : [ ], | ||
"type" : "call" | ||
} ], | ||
"vmTrace" : null | ||
}, | ||
"id" : 53 | ||
}, | ||
"statusCode" : 200 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had a very quick look at what/if we are logging RPC methods. It might be worth creating a ticket to have a consistent approach to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3528