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

update eth_call error message #8129

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -24,10 +24,12 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter;
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.response.RpcErrorType;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason;
import org.hyperledger.besu.testutil.BlockTestUtil;

import java.util.Map;
Expand Down Expand Up @@ -132,7 +134,12 @@ public void shouldReturnErrorWithGasLimitTooLow() {

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.INTRINSIC_GAS_EXCEEDS_LIMIT);
new JsonRpcErrorResponse(
null,
JsonRpcError.from(
ValidationResult.invalid(
TransactionInvalidReason.INTRINSIC_GAS_EXCEEDS_GAS_LIMIT,
"intrinsic gas cost 21272 exceeds gas limit 0")));

final JsonRpcResponse response = method.response(request);

Expand All @@ -152,7 +159,12 @@ public void shouldReturnErrorWithGasPriceTooHighAndStrict() {

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE);
new JsonRpcErrorResponse(
null,
JsonRpcError.from(
ValidationResult.invalid(
TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE,
"transaction up-front cost 0x2fefd80000000000000 exceeds transaction sender account balance 0x340ab63a0215af0d")));

final JsonRpcResponse response = method.response(request);

Expand Down Expand Up @@ -192,7 +204,12 @@ public void shouldReturnErrorWithGasPriceTooHigh() {

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE);
new JsonRpcErrorResponse(
null,
JsonRpcError.from(
ValidationResult.invalid(
TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE,
"transaction up-front cost 0x2fefd80000000000000 exceeds transaction sender account balance 0x340ab63a0215af0d")));

final JsonRpcResponse response = method.response(request);

Expand Down Expand Up @@ -231,7 +248,12 @@ public void shouldReturnErrorWithGasPriceAndEmptyBalance() {

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE);
new JsonRpcErrorResponse(
null,
JsonRpcError.from(
ValidationResult.invalid(
TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE,
"transaction up-front cost 0x2fefd80 exceeds transaction sender account balance 0x0")));

final JsonRpcResponse response = method.response(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter;
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.response.RpcErrorType;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason;
import org.hyperledger.besu.testutil.BlockTestUtil;

import java.math.BigInteger;
Expand Down Expand Up @@ -92,8 +94,13 @@ public void shouldReturnErrorWithGasPriceTooHigh() {
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");

final ValidationResult<TransactionInvalidReason> validationResult =
ValidationResult.invalid(
TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE,
"transaction up-front cost 0x2000000000000000000000 exceeds transaction sender account balance 0x130ee8e7179044400000");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE);
new JsonRpcErrorResponse(null, JsonRpcError.from(validationResult));

final JsonRpcResponse response = method.response(request);

Expand Down Expand Up @@ -131,8 +138,13 @@ public void shouldReturnErrorWithGasPriceLessThanCurrentBaseFee() {
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");

final ValidationResult<TransactionInvalidReason> validationResult =
ValidationResult.invalid(
TransactionInvalidReason.GAS_PRICE_BELOW_CURRENT_BASE_FEE,
"gasPrice is less than the current BaseFee");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.GAS_PRICE_BELOW_CURRENT_BASE_FEE);
new JsonRpcErrorResponse(null, JsonRpcError.from(validationResult));

final JsonRpcResponse response = method.response(request);

Expand Down Expand Up @@ -172,9 +184,12 @@ public void shouldReturnErrorWithInvalidChainId() {
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final ValidationResult<TransactionInvalidReason> validationResult =
ValidationResult.invalid(
TransactionInvalidReason.WRONG_CHAIN_ID,
"transaction was meant for chain id 1983 and not this chain id 1982");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.WRONG_CHAIN_ID);

new JsonRpcErrorResponse(null, JsonRpcError.from(validationResult));
final JsonRpcResponse response = method.response(request);

assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
Expand Down Expand Up @@ -212,9 +227,13 @@ public void shouldReturnErrorWithValidMaxFeePerGasLessThanCurrentBaseFee() {
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.GAS_PRICE_BELOW_CURRENT_BASE_FEE);

final ValidationResult<TransactionInvalidReason> validationResult =
ValidationResult.invalid(
TransactionInvalidReason.GAS_PRICE_BELOW_CURRENT_BASE_FEE,
"gasPrice is less than the current BaseFee");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, JsonRpcError.from(validationResult));
final JsonRpcResponse response = method.response(request);

assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
Expand All @@ -232,9 +251,13 @@ public void shouldReturnErrorWithValidMaxFeePerGasLessThanMaxPriorityFeePerGas()
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");

final ValidationResult<TransactionInvalidReason> validationResult =
ValidationResult.invalid(
TransactionInvalidReason.MAX_PRIORITY_FEE_PER_GAS_EXCEEDS_MAX_FEE_PER_GAS,
"max priority fee per gas cannot be greater than max fee per gas");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(
null, RpcErrorType.MAX_PRIORITY_FEE_PER_GAS_EXCEEDS_MAX_FEE_PER_GAS);
new JsonRpcErrorResponse(null, JsonRpcError.from(validationResult));

final JsonRpcResponse response = method.response(request);

Expand All @@ -252,8 +275,13 @@ public void shouldReturnErrorWithMaxFeePerGasAndEmptyBalance() {
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");

final ValidationResult<TransactionInvalidReason> validationResult =
ValidationResult.invalid(
TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE,
"transaction up-front cost 0x7735940200000000 exceeds transaction sender account balance 0x0");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE);
new JsonRpcErrorResponse(null, JsonRpcError.from(validationResult));

final JsonRpcResponse response = method.response(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.StateOverrideMap;
import org.hyperledger.besu.datatypes.Wei;
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;
Expand Down Expand Up @@ -107,11 +106,7 @@ protected Object resultByBlockHeader(
request.getRequest().getId(),
result.getOutput().toString())
: errorResponse(request, result)),
reason ->
errorResponse(
request,
JsonRpcErrorConverter.convertTransactionInvalidReason(
reason)))),
reason -> errorResponse(request, result))),
header)
.orElse(errorResponse(request, INTERNAL_ERROR));
}
Expand All @@ -134,14 +129,10 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {

private JsonRpcErrorResponse errorResponse(
final JsonRpcRequestContext request, final TransactionSimulatorResult result) {

final ValidationResult<TransactionInvalidReason> validationResult =
result.getValidationResult();
if (validationResult != null && !validationResult.isValid()) {
return errorResponse(
request,
JsonRpcErrorConverter.convertTransactionInvalidReason(
validationResult.getInvalidReason()));
return errorResponse(request, JsonRpcError.from(validationResult));
} else {
final TransactionProcessingResult resultTrx = result.result();
if (resultTrx != null && resultTrx.getRevertReason().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public AbstractEngineNewPayload(
@Override
public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) {
engineCallListener.executionEngineCalled();

new Exception().printStackTrace(System.out);
final EnginePayloadParameter blockParam;
try {
blockParam = requestContext.getRequiredParameter(0, EnginePayloadParameter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public int getCode() {

@JsonGetter("message")
public String getMessage() {
return (reason == null ? message : message + ": " + reason);
return (reason == null ? message : "%s (%s)".formatted(message, reason));
}

@JsonGetter("data")
Expand All @@ -92,12 +92,29 @@ public boolean equals(final Object o) {
}
final JsonRpcError that = (JsonRpcError) o;
return code == that.code
&& Objects.equals(message.split(":", -1)[0], that.message.split(":", -1)[0])
&& Objects.equals(message.split(" \\(", -1)[0], that.message.split(" \\(", -1)[0])
&& Objects.equals(data, that.data);
}

@Override
public String toString() {
return "JsonRpcError{"
+ "code="
+ code
+ ", message='"
+ message
+ '\''
+ ", data='"
+ data
+ '\''
+ ", reason='"
+ reason
+ '\''
+ '}';
}

@Override
public int hashCode() {
return Objects.hash(code, message.split(":", -1)[0], data);
return Objects.hash(code, message.split(" \\(", -1)[0], data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,18 @@ private static FlatTrace.Context handleHalt(
traceFrameBuilder = currentContext.getBuilder();
}
traceFrameBuilder.error(
traceFrame.getExceptionalHaltReason().map(ExceptionalHaltReason::getDescription));
traceFrame
.getExceptionalHaltReason()
.map(
exceptionalHaltReason -> {
if (exceptionalHaltReason
.name()
.equals(ExceptionalHaltReason.INVALID_OPERATION.name())) {
return ExceptionalHaltReason.INVALID_OPERATION.getDescription();
} else {
return exceptionalHaltReason.getDescription();
}
}));
if (currentContext != null) {
final Action.Builder actionBuilder = traceFrameBuilder.getActionBuilder();
actionBuilder.value(Quantity.create(traceFrame.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void methodErrorWithDataShouldReturnErrorResponseWithDecodedData() throws
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(200);
final JsonObject json = new JsonObject(resp.body().string());
testHelper.assertValidJsonRpcError(json, 1, -2, "Error with data: ABC", "abc");
testHelper.assertValidJsonRpcError(json, 1, -2, "Error with data (ABC)", "abc");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void shouldReturnExecutionRevertErrorWithABIParseError() {
final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse(null, expectedError);

assertThat(expectedResponse.getError().getMessage())
.isEqualTo("Execution reverted: ABI decode error");
.isEqualTo("Execution reverted (ABI decode error)");

mockTransactionProcessorSuccessResult(expectedResponse);
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
Expand All @@ -304,7 +304,7 @@ public void shouldReturnExecutionRevertErrorWithABIParseError() {

assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
assertThat(((JsonRpcErrorResponse) response).getError().getMessage())
.isEqualTo("Execution reverted: ABI decode error");
.isEqualTo("Execution reverted (ABI decode error)");
}

@Test
Expand All @@ -319,7 +319,7 @@ public void shouldReturnExecutionRevertErrorWithParsedABI() {
final JsonRpcErrorResponse expectedResponse = new JsonRpcErrorResponse(null, expectedError);

assertThat(expectedResponse.getError().getMessage())
.isEqualTo("Execution reverted: ERC20: transfer from the zero address");
.isEqualTo("Execution reverted (ERC20: transfer from the zero address)");

mockTransactionProcessorSuccessResult(expectedResponse);
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
Expand Down Expand Up @@ -347,7 +347,7 @@ public void shouldReturnExecutionRevertErrorWithParsedABI() {

assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
assertThat(((JsonRpcErrorResponse) response).getError().getMessage())
.isEqualTo("Execution reverted: ERC20: transfer from the zero address");
.isEqualTo("Execution reverted (ERC20: transfer from the zero address)");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ public void shouldReturnErrorReasonWhenTransactionReverted() {
null, new JsonRpcError(RpcErrorType.REVERT_ERROR, executionRevertedReason));

assertThat(((JsonRpcErrorResponse) expectedResponse).getError().getMessage())
.isEqualTo("Execution reverted: ERC20: transfer from the zero address");
.isEqualTo("Execution reverted (ERC20: transfer from the zero address)");

final JsonRpcResponse actualResponse = method.response(request);

assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse);

assertThat(((JsonRpcErrorResponse) actualResponse).getError().getMessage())
.isEqualTo("Execution reverted: ERC20: transfer from the zero address");
.isEqualTo("Execution reverted (ERC20: transfer from the zero address)");
}

@Test
Expand All @@ -359,14 +359,14 @@ public void shouldReturnABIDecodeErrorReasonWhenInvalidRevertReason() {
null, new JsonRpcError(RpcErrorType.REVERT_ERROR, invalidRevertReason));

assertThat(((JsonRpcErrorResponse) expectedResponse).getError().getMessage())
.isEqualTo("Execution reverted: ABI decode error");
.isEqualTo("Execution reverted (ABI decode error)");

final JsonRpcResponse actualResponse = method.response(request);

assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse);

assertThat(((JsonRpcErrorResponse) actualResponse).getError().getMessage())
.isEqualTo("Execution reverted: ABI decode error");
.isEqualTo("Execution reverted (ABI decode error)");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"response": {
"jsonrpc": "2.0",
"id": 4,
"error":{"code":-32009,"message":"blob gas price below current blob base fee"}
"error":{"code":-32009,"message":"blob gas price below current blob base fee (tx max fee per blob gas less than block blob gas fee: address 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b blobGasFeeCap: 0 wei, blobBaseFee: 1 wei)"}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"response": {
"jsonrpc": "2.0",
"id": 4,
"error":{"code":-32000,"message":"Total blob gas too high"}
"error":{"code":-32000,"message":"Total blob gas too high (total blob gas 917504 exceeds max blob gas per block 786432)"}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"response": {
"jsonrpc": "2.0",
"id": 4,
"error":{"code":-32602,"message":"Invalid transaction type"}
"error":{"code":-32602,"message":"Invalid transaction type (transaction blob transactions must have a to address)"}
},
"statusCode": 200
}
Loading
Loading