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

Fix debug_traceCall to handle underpriced transactions #7510

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType.INTERNAL_ERROR;

import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter;
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.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace;
Expand All @@ -28,19 +30,18 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.debug.TraceOptions;
import org.hyperledger.besu.ethereum.mainnet.ImmutableTransactionValidationParams;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams;
import org.hyperledger.besu.ethereum.transaction.PreCloseStateHandler;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator;
import org.hyperledger.besu.ethereum.vm.DebugOperationTracer;

import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DebugTraceCall extends AbstractTraceCall {
private static final Logger LOG = LoggerFactory.getLogger(DebugTraceCall.class);

public DebugTraceCall(
final BlockchainQueries blockchainQueries,
Expand Down Expand Up @@ -69,6 +70,44 @@ protected TraceOptions getTraceOptions(final JsonRpcRequestContext requestContex
}
}

protected Object resultByBlockHeader(
Copy link
Contributor

Choose a reason for hiding this comment

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

This method doesn't appear to be used anywhere in DebugTraceCall

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, yeah, I just removed it, I also removed the errorResponse method. Weirdly, the compiler caught that errorResponse was not being used anywhere when I tried compiling and building after removing resultByBlockHeader right now but didn't catch resultByBlockHeader...

final JsonRpcRequestContext request, final BlockHeader header) {
final JsonCallParameter callParams = JsonCallParameterUtil.validateAndGetCallParams(request);

final TraceOptions traceOptions = getTraceOptions(request);
final DebugOperationTracer tracer = new DebugOperationTracer(traceOptions, false);

TransactionValidationParams validationParams = buildTransactionValidationParams();

return transactionSimulator
.process(
callParams,
validationParams,
tracer,
(mutableWorldState, transactionSimulatorResult) -> {
return transactionSimulatorResult.map(
result -> {
if (result.isInvalid()) {
return errorResponse(
request,
JsonRpcErrorConverter.convertTransactionInvalidReason(
result.getValidationResult().getInvalidReason()));
} else {
return new DebugTraceTransactionResult(
new TransactionTrace(
result.transaction(), result.result(), tracer.getTraceFrames()));
}
});
},
header)
.orElse(errorResponse(request, RpcErrorType.INTERNAL_ERROR));
}

private JsonRpcErrorResponse errorResponse(
final JsonRpcRequestContext request, final RpcErrorType rpcErrorType) {
return new JsonRpcErrorResponse(request.getRequest().getId(), new JsonRpcError(rpcErrorType));
}

@Override
protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
final Optional<BlockParameter> maybeBlockParameter;
Expand All @@ -89,7 +128,6 @@ protected PreCloseStateHandler<Object> getSimulatorResultHandler(
maybeSimulatorResult.map(
result -> {
if (result.isInvalid()) {
LOG.error("Invalid simulator result {}", result);
final JsonRpcError error =
new JsonRpcError(
INTERNAL_ERROR, result.getValidationResult().getErrorMessage());
Expand All @@ -103,4 +141,13 @@ protected PreCloseStateHandler<Object> getSimulatorResultHandler(
return new DebugTraceTransactionResult(transactionTrace);
});
}

@Override
protected TransactionValidationParams buildTransactionValidationParams() {
return ImmutableTransactionValidationParams.builder()
.from(TransactionValidationParams.transactionSimulator())
.isAllowExceedingBalance(true)
.allowUnderpriced(true)
.build();
}
}
Loading