Skip to content

Commit

Permalink
Support for chainId and EIP-1559 fee market in linea_estimateGas
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed Oct 4, 2024
1 parent 8e9fe21 commit ac6b1d1
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -335,6 +445,15 @@ public String execute(final NodeRequests nodeRequests) {
static class RawEstimateGasResponse extends org.web3j.protocol.core.Response<String> {}
}

@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) {}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down

0 comments on commit ac6b1d1

Please sign in to comment.