Skip to content

Commit

Permalink
Merge branch 'main' into linea-estimateGas-chainId-eip1559
Browse files Browse the repository at this point in the history
# Conflicts:
#	acceptance-tests/src/test/java/linea/plugin/acc/test/rpc/linea/EstimateGasTest.java
#	gradle.properties
  • Loading branch information
fab-10 committed Dec 9, 2024
2 parents ac6b1d1 + eaeb684 commit 77e343b
Show file tree
Hide file tree
Showing 44 changed files with 1,234 additions and 376 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Next release
* feat: Report rejected transactions only due to trace limit overflows to an external service.
* feat: Report rejected transactions to an external service for validators used by LineaTransactionPoolValidatorPlugin [#85](https://github.com/Consensys/linea-sequencer/pull/85)
* feat: Report rejected transactions to an external service for LineaTransactionSelector used by LineaTransactionSelectorPlugin [#69](https://github.com/Consensys/linea-sequencer/pull/69)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@

package linea.plugin.acc.test;

import static net.consensys.linea.metrics.LineaMetricCategory.PRICING_CONF;
import static net.consensys.linea.metrics.LineaMetricCategory.SEQUENCER_PROFITABILITY;
import static net.consensys.linea.metrics.LineaMetricCategory.TX_POOL_PROFITABILITY;
import static org.assertj.core.api.Assertions.*;

import java.io.IOException;
import java.math.BigInteger;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -33,7 +40,9 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import linea.plugin.acc.test.tests.web3j.generated.RevertExample;
import linea.plugin.acc.test.tests.web3j.generated.SimpleStorage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
Expand All @@ -42,6 +51,8 @@
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.plugin.services.metrics.MetricCategory;
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.account.Accounts;
import org.hyperledger.besu.tests.acceptance.dsl.condition.txpool.TxPoolConditions;
Expand All @@ -66,13 +77,15 @@
import org.web3j.tx.response.TransactionReceiptProcessor;

/** Base class for plugin tests. */
@Slf4j
public class LineaPluginTestBase extends AcceptanceTestBase {
public static final int MAX_CALLDATA_SIZE = 1188; // contract has a call data size of 1160
public static final int MAX_TX_GAS_LIMIT = DefaultGasProvider.GAS_LIMIT.intValue();
public static final long CHAIN_ID = 1337L;
public static final CliqueOptions LINEA_CLIQUE_OPTIONS =
new CliqueOptions(
CliqueOptions.DEFAULT.blockPeriodSeconds(), CliqueOptions.DEFAULT.epochLength(), false);
protected static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
protected BesuNode minerNode;

@BeforeEach
Expand Down Expand Up @@ -122,6 +135,12 @@ private BesuNode createCliqueNodeWithExtraCliOptionsAndRpcApis(
.genesisConfigProvider(
validators -> Optional.of(provideGenesisConfig(validators, cliqueOptions)))
.extraCLIOptions(extraCliOptions)
.metricsConfiguration(
MetricsConfiguration.builder()
.enabled(true)
.metricCategories(
Set.of(PRICING_CONF, SEQUENCER_PROFITABILITY, TX_POOL_PROFITABILITY))
.build())
.requestedPlugins(
List.of(
"LineaExtraDataPlugin",
Expand Down Expand Up @@ -229,6 +248,17 @@ protected SimpleStorage deploySimpleStorage() throws Exception {
return deploy.send();
}

protected RevertExample deployRevertExample() throws Exception {
final Web3j web3j = minerNode.nodeRequests().eth();
final Credentials credentials = Credentials.create(Accounts.GENESIS_ACCOUNT_ONE_PRIVATE_KEY);
TransactionManager txManager =
new RawTransactionManager(web3j, credentials, CHAIN_ID, createReceiptProcessor(web3j));

final RemoteCall<RevertExample> deploy =
RevertExample.deploy(web3j, txManager, new DefaultGasProvider());
return deploy.send();
}

public static String getResourcePath(String resource) {
return Objects.requireNonNull(LineaPluginTestBase.class.getResource(resource)).getPath();
}
Expand Down Expand Up @@ -306,4 +336,33 @@ protected Bytes32 createExtraDataPricingField(
return Bytes32.rightPad(
Bytes.concatenate(Bytes.of((byte) 1), fixed.toBytes(), variable.toBytes(), min.toBytes()));
}

protected double getMetricValue(
final MetricCategory category,
final String metricName,
final List<Map.Entry<String, String>> labelValues)
throws IOException, InterruptedException {

final var metricsReq =
HttpRequest.newBuilder().GET().uri(URI.create("http://127.0.0.1:9545/metrics")).build();

final var respLines = HTTP_CLIENT.send(metricsReq, HttpResponse.BodyHandlers.ofLines());

final var searchString =
category.getApplicationPrefix().orElse("")
+ category.getName()
+ "_"
+ metricName
+ labelValues.stream()
.map(lv -> lv.getKey() + "=\"" + lv.getValue() + "\"")
.collect(Collectors.joining(",", "{", "}"));

final var foundMetric =
respLines.body().filter(line -> line.startsWith(searchString)).findFirst();

return foundMetric
.map(line -> line.substring(searchString.length()).trim())
.map(Double::valueOf)
.orElse(Double.NaN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package linea.plugin.acc.test.extradata;

import static java.util.Map.entry;
import static net.consensys.linea.metrics.LineaMetricCategory.PRICING_CONF;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
Expand Down Expand Up @@ -78,7 +80,7 @@ public void updateMinGasPriceViaExtraData() {
}

@Test
public void updateProfitabilityParamsViaExtraData() throws IOException {
public void updateProfitabilityParamsViaExtraData() throws IOException, InterruptedException {
final Web3j web3j = minerNode.nodeRequests().eth();
final Account sender = accounts.getSecondaryBenefactor();
final Account recipient = accounts.createAccount("recipient");
Expand Down Expand Up @@ -121,6 +123,21 @@ public void updateProfitabilityParamsViaExtraData() throws IOException {
assertThat(signedUnprofitableTxResp.getError().getMessage()).isEqualTo("Gas price too low");

assertThat(getTxPoolContent()).isEmpty();

final var fixedCostMetric =
getMetricValue(PRICING_CONF, "values", List.of(entry("field", "fixed_cost_wei")));

assertThat(fixedCostMetric).isEqualTo(MIN_GAS_PRICE.multiply(2).getValue().doubleValue());

final var variableCostMetric =
getMetricValue(PRICING_CONF, "values", List.of(entry("field", "variable_cost_wei")));

assertThat(variableCostMetric).isEqualTo(MIN_GAS_PRICE.getValue().doubleValue());

final var ethGasPriceMetric =
getMetricValue(PRICING_CONF, "values", List.of(entry("field", "eth_gas_price_wei")));

assertThat(ethGasPriceMetric).isEqualTo(MIN_GAS_PRICE.getValue().doubleValue());
}

static class MinerSetExtraDataRequest implements Transaction<Boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import linea.plugin.acc.test.LineaPluginTestBase;
Expand Down Expand Up @@ -204,6 +206,39 @@ public void passingChainIdAndEIP1559FieldsWorks() {
assertThat(respLinea.getResult()).isNotNull();
}

@Test
public void passingStateOverridesWorks() {

final Account sender = accounts.getSecondaryBenefactor();

final var actualBalance = minerNode.execute(ethTransactions.getBalance(sender));

assertThat(actualBalance).isGreaterThan(BigInteger.ONE);

final CallParams callParams =
new CallParams(
"0x539",
sender.getAddress(),
sender.getAddress(),
"1",
Bytes.EMPTY.toHexString(),
"0",
"0x1234",
null,
null);

final var zeroBalance = Map.of("balance", Wei.ZERO.toHexString());

final var stateOverrides = Map.of(accounts.getSecondaryBenefactor().getAddress(), zeroBalance);

final var reqLinea = new LineaEstimateGasRequest(callParams, stateOverrides);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respLinea.hasError()).isTrue();
assertThat(respLinea.getError().getMessage())
.isEqualTo(
"transaction up-front cost 0x208cbab601 exceeds transaction sender account balance 0x0");
}

@Test
public void lineaEstimateGasIsProfitable() {

Expand Down Expand Up @@ -368,17 +403,24 @@ protected void assertMinGasPriceLowerBound(final Wei baseFee, final Wei estimate
static class LineaEstimateGasRequest
implements Transaction<LineaEstimateGasRequest.LineaEstimateGasResponse> {
private final CallParams callParams;
private final Map<String, Map<String, String>> stateOverrides;

public LineaEstimateGasRequest(final CallParams callParams) {
this(callParams, null);
}

public LineaEstimateGasRequest(
final CallParams callParams, final Map<String, Map<String, String>> stateOverrides) {
this.callParams = callParams;
this.stateOverrides = stateOverrides;
}

@Override
public LineaEstimateGasResponse execute(final NodeRequests nodeRequests) {
try {
return new Request<>(
"linea_estimateGas",
List.of(callParams),
Arrays.asList(callParams, stateOverrides),
nodeRequests.getWeb3jService(),
LineaEstimateGasResponse.class)
.send();
Expand Down Expand Up @@ -456,4 +498,6 @@ record CallParams(
String gasPrice,
String maxFeePerGas,
String maxPriorityFeePerGas) {}

record StateOverride(String account, String balance) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import linea.plugin.acc.test.LineaPluginTestBase;
import linea.plugin.acc.test.TestCommandLineOptionsBuilder;
import linea.plugin.acc.test.tests.web3j.generated.RevertExample;
import linea.plugin.acc.test.tests.web3j.generated.SimpleStorage;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
Expand All @@ -46,7 +47,7 @@ public List<String> getTestCliOptions() {
return new TestCommandLineOptionsBuilder()
.set(
"--plugin-linea-module-limit-file-path=",
getResourcePath("/txOverflowModuleLimits.toml"))
getResourcePath("/moduleLimits_sendRawTx.toml"))
.set("--plugin-linea-tx-pool-simulation-check-api-enabled=", "true")
.build();
}
Expand Down Expand Up @@ -101,4 +102,36 @@ public void transactionOverModuleLineCountNotAccepted() throws Exception {
.map(Hash::toHexString)
.forEach(hash -> minerNode.verify(eth.expectSuccessfulTransactionReceipt(hash)));
}

@Test
public void transactionsThatRevertAreAccepted() throws Exception {
final RevertExample revertExample = deployRevertExample();
final Web3j web3j = minerNode.nodeRequests().eth();
final String contractAddress = revertExample.getContractAddress();
final String txData = revertExample.setValue(BigInteger.ZERO).encodeFunctionCall();

// this tx reverts but nevertheless it is accepted in the pool
final RawTransaction txThatReverts =
RawTransaction.createTransaction(
CHAIN_ID,
BigInteger.ZERO,
GAS_LIMIT.divide(BigInteger.TEN),
contractAddress,
VALUE,
txData,
GAS_PRICE,
GAS_PRICE.multiply(BigInteger.TEN).add(BigInteger.ONE));
final byte[] signedTxContractInteraction =
TransactionEncoder.signMessage(
txThatReverts, Credentials.create(Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY));

final EthSendTransaction signedTxContractInteractionResp =
web3j.ethSendRawTransaction(Numeric.toHexString(signedTxContractInteraction)).send();

assertThat(signedTxContractInteractionResp.hasError()).isFalse();

final var expectedConfirmedTxHash = signedTxContractInteractionResp.getTransactionHash();

minerNode.verify(eth.expectSuccessfulTransactionReceipt(expectedConfirmedTxHash));
}
}
75 changes: 75 additions & 0 deletions acceptance-tests/src/test/resources/moduleLimits_sendRawTx.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

##
# This file specifies prover limit by each EVM module
# WARN: The prover/arithmetization team has the owneship of this.
# Changing this values may compromise the system.
# issue: https://github.com/Consensys/zkevm-monorepo/issues/525
##

[traces-limits]
#
# Arithmetization module limits
#
ADD = 70
BIN = 262144
BLAKE_MODEXP_DATA = 262144
BLOCK_DATA = 13
BLOCK_HASH = 1
EC_DATA = 4096
EUC = 16384 # can probably be lower
EXP = 32760
EXT = 20
GAS = 262144
HUB = 174
MMIO = 1048576
MMU = 524288
MOD = 20
MUL = 20
MXP = 35
PHONEY_RLP = 65536 # can probably get lower
ROM = 2402
ROM_LEX = 20
SHF = 63
TX_RLP = 131072
TRM = 120
WCP = 156
LOG_DATA = 20
LOG_INFO = 20
RLP_ADDR = 20
RLP_TXN = 1300
RLP_TXN_RCPT = 100
TXN_DATA = 30
SHAKIRA_DATA = 262144
STP = 20
OOB = 262144

#
# Block-specific limits
#
BLOCK_KECCAK = 8192
BLOCK_L1_SIZE = 1000000
BLOCK_L2_L1_LOGS = 16
BLOCK_TRANSACTIONS = 200 # max number of tx in an L2 block

#
# Fixed size, static tables
#
BIN_REFERENCE_TABLE = 262144 # contains 3 * 256^2 + 256 data rows + 1 padding row
SHF_REFERENCE_TABLE = 4096 # contains 9 * 256 data rows + 1 padding row
INSTRUCTION_DECODER = 512 # contains 256 data rows + 1 padding row

#
# Precompiles limits
#
PRECOMPILE_ECRECOVER_EFFECTIVE_CALLS = 10000
PRECOMPILE_SHA2_BLOCKS = 10000
PRECOMPILE_RIPEMD_BLOCKS = 10000
PRECOMPILE_ECPAIRING_MILLER_LOOPS = 10000
PRECOMPILE_MODEXP_EFFECTIVE_CALLS = 10000
PRECOMPILE_ECADD_EFFECTIVE_CALLS = 10000
PRECOMPILE_ECMUL_EFFECTIVE_CALLS = 10000
PRECOMPILE_ECPAIRING_FINAL_EXPONENTIATIONS = 10000
PRECOMPILE_ECPAIRING_G2_MEMBERSHIP_CALLS = 10000
PRECOMPILE_ECPAIRING_MILLER_LOOPS = 10000
PRECOMPILE_BLAKE_EFFECTIVE_CALLS = 10000
PRECOMPILE_BLAKE_ROUNDS = 512
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EUC = 16384 # can probably be lower
EXP = 32760
EXT = 20
GAS = 262144
HUB = 50
HUB = 51
MMIO = 1048576
MMU = 524288
MOD = 20
Expand Down
Loading

0 comments on commit 77e343b

Please sign in to comment.