Skip to content

Commit

Permalink
feature: Add module limit verification to linea_estimateGas
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <[email protected]>
  • Loading branch information
Gabriel-Trintinalia committed Apr 8, 2024
1 parent 03cdacf commit 45fa4eb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package net.consensys.linea.rpc.linea;

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

import com.google.auto.service.AutoService;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,6 @@ public void register(OperationTracer tracer) {
tracers.add(tracer);
}

/**
* Retrieves a registered tracer by its class type.
*
* @param clazz the class of the tracer to retrieve
* @param <T> the type of the tracer
* @return the registered tracer of the specified type
* @throws IllegalArgumentException if no tracer of the specified class is registered
*/
public <T extends OperationTracer> T getTracer(Class<T> clazz) {
for (OperationTracer tracer : tracers) {
if (clazz.isInstance(tracer)) {
return clazz.cast(tracer);
}
}
throw new IllegalArgumentException("No tracer found for class: " + clazz.getName());
}

/**
* Creates a {@link TracerAggregator} instance and registers the provided tracers.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private ModuleLimitsValidationResult(
this.moduleName = moduleName;
}

public static ModuleLimitsValidationResult ok() {
public static ModuleLimitsValidationResult valid() {
return new ModuleLimitsValidationResult(
ModuleLineCountValidator.ModuleLineCountResult.VALID, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
*/
package net.consensys.linea.sequencer.modulelimit;

import java.io.File;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import com.google.common.io.Resources;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.config.LineaTracerConfiguration;
import org.apache.tuweni.toml.Toml;
import org.apache.tuweni.toml.TomlParseResult;
import org.apache.tuweni.toml.TomlTable;

/**
* Accumulates and verifies line counts for modules based on provided limits. It supports verifying
Expand Down Expand Up @@ -70,7 +79,7 @@ public ModuleLimitsValidationResult validate(Map<String, Integer> currentAccumul
return ModuleLimitsValidationResult.blockModuleLineCountFull(moduleName);
}
}
return ModuleLimitsValidationResult.ok();
return ModuleLimitsValidationResult.valid();
}

/**
Expand All @@ -90,4 +99,27 @@ public enum ModuleLineCountResult {
BLOCK_MODULE_LINE_COUNT_FULL,
MODULE_NOT_DEFINED
}

public static Map<String, Integer> createLimitModules(
LineaTracerConfiguration lineaTracerConfiguration) {
try {
URL url = new File(lineaTracerConfiguration.moduleLimitsFilePath()).toURI().toURL();
final String tomlString = Resources.toString(url, StandardCharsets.UTF_8);
TomlParseResult result = Toml.parse(tomlString);
final TomlTable table = result.getTable("traces-limits");
final Map<String, Integer> limitsMap =
table.toMap().entrySet().stream()
.collect(
Collectors.toUnmodifiableMap(
Map.Entry::getKey, e -> Math.toIntExact((Long) e.getValue())));

return limitsMap;
} catch (final Exception e) {
final String errorMsg =
"Problem reading the toml file containing the limits for the modules: "
+ lineaTracerConfiguration.moduleLimitsFilePath();
log.error(errorMsg);
throw new RuntimeException(errorMsg, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package net.consensys.linea.sequencer.txselection;

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

import java.util.Optional;

Expand Down

0 comments on commit 45fa4eb

Please sign in to comment.