Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit ef0baef

Browse files
macfarlagaryschulte
authored andcommitted
Ignore gasPrice if 1559 gas params are specified (#8059)
* don't throw if all the gasprice params are specified Signed-off-by: Sally MacFarlane <[email protected]> --------- Signed-off-by: Sally MacFarlane <[email protected]>
1 parent f130196 commit ef0baef

File tree

7 files changed

+50
-25
lines changed

7 files changed

+50
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Add RPC HTTP options to specify custom truststore and its password [#7978](https://github.com/hyperledger/besu/pull/7978)
1919
- Retrieve all transaction receipts for a block in one request [#6646](https://github.com/hyperledger/besu/pull/6646)
2020
- Implement EIP-7840: Add blob schedule to config files [#8042](https://github.com/hyperledger/besu/pull/8042)
21+
- Allow gasPrice (legacy) and 1559 gasPrice params to be specified simultaneously for `eth_call`, `eth_createAccessList`, and `eth_estimateGas` [#8059](https://github.com/hyperledger/besu/pull/8059)
2122

2223

2324
### Bug fixes

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/BaseJsonRpcProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
2525
import org.hyperledger.besu.ethereum.privacy.MultiTenancyValidationException;
2626

27+
import java.util.Arrays;
28+
2729
import io.opentelemetry.api.trace.Span;
2830
import io.vertx.core.json.JsonArray;
2931
import io.vertx.core.json.JsonObject;
@@ -44,7 +46,8 @@ public JsonRpcResponse process(
4446
return method.response(request);
4547
} catch (final InvalidJsonRpcParameters e) {
4648
LOG.debug(
47-
"Invalid Params for method: {}, error: {}",
49+
"Invalid Params {} for method: {}, error: {}",
50+
Arrays.toString(request.getRequest().getParams()),
4851
method.getName(),
4952
e.getRpcErrorType().getMessage(),
5053
e);

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/execution/TracedJsonRpcProcessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public JsonRpcResponse process(
8282
case INVALID_EXECUTION_REQUESTS_PARAMS:
8383
case INVALID_EXTRA_DATA_PARAMS:
8484
case INVALID_FILTER_PARAMS:
85-
case INVALID_GAS_PRICE_PARAMS:
8685
case INVALID_HASH_RATE_PARAMS:
8786
case INVALID_ID_PARAMS:
8887
case INVALID_RETURN_COMPLETE_TRANSACTION_PARAMS:

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException;
2121
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
2222

23+
import java.util.Arrays;
24+
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2328
public class JsonCallParameterUtil {
29+
private static final Logger LOG = LoggerFactory.getLogger(JsonCallParameterUtil.class);
2430

2531
private JsonCallParameterUtil() {}
2632

@@ -36,9 +42,14 @@ public static JsonCallParameter validateAndGetCallParams(final JsonRpcRequestCon
3642
if (callParams.getGasPrice() != null
3743
&& (callParams.getMaxFeePerGas().isPresent()
3844
|| callParams.getMaxPriorityFeePerGas().isPresent())) {
39-
throw new InvalidJsonRpcParameters(
40-
"gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas",
41-
RpcErrorType.INVALID_GAS_PRICE_PARAMS);
45+
try {
46+
LOG.debug(
47+
"gasPrice will be ignored since 1559 values are defined (maxFeePerGas or maxPriorityFeePerGas). {}",
48+
Arrays.toString(request.getRequest().getParams()));
49+
} catch (Exception e) {
50+
LOG.debug(
51+
"gasPrice will be ignored since 1559 values are defined (maxFeePerGas or maxPriorityFeePerGas)");
52+
}
4253
}
4354
return callParams;
4455
}

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/RpcErrorType.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public enum RpcErrorType implements RpcMethodError {
6565
INVALID_EXECUTION_REQUESTS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid execution requests params"),
6666
INVALID_EXTRA_DATA_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid extra data params"),
6767
INVALID_FILTER_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid filter params"),
68-
INVALID_GAS_PRICE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid gas price params"),
6968
INVALID_HASH_RATE_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid hash rate params"),
7069
INVALID_ID_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid ID params"),
7170
INVALID_RETURN_COMPLETE_TRANSACTION_PARAMS(

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.hyperledger.besu.datatypes.Wei;
2828
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
2929
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
30-
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
3130
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter;
3231
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
3332
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
@@ -51,7 +50,6 @@
5150

5251
import org.apache.tuweni.bytes.Bytes;
5352
import org.apache.tuweni.bytes.Bytes32;
54-
import org.assertj.core.api.Assertions;
5553
import org.junit.jupiter.api.BeforeEach;
5654
import org.junit.jupiter.api.Test;
5755
import org.junit.jupiter.api.extension.ExtendWith;
@@ -156,14 +154,16 @@ public void pendingBlockTagEstimateOnPendingBlock() {
156154
}
157155

158156
@Test
159-
public void shouldReturnGasEstimateErrorWhenGasPricePresentForEip1559Transaction() {
157+
public void shouldNotErrorWhenGasPricePresentForEip1559Transaction() {
158+
final Wei gasPrice = Wei.of(1000);
159+
final List<AccessListEntry> expectedAccessList = new ArrayList<>();
160160
final JsonRpcRequestContext request =
161-
ethCreateAccessListRequest(eip1559TransactionCallParameter(Optional.of(Wei.of(10))));
162-
mockTransactionSimulatorResult(false, false, 1L, latestBlockHeader);
161+
ethCreateAccessListRequest(eip1559TransactionCallParameter(Optional.of(gasPrice)));
162+
mockTransactionSimulatorResult(true, false, 1L, latestBlockHeader);
163163

164-
Assertions.assertThatThrownBy(() -> method.response(request))
165-
.isInstanceOf(InvalidJsonRpcParameters.class)
166-
.hasMessageContaining("gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas");
164+
final JsonRpcResponse expectedResponse =
165+
new JsonRpcSuccessResponse(null, new CreateAccessListResult(expectedAccessList, 1L));
166+
assertThat(method.response(request)).usingRecursiveComparison().isEqualTo(expectedResponse);
167167
}
168168

169169
@Test

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.hyperledger.besu.datatypes.parameters.UnsignedLongParameter;
2929
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
3030
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
31-
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
3231
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter;
3332
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
3433
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
@@ -52,7 +51,6 @@
5251
import java.util.Optional;
5352

5453
import org.apache.tuweni.bytes.Bytes;
55-
import org.assertj.core.api.Assertions;
5654
import org.junit.jupiter.api.BeforeEach;
5755
import org.junit.jupiter.api.Test;
5856
import org.junit.jupiter.api.extension.ExtendWith;
@@ -196,13 +194,15 @@ public void shouldUseGasPriceParameterWhenIsPresent() {
196194
}
197195

198196
@Test
199-
public void shouldReturnGasEstimateErrorWhenGasPricePresentForEip1559Transaction() {
197+
public void shouldNotErrorWhenGasPricePresentForEip1559Transaction() {
198+
final Wei gasPrice = Wei.of(1000);
200199
final JsonRpcRequestContext request =
201-
ethEstimateGasRequest(eip1559TransactionCallParameter(Optional.of(Wei.of(10))));
202-
mockTransientProcessorResultGasEstimate(1L, false, false, latestBlockHeader);
203-
Assertions.assertThatThrownBy(() -> method.response(request))
204-
.isInstanceOf(InvalidJsonRpcParameters.class)
205-
.hasMessageContaining("gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas");
200+
ethEstimateGasRequest(eip1559TransactionCallParameter(Optional.of(gasPrice)));
201+
mockTransientProcessorResultGasEstimate(
202+
1L, true, gasPrice, Optional.empty(), latestBlockHeader);
203+
204+
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Quantity.create(1L));
205+
assertThat(method.response(request)).usingRecursiveComparison().isEqualTo(expectedResponse);
206206
}
207207

208208
@Test
@@ -534,6 +534,14 @@ private TransactionSimulatorResult getMockTransactionSimulatorResult(
534534
any(OperationTracer.class),
535535
eq(blockHeader)))
536536
.thenReturn(Optional.of(mockTxSimResult));
537+
// for testing different combination of gasPrice params
538+
when(transactionSimulator.process(
539+
eq(modifiedEip1559TransactionCallParameter(Optional.of(gasPrice))),
540+
eq(Optional.empty()), // no account overrides
541+
any(TransactionValidationParams.class),
542+
any(OperationTracer.class),
543+
eq(blockHeader)))
544+
.thenReturn(Optional.of(mockTxSimResult));
537545
}
538546
final TransactionProcessingResult mockResult = mock(TransactionProcessingResult.class);
539547
when(mockResult.getEstimateGasUsedByTransaction()).thenReturn(estimateGas);
@@ -578,11 +586,11 @@ private CallParameter eip1559TransactionCallParameter() {
578586
return eip1559TransactionCallParameter(Optional.empty());
579587
}
580588

581-
private JsonCallParameter eip1559TransactionCallParameter(final Optional<Wei> gasPrice) {
589+
private JsonCallParameter eip1559TransactionCallParameter(final Optional<Wei> maybeGasPrice) {
582590
return new JsonCallParameter.JsonCallParameterBuilder()
583591
.withFrom(Address.fromHexString("0x0"))
584592
.withTo(Address.fromHexString("0x0"))
585-
.withGasPrice(gasPrice.orElse(null))
593+
.withGasPrice(maybeGasPrice.orElse(null))
586594
.withMaxPriorityFeePerGas(Wei.fromHexString("0x10"))
587595
.withMaxFeePerGas(Wei.fromHexString("0x10"))
588596
.withValue(Wei.ZERO)
@@ -592,11 +600,15 @@ private JsonCallParameter eip1559TransactionCallParameter(final Optional<Wei> ga
592600
}
593601

594602
private CallParameter modifiedEip1559TransactionCallParameter() {
603+
return modifiedEip1559TransactionCallParameter(Optional.empty());
604+
}
605+
606+
private CallParameter modifiedEip1559TransactionCallParameter(final Optional<Wei> gasPrice) {
595607
return new CallParameter(
596608
Address.fromHexString("0x0"),
597609
Address.fromHexString("0x0"),
598610
Long.MAX_VALUE,
599-
Wei.ZERO,
611+
gasPrice.orElse(Wei.ZERO),
600612
Optional.of(Wei.fromHexString("0x10")),
601613
Optional.of(Wei.fromHexString("0x10")),
602614
Wei.ZERO,

0 commit comments

Comments
 (0)