Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Module Line Count Verification to linea_estimateGas RPC Method #1

Merged
merged 11 commits into from
Apr 10, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Consensys Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package linea.plugin.acc.test.rpc.linea;

import static org.assertj.core.api.Assertions.assertThat;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.List;

import linea.plugin.acc.test.LineaPluginTestBase;
import linea.plugin.acc.test.TestCommandLineOptionsBuilder;
import linea.plugin.acc.test.tests.web3j.generated.SimpleStorage;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
import org.junit.jupiter.api.Test;

public class EstimateGasModuleLimitOverflowTest extends LineaPluginTestBase {
@Override
public List<String> getTestCliOptions() {
return new TestCommandLineOptionsBuilder()
.set(
"--plugin-linea-module-limit-file-path=",
getResourcePath("/txOverflowModuleLimits.toml"))
.build();
}

@Test
public void estimateGasFailsForExceedingModuleLineCountTest() throws Exception {

final Account sender = accounts.getSecondaryBenefactor();

final SimpleStorage simpleStorage = deploySimpleStorage();
final String txData = simpleStorage.add(BigInteger.valueOf(100)).encodeFunctionCall();
final var payload = Bytes.wrap(txData.getBytes(StandardCharsets.UTF_8));

final EstimateGasTest.CallParams callParams =
new EstimateGasTest.CallParams(
sender.getAddress(),
simpleStorage.getContractAddress(),
null,
payload.toHexString(),
"0");

final var reqLinea = new EstimateGasTest.BadLineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respLinea.getCode()).isEqualTo(-32000);
assertThat(respLinea.getMessage())
.isEqualTo("Transaction line count for module HUB=66 is above the limit 30");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import net.consensys.linea.config.LineaProfitabilityConfiguration;
import net.consensys.linea.config.LineaRpcCliOptions;
import net.consensys.linea.config.LineaRpcConfiguration;
import net.consensys.linea.config.LineaTracerConfiguration;
import net.consensys.linea.config.LineaTracerConfigurationCLiOptions;
import net.consensys.linea.config.LineaTransactionPoolValidatorCliOptions;
import net.consensys.linea.config.LineaTransactionPoolValidatorConfiguration;
import net.consensys.linea.config.LineaTransactionSelectorCliOptions;
Expand All @@ -42,10 +44,12 @@ public abstract class AbstractLineaSharedOptionsPlugin implements BesuPlugin {
private static LineaRpcCliOptions rpcCliOptions;
private static LineaProfitabilityCliOptions profitabilityCliOptions;
protected static LineaTransactionSelectorConfiguration transactionSelectorConfiguration;
protected static LineaTracerConfigurationCLiOptions tracerConfigurationCliOptions;
protected static LineaTransactionPoolValidatorConfiguration transactionPoolValidatorConfiguration;
protected static LineaL1L2BridgeConfiguration l1L2BridgeConfiguration;
protected static LineaRpcConfiguration rpcConfiguration;
protected static LineaProfitabilityConfiguration profitabilityConfiguration;
protected static LineaTracerConfiguration tracerConfiguration;

static {
// force the initialization of the gnark compress native library to fail fast in case of issues
Expand All @@ -67,12 +71,14 @@ public synchronized void register(final BesuContext context) {
l1L2BridgeCliOptions = LineaL1L2BridgeCliOptions.create();
rpcCliOptions = LineaRpcCliOptions.create();
profitabilityCliOptions = LineaProfitabilityCliOptions.create();
tracerConfigurationCliOptions = LineaTracerConfigurationCLiOptions.create();

cmdlineOptions.addPicoCLIOptions(CLI_OPTIONS_PREFIX, transactionSelectorCliOptions);
cmdlineOptions.addPicoCLIOptions(CLI_OPTIONS_PREFIX, transactionPoolValidatorCliOptions);
cmdlineOptions.addPicoCLIOptions(CLI_OPTIONS_PREFIX, l1L2BridgeCliOptions);
cmdlineOptions.addPicoCLIOptions(CLI_OPTIONS_PREFIX, rpcCliOptions);
cmdlineOptions.addPicoCLIOptions(CLI_OPTIONS_PREFIX, profitabilityCliOptions);
cmdlineOptions.addPicoCLIOptions(CLI_OPTIONS_PREFIX, tracerConfigurationCliOptions);
cliOptionsRegistered = true;
}
}
Expand All @@ -85,6 +91,7 @@ public void beforeExternalServices() {
l1L2BridgeConfiguration = l1L2BridgeCliOptions.toDomainObject();
rpcConfiguration = rpcCliOptions.toDomainObject();
profitabilityConfiguration = profitabilityCliOptions.toDomainObject();
tracerConfiguration = tracerConfigurationCliOptions.toDomainObject();
configured = true;
}

Expand All @@ -109,6 +116,8 @@ public void beforeExternalServices() {
"Configured plugin {} with profitability calculator configuration: {}",
getName(),
profitabilityConfiguration);

log.debug("Configured plugin {} with tracer configuration: {}", getName(), tracerConfiguration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Consensys Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package net.consensys.linea.config;

import lombok.Builder;

/** The Linea tracer configuration. */
@Builder(toBuilder = true)
public record LineaTracerConfiguration(String moduleLimitsFilePath) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Consensys Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package net.consensys.linea.config;

import com.google.common.base.MoreObjects;
import picocli.CommandLine;

public class LineaTracerConfigurationCLiOptions {

public static final String MODULE_LIMIT_FILE_PATH = "--plugin-linea-module-limit-file-path";
public static final String DEFAULT_MODULE_LIMIT_FILE_PATH = "moduleLimitFile.toml";

@CommandLine.Option(
names = {MODULE_LIMIT_FILE_PATH},
hidden = true,
paramLabel = "<STRING>",
description =
"Path to the toml file containing the module limits (default: ${DEFAULT-VALUE})")
private String moduleLimitFilePath = DEFAULT_MODULE_LIMIT_FILE_PATH;

private LineaTracerConfigurationCLiOptions() {}

/**
* Create Linea cli options.
*
* @return the Linea cli options
*/
public static LineaTracerConfigurationCLiOptions create() {
return new LineaTracerConfigurationCLiOptions();
}

/**
* Linea cli options from config.
*
* @param config the config
* @return the Linea cli options
*/
public static LineaTracerConfigurationCLiOptions fromConfig(
final LineaTracerConfiguration config) {
final LineaTracerConfigurationCLiOptions options = create();
options.moduleLimitFilePath = config.moduleLimitsFilePath();
return options;
}

/**
* To domain object Linea factory configuration.
*
* @return the Linea factory configuration
*/
public LineaTracerConfiguration toDomainObject() {
return LineaTracerConfiguration.builder().moduleLimitsFilePath(moduleLimitFilePath).build();
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add(MODULE_LIMIT_FILE_PATH, moduleLimitFilePath)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
public class LineaTransactionSelectorCliOptions {
public static final String MAX_BLOCK_CALLDATA_SIZE = "--plugin-linea-max-block-calldata-size";
public static final int DEFAULT_MAX_BLOCK_CALLDATA_SIZE = 70_000;

public static final String MODULE_LIMIT_FILE_PATH = "--plugin-linea-module-limit-file-path";
public static final String DEFAULT_MODULE_LIMIT_FILE_PATH = "moduleLimitFile.toml";

public static final String OVER_LINE_COUNT_LIMIT_CACHE_SIZE =
"--plugin-linea-over-line-count-limit-cache-size";
public static final int DEFAULT_OVER_LINE_COUNT_LIMIT_CACHE_SIZE = 10_000;
Expand All @@ -48,14 +44,6 @@ public class LineaTransactionSelectorCliOptions {
description = "Maximum size for the calldata of a block (default: ${DEFAULT-VALUE})")
private int maxBlockCallDataSize = DEFAULT_MAX_BLOCK_CALLDATA_SIZE;

@CommandLine.Option(
names = {MODULE_LIMIT_FILE_PATH},
hidden = true,
paramLabel = "<STRING>",
description =
"Path to the toml file containing the module limits (default: ${DEFAULT-VALUE})")
private String moduleLimitFilePath = DEFAULT_MODULE_LIMIT_FILE_PATH;

@Positive
@CommandLine.Option(
names = {OVER_LINE_COUNT_LIMIT_CACHE_SIZE},
Expand Down Expand Up @@ -112,7 +100,6 @@ public static LineaTransactionSelectorCliOptions fromConfig(
final LineaTransactionSelectorConfiguration config) {
final LineaTransactionSelectorCliOptions options = create();
options.maxBlockCallDataSize = config.maxBlockCallDataSize();
options.moduleLimitFilePath = config.moduleLimitsFilePath();
options.overLineCountLimitCacheSize = config.overLinesLimitCacheSize();
options.maxGasPerBlock = config.maxGasPerBlock();
options.unprofitableCacheSize = config.unprofitableCacheSize();
Expand All @@ -128,7 +115,6 @@ public static LineaTransactionSelectorCliOptions fromConfig(
public LineaTransactionSelectorConfiguration toDomainObject() {
return LineaTransactionSelectorConfiguration.builder()
.maxBlockCallDataSize(maxBlockCallDataSize)
.moduleLimitsFilePath(moduleLimitFilePath)
.overLinesLimitCacheSize(overLineCountLimitCacheSize)
.maxGasPerBlock(maxGasPerBlock)
.unprofitableCacheSize(unprofitableCacheSize)
Expand All @@ -140,7 +126,6 @@ public LineaTransactionSelectorConfiguration toDomainObject() {
public String toString() {
return MoreObjects.toStringHelper(this)
.add(MAX_BLOCK_CALLDATA_SIZE, maxBlockCallDataSize)
.add(MODULE_LIMIT_FILE_PATH, moduleLimitFilePath)
.add(OVER_LINE_COUNT_LIMIT_CACHE_SIZE, overLineCountLimitCacheSize)
.add(MAX_GAS_PER_BLOCK, maxGasPerBlock)
.add(UNPROFITABLE_CACHE_SIZE, unprofitableCacheSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@Builder(toBuilder = true)
public record LineaTransactionSelectorConfiguration(
int maxBlockCallDataSize,
String moduleLimitsFilePath,
int overLinesLimitCacheSize,
long maxGasPerBlock,
int unprofitableCacheSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package net.consensys.linea.rpc.linea;

import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.createLimitModules;

import com.google.auto.service.AutoService;
import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.AbstractLineaRequiredPlugin;
Expand Down Expand Up @@ -87,6 +89,10 @@ public void doRegister(final BesuContext context) {
public void beforeExternalServices() {
super.beforeExternalServices();
lineaEstimateGasMethod.init(
rpcConfiguration, transactionPoolValidatorConfiguration, profitabilityConfiguration);
rpcConfiguration,
transactionPoolValidatorConfiguration,
profitabilityConfiguration,
createLimitModules(tracerConfiguration),
l1L2BridgeConfiguration);
}
}
Loading
Loading