Skip to content
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 31 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
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 Feb 18, 2022
178b024
some WIP code for trace_rawTransaction
macfarla Feb 18, 2022
f81868a
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla Feb 20, 2022
ae62142
added test dirs to specs; handle empty optionals
macfarla Feb 21, 2022
20f0949
handle null
macfarla Feb 21, 2022
4b66fa1
headers
macfarla Feb 21, 2022
9000863
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla Feb 21, 2022
8cebba7
cleanup
macfarla Feb 21, 2022
692aa82
payload
macfarla Feb 21, 2022
9293b36
comment
macfarla Feb 21, 2022
5ab6ba6
error response
macfarla Feb 21, 2022
d326deb
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla Feb 22, 2022
159c311
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla Feb 24, 2022
4355d5e
PR review
macfarla Feb 24, 2022
7b8dbd5
changelog
macfarla Feb 24, 2022
a0bf437
merge main changes
frankisawesome Mar 2, 2022
1ee657f
merge main
macfarla Mar 4, 2022
9b46f20
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla Mar 4, 2022
a3ddbad
Merge branch 'trace-raw-transaction' of github.com:macfarla/besu into…
macfarla Mar 4, 2022
5857359
comment
macfarla Mar 4, 2022
9897f8f
code smells
macfarla Mar 4, 2022
df642e8
merge
macfarla Mar 4, 2022
c56c5d8
code smells
macfarla Mar 4, 2022
cc7a10b
changelog
macfarla Mar 4, 2022
341c18d
Merge branch 'main' into trace-raw-transaction
MadelineMurray Mar 7, 2022
7d227ab
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla Mar 7, 2022
4bb3920
cache the block number to make sure we are using the same block
macfarla Mar 7, 2022
f19c781
Merge branch 'trace-raw-transaction' of github.com:macfarla/besu into…
macfarla Mar 7, 2022
eb45609
check optional
macfarla Mar 7, 2022
dd5877f
Merge branch 'main' of github.com:hyperledger/besu into trace-raw-tra…
macfarla Mar 7, 2022
4f58529
Merge branch 'main' into trace-raw-transaction
macfarla Mar 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Additions and Improvements
- Execution layer (The Merge):
- Execution specific RPC endpoint [[#3378](https://github.com/hyperledger/besu/issues/3378)
- Tracing APIs: trace_rawTransaction, trace_get

### Bug Fixes
- Reject locally-sourced transactions below the minimum gas price when not mining. [#3397](https://github.com/hyperledger/besu/pull/3397)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static Address privateContractAddress(
})));
}

public static Address fromPlugin(final org.hyperledger.besu.plugin.data.Address logger) {
return logger instanceof Address ? (Address) logger : wrap(logger.copy());
public static Address fromPlugin(final org.hyperledger.besu.plugin.data.Address address) {
return address instanceof Address ? (Address) address : wrap(address.copy());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,13 @@ public enum RpcMethod {
PERM_REMOVE_NODES_FROM_WHITELIST("perm_removeNodesFromWhitelist"),
PERM_REMOVE_NODES_FROM_ALLOWLIST("perm_removeNodesFromAllowlist"),
RPC_MODULES("rpc_modules"),
TRACE_REPLAY_BLOCK_TRANSACTIONS("trace_replayBlockTransactions"),
TRACE_BLOCK("trace_block"),
TRACE_CALL("trace_call"),
TRACE_GET("trace_get"),
TRACE_TRANSACTION("trace_transaction"),
TRACE_FILTER("trace_filter"),
TRACE_RAW_TRANSACTION("trace_rawTransaction"),
TRACE_REPLAY_BLOCK_TRANSACTIONS("trace_replayBlockTransactions"),
TRACE_TRANSACTION("trace_transaction"),
TX_POOL_BESU_STATISTICS("txpool_besuStatistics"),
TX_POOL_BESU_TRANSACTIONS("txpool_besuTransactions"),
TX_POOL_BESU_PENDING_TRANSACTIONS("txpool_besuPendingTransactions"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter.TraceType;

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
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.results.TraceCallResult;
Expand Down Expand Up @@ -59,6 +61,18 @@ protected AbstractTraceByBlock(
this.transactionSimulator = transactionSimulator;
}

@Override
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
final Optional<BlockParameter> maybeBlockParameter =
request.getOptionalParameter(2, BlockParameter.class);

if (maybeBlockParameter.isPresent()) {
return maybeBlockParameter.get();
}

return BlockParameter.LATEST;
}

protected JsonNode getTraceCallResult(
final ProtocolSchedule protocolSchedule,
final Set<TraceTypeParameter.TraceType> traceTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Stream<FlatTrace> resultByTransactionHash(final Hash transactionHash) {
.transactionByHash(transactionHash)
.flatMap(TransactionWithMetadata::getBlockNumber)
.flatMap(blockNumber -> blockchainQueries.getBlockchain().getBlockByNumber(blockNumber))
.map((block) -> getTraceBlock(block, transactionHash))
.map(block -> getTraceBlock(block, transactionHash))
.orElse(Stream.empty());
}

Expand Down Expand Up @@ -82,7 +82,7 @@ private Stream<FlatTrace> getTraceStream(
final TransactionTrace transactionTrace, final Block block) {
return FlatTraceGenerator.generateFromTransactionTraceAndBlock(
this.protocolSchedule, transactionTrace, block)
.map(trace -> (FlatTrace) trace);
.map(FlatTrace.class::cast);
}

protected JsonNode arrayNodeFromTraceStream(final Stream<FlatTrace> traceStream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

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.BlockParameter;
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;
Expand Down Expand Up @@ -51,18 +50,6 @@ public String getName() {
return transactionSimulator != null ? RpcMethod.TRACE_CALL.getMethodName() : null;
}

@Override
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
final Optional<BlockParameter> maybeBlockParameter =
request.getOptionalParameter(2, BlockParameter.class);

if (maybeBlockParameter.isPresent()) {
return maybeBlockParameter.get();
}

return BlockParameter.LATEST;
}

@Override
protected Object resultByBlockNumber(
final JsonRpcRequestContext requestContext, final long blockNumber) {
Expand Down
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);
Copy link
Contributor

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.

  • What level of logging (Is trace level the right level?)
  • What are we logging? params? Just the name of the called method? Just the most important params, like here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} catch (final RLPException | IllegalArgumentException e) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
}

final TraceTypeParameter traceTypeParameter =
requestContext.getRequiredParameter(1, TraceTypeParameter.class);
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see this message at DEBUG level

	at org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcHttpService.lambda$handleJsonSingleRequest$14(JsonRpcHttpService.java:610)
	at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:159)
	at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
	at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:157)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.fasterxml.jackson.databind.exc.ValueInstantiationException: Cannot construct instance of `org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter`, problem: Invalid trace types supplied: boo, foo
 at [Source: (String)"["boo","foo"]"; line: 1, column: 13]


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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TraceCall;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TraceFilter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TraceGet;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TraceRawTransaction;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TraceReplayBlockTransactions;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.TraceTransaction;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay;
Expand Down Expand Up @@ -69,6 +70,14 @@ protected Map<String, JsonRpcMethod> create() {
new TraceCall(
blockchainQueries,
protocolSchedule,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule,
privacyParameters)),
new TraceRawTransaction(
protocolSchedule,
blockchainQueries,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ private void checkResponse(final ObjectNode responseBody, final ObjectNode expec
assertThat(
mapper
.writerWithDefaultPrettyPrinter()
.withoutAttribute("creationMethod")
.writeValueAsString(mapper.readTree(actualResult)))
.isEqualTo(
mapper
.writerWithDefaultPrettyPrinter()
.withoutAttribute("creationMethod")
.writeValueAsString(mapper.readTree(expectedResult)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static Object[][] specs() {
"trace/specs/replay-trace-transaction/all",
"trace/specs/replay-trace-transaction/halt-cases",
"trace/specs/trace-filter",
"trace/specs/trace-call"
"trace/specs/trace-call",
"trace/specs/trace-raw-transaction"
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static Object[][] specs() {
"trace/specs/replay-trace-transaction/all",
"trace/specs/replay-trace-transaction/halt-cases",
"trace/specs/trace-filter",
"trace/specs/trace-call"
"trace/specs/trace-call",
"trace/specs/trace-raw-transaction"
});
}
}
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
}
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
}
Loading