Skip to content

Commit

Permalink
Revert "Draft fix for allowing gasPrice alongside 1559 max*FeePerGas …
Browse files Browse the repository at this point in the history
…params instead of responding with error"

This reverts commit c5e564c.
  • Loading branch information
siladu committed Dec 21, 2024
1 parent adbf853 commit 331cacc
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.privacy.MultiTenancyValidationException;

import java.util.Arrays;

import io.opentelemetry.api.trace.Span;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
Expand All @@ -46,8 +44,7 @@ public JsonRpcResponse process(
return method.response(request);
} catch (final InvalidJsonRpcParameters e) {
LOG.debug(
"Invalid Params {} for method: {}, error: {}",
Arrays.toString(request.getRequest().getParams()),
"Invalid Params for method: {}, error: {}",
method.getName(),
e.getRpcErrorType().getMessage(),
e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public JsonRpcResponse process(
case INVALID_EXECUTION_REQUESTS_PARAMS:
case INVALID_EXTRA_DATA_PARAMS:
case INVALID_FILTER_PARAMS:
case INVALID_GAS_PRICE_PARAMS:
case INVALID_HASH_RATE_PARAMS:
case INVALID_ID_PARAMS:
case INVALID_RETURN_COMPLETE_TRANSACTION_PARAMS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;

import java.util.Arrays;

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

public class JsonCallParameterUtil {

private static final Logger LOG = LoggerFactory.getLogger(JsonCallParameterUtil.class);

private JsonCallParameterUtil() {}

public static JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext request) {
Expand All @@ -43,13 +36,9 @@ public static JsonCallParameter validateAndGetCallParams(final JsonRpcRequestCon
if (callParams.getGasPrice() != null
&& (callParams.getMaxFeePerGas().isPresent()
|| callParams.getMaxPriorityFeePerGas().isPresent())) {
try {
LOG.warn(
"gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas {}",
Arrays.toString(request.getRequest().getParams()));
} catch (Exception e) {
LOG.warn("gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas");
}
throw new InvalidJsonRpcParameters(
"gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas",
RpcErrorType.INVALID_GAS_PRICE_PARAMS);
}
return callParams;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public enum RpcErrorType implements RpcMethodError {
INVALID_EXECUTION_REQUESTS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid execution requests params"),
INVALID_EXTRA_DATA_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid extra data params"),
INVALID_FILTER_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid filter params"),
INVALID_GAS_PRICE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid gas price params"),
INVALID_HASH_RATE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid hash rate params"),
INVALID_ID_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid ID params"),
INVALID_RETURN_COMPLETE_TRANSACTION_PARAMS(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
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.JsonCallParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
Expand All @@ -50,6 +51,7 @@

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -153,6 +155,17 @@ public void pendingBlockTagEstimateOnPendingBlock() {
assertThat(method.response(request)).usingRecursiveComparison().isEqualTo(expectedResponse);
}

@Test
public void shouldReturnGasEstimateErrorWhenGasPricePresentForEip1559Transaction() {
final JsonRpcRequestContext request =
ethCreateAccessListRequest(eip1559TransactionCallParameter(Optional.of(Wei.of(10))));
mockTransactionSimulatorResult(false, false, 1L, latestBlockHeader);

Assertions.assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas");
}

@Test
public void shouldReturnErrorWhenWorldStateIsNotAvailable() {
when(worldStateArchive.isWorldStateAvailable(any(), any())).thenReturn(false);
Expand Down Expand Up @@ -377,6 +390,10 @@ private CallParameter eip1559TransactionCallParameter() {
return eip1559TransactionCallParameter(Optional.empty(), null);
}

private CallParameter eip1559TransactionCallParameter(final Optional<Wei> gasPrice) {
return eip1559TransactionCallParameter(gasPrice, null);
}

private CallParameter eip1559TransactionCallParameter(
final List<AccessListEntry> accessListEntries) {
return eip1559TransactionCallParameter(Optional.empty(), accessListEntries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.hyperledger.besu.datatypes.parameters.UnsignedLongParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
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.JsonCallParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
Expand All @@ -51,6 +52,7 @@
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -193,11 +195,22 @@ public void shouldUseGasPriceParameterWhenIsPresent() {
assertThat(method.response(request)).usingRecursiveComparison().isEqualTo(expectedResponse);
}

@Test
public void shouldReturnGasEstimateErrorWhenGasPricePresentForEip1559Transaction() {
final JsonRpcRequestContext request =
ethEstimateGasRequest(eip1559TransactionCallParameter(Optional.of(Wei.of(10))));
mockTransientProcessorResultGasEstimate(1L, false, false, latestBlockHeader);
Assertions.assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas");
}

@Test
public void
shouldReturnGasEstimateWhenTransientEip1559TransactionProcessorReturnsResultSuccess() {
final JsonRpcRequestContext request = ethEstimateGasRequest(eip1559TransactionCallParameter());
mockTransientProcessorResultGasEstimate(1L, true, false, latestBlockHeader);

final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Quantity.create(1L));
assertThat(method.response(request)).usingRecursiveComparison().isEqualTo(expectedResponse);
}
Expand Down

0 comments on commit 331cacc

Please sign in to comment.