diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasCompatibilityModeTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasCompatibilityModeTest.java index 156864fb..da41344f 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasCompatibilityModeTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasCompatibilityModeTest.java @@ -70,7 +70,8 @@ protected void assertMinGasPriceLowerBound(final Wei baseFee, final Wei estimate public void lineaEstimateGasPriorityFeeMinGasPriceLowerBound() { final Account sender = accounts.getSecondaryBenefactor(); - final CallParams callParams = new CallParams(sender.getAddress(), null, "", "", "0", null); + final CallParams callParams = + new CallParams(null, sender.getAddress(), null, "", "", "0", null, null, null); final var reqLinea = new LineaEstimateGasRequest(callParams); final var respLinea = reqLinea.execute(minerNode.nodeRequests()).getResult(); diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasModuleLimitOverflowTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasModuleLimitOverflowTest.java index 95f0ec0d..cff3e6e7 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasModuleLimitOverflowTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasModuleLimitOverflowTest.java @@ -48,11 +48,14 @@ public void estimateGasFailsForExceedingModuleLineCountTest() throws Exception { final EstimateGasTest.CallParams callParams = new EstimateGasTest.CallParams( + null, sender.getAddress(), simpleStorage.getContractAddress(), null, payload.toHexString(), "0", + null, + null, null); final var reqLinea = new EstimateGasTest.BadLineaEstimateGasRequest(callParams); diff --git a/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasTest.java b/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasTest.java index 42eece1e..742cb4eb 100644 --- a/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasTest.java +++ b/acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasTest.java @@ -14,6 +14,7 @@ */ package linea.plugin.acc.test.rpc.linea; +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; @@ -27,6 +28,7 @@ import java.util.List; import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; import linea.plugin.acc.test.LineaPluginTestBase; import linea.plugin.acc.test.TestCommandLineOptionsBuilder; import linea.plugin.acc.test.tests.web3j.generated.SimpleStorage; @@ -95,7 +97,15 @@ public void lineaEstimateGasMatchesEthEstimateGas() { final CallParams callParams = new CallParams( - sender.getAddress(), sender.getAddress(), null, Bytes.EMPTY.toHexString(), "0", null); + null, + sender.getAddress(), + sender.getAddress(), + null, + Bytes.EMPTY.toHexString(), + "0", + null, + null, + null); final var reqEth = new RawEstimateGasRequest(callParams); final var reqLinea = new LineaEstimateGasRequest(callParams); @@ -111,12 +121,84 @@ public void passingGasPriceFieldWorks() { final CallParams callParams = new CallParams( + null, sender.getAddress(), sender.getAddress(), null, Bytes.EMPTY.toHexString(), "0", - "0x1234"); + "0x1234", + null, + null); + + final var reqLinea = new LineaEstimateGasRequest(callParams); + final var respLinea = reqLinea.execute(minerNode.nodeRequests()); + assertThat(respLinea.hasError()).isFalse(); + assertThat(respLinea.getResult()).isNotNull(); + } + + @Test + public void passingChainIdFieldWorks() { + + final Account sender = accounts.getSecondaryBenefactor(); + + final CallParams callParams = + new CallParams( + "0x539", + sender.getAddress(), + sender.getAddress(), + null, + Bytes.EMPTY.toHexString(), + "0", + "0x1234", + null, + null); + + final var reqLinea = new LineaEstimateGasRequest(callParams); + final var respLinea = reqLinea.execute(minerNode.nodeRequests()); + assertThat(respLinea.hasError()).isFalse(); + assertThat(respLinea.getResult()).isNotNull(); + } + + @Test + public void passingEIP1559FieldsWorks() { + + final Account sender = accounts.getSecondaryBenefactor(); + + final CallParams callParams = + new CallParams( + null, + sender.getAddress(), + sender.getAddress(), + null, + Bytes.EMPTY.toHexString(), + "0", + null, + "0x1234", + "0x1"); + + final var reqLinea = new LineaEstimateGasRequest(callParams); + final var respLinea = reqLinea.execute(minerNode.nodeRequests()); + assertThat(respLinea.hasError()).isFalse(); + assertThat(respLinea.getResult()).isNotNull(); + } + + @Test + public void passingChainIdAndEIP1559FieldsWorks() { + + final Account sender = accounts.getSecondaryBenefactor(); + + final CallParams callParams = + new CallParams( + "0x539", + sender.getAddress(), + sender.getAddress(), + null, + Bytes.EMPTY.toHexString(), + "0", + null, + "0x1234", + null); final var reqLinea = new LineaEstimateGasRequest(callParams); final var respLinea = reqLinea.execute(minerNode.nodeRequests()); @@ -135,12 +217,15 @@ public void passingStateOverridesWorks() { final CallParams callParams = new CallParams( + "0x539", sender.getAddress(), sender.getAddress(), "1", Bytes.EMPTY.toHexString(), "0", - "0x1234"); + "0x1234", + null, + null); final var zeroBalance = Map.of("balance", Wei.ZERO.toHexString()); @@ -172,7 +257,15 @@ public void lineaEstimateGasIsProfitable() { final CallParams callParams = new CallParams( - sender.getAddress(), sender.getAddress(), null, payload.toHexString(), "0", null); + null, + sender.getAddress(), + sender.getAddress(), + null, + payload.toHexString(), + "0", + null, + null, + null); final var reqLinea = new LineaEstimateGasRequest(callParams); final var respLinea = reqLinea.execute(minerNode.nodeRequests()).getResult(); @@ -223,7 +316,16 @@ protected void assertIsProfitable( public void invalidParametersLineaEstimateGasRequestReturnErrorResponse() { final Account sender = accounts.getSecondaryBenefactor(); final CallParams callParams = - new CallParams(sender.getAddress(), null, "", "", String.valueOf(Integer.MAX_VALUE), null); + new CallParams( + null, + sender.getAddress(), + null, + "", + "", + String.valueOf(Integer.MAX_VALUE), + null, + null, + null); final var reqLinea = new BadLineaEstimateGasRequest(callParams); final var respLinea = reqLinea.execute(minerNode.nodeRequests()); assertThat(respLinea.getCode()).isEqualTo(RpcErrorType.INVALID_PARAMS.getCode()); @@ -237,7 +339,15 @@ public void revertedTransactionReturnErrorResponse() throws Exception { final var reqLinea = new BadLineaEstimateGasRequest( new CallParams( - sender.getAddress(), simpleStorage.getContractAddress(), "", "", "0", null)); + null, + sender.getAddress(), + simpleStorage.getContractAddress(), + "", + "", + "0", + null, + null, + null)); final var respLinea = reqLinea.execute(minerNode.nodeRequests()); assertThat(respLinea.getCode()).isEqualTo(-32000); assertThat(respLinea.getMessage()).isEqualTo("Execution reverted"); @@ -250,11 +360,14 @@ public void failedTransactionReturnErrorResponse() { final var reqLinea = new BadLineaEstimateGasRequest( new CallParams( + null, sender.getAddress(), null, "", Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY, "0", + null, + null, null)); final var respLinea = reqLinea.execute(minerNode.nodeRequests()); assertThat(respLinea.getCode()).isEqualTo(-32000); @@ -374,8 +487,17 @@ public String execute(final NodeRequests nodeRequests) { static class RawEstimateGasResponse extends org.web3j.protocol.core.Response {} } + @JsonInclude(NON_NULL) record CallParams( - String from, String to, String value, String data, String gas, String gasPrice) {} + String chainId, + String from, + String to, + String value, + String data, + String gas, + String gasPrice, + String maxFeePerGas, + String maxPriorityFeePerGas) {} record StateOverride(String account, String balance) {} } diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/methods/LineaEstimateGas.java b/sequencer/src/main/java/net/consensys/linea/rpc/methods/LineaEstimateGas.java index f3250aa1..0723f693 100644 --- a/sequencer/src/main/java/net/consensys/linea/rpc/methods/LineaEstimateGas.java +++ b/sequencer/src/main/java/net/consensys/linea/rpc/methods/LineaEstimateGas.java @@ -491,9 +491,8 @@ private Transaction createTransactionForSimulation( .signature(FAKE_SIGNATURE_FOR_SIZE_CALCULATION); if (isBaseFeeTransaction(callParameters)) { - callParameters.getMaxFeePerGas().ifPresent(txBuilder::maxFeePerGas); - callParameters.getMaxPriorityFeePerGas().ifPresent(txBuilder::maxPriorityFeePerGas); - callParameters.getMaxFeePerBlobGas().ifPresent(txBuilder::maxFeePerBlobGas); + txBuilder.maxFeePerGas(callParameters.getMaxFeePerGas().orElse(Wei.ZERO)); + txBuilder.maxPriorityFeePerGas(callParameters.getMaxPriorityFeePerGas().orElse(Wei.ZERO)); } else { txBuilder.gasPrice( callParameters.getGasPrice() != null @@ -503,6 +502,22 @@ private Transaction createTransactionForSimulation( callParameters.getAccessList().ifPresent(txBuilder::accessList); + final var txType = txBuilder.guessType().getTransactionType(); + + if (txType.supportsBlob()) { + txBuilder.maxFeePerBlobGas(callParameters.getMaxFeePerBlobGas().orElse(Wei.ZERO)); + } + + callParameters + .getChainId() + .ifPresentOrElse( + txBuilder::chainId, + () -> { + if (txType.requiresChainId()) { + blockchainService.getChainId().ifPresent(txBuilder::chainId); + } + }); + return txBuilder.build(); }