From ac6b1d1c01fe347fef8c7890702fcb334f793dc8 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 4 Oct 2024 13:23:13 +0200 Subject: [PATCH] Support for chainId and EIP-1559 fee market in linea_estimateGas Signed-off-by: Fabio Di Fabio --- .../EstimateGasCompatibilityModeTest.java | 3 +- .../EstimateGasModuleLimitOverflowTest.java | 3 + .../acc/test/rpc/linea/EstimateGasTest.java | 131 +++++++++++++++++- gradle.properties | 2 +- .../linea/rpc/methods/LineaEstimateGas.java | 15 +- 5 files changed, 143 insertions(+), 11 deletions(-) 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 f4e17cec..b342c610 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; @@ -25,6 +26,7 @@ import java.nio.charset.StandardCharsets; import java.util.List; +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; @@ -93,7 +95,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); @@ -109,12 +119,84 @@ public void passingGasPriceFieldWorks() { final CallParams callParams = new CallParams( + null, + 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 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", - "0x1234"); + 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()); @@ -140,7 +222,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(); @@ -191,7 +281,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()); @@ -205,7 +304,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"); @@ -218,11 +325,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); @@ -335,6 +445,15 @@ 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) {} } diff --git a/gradle.properties b/gradle.properties index f0e3c8c0..94d16d25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ releaseVersion=0.8.0-rc1.1 -besuVersion=24.10-delivery34 +besuVersion=24.10-delivery35 arithmetizationVersion=0.8.0-rc1 besuArtifactGroup=io.consensys.linea-besu distributionIdentifier=linea-sequencer 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 34d25066..273871b3 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 @@ -476,9 +476,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 @@ -488,6 +487,16 @@ private Transaction createTransactionForSimulation( callParameters.getAccessList().ifPresent(txBuilder::accessList); + callParameters + .getChainId() + .ifPresentOrElse( + txBuilder::chainId, + () -> { + if (txBuilder.guessType().getTransactionType().requiresChainId()) { + blockchainService.getChainId().ifPresent(txBuilder::chainId); + } + }); + return txBuilder.build(); }