From 3ee98eab609b7e0424f0dfbc9bfe166b53f2e4a3 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Wed, 20 Dec 2023 12:33:04 +1100 Subject: [PATCH] [MINOR] Add javadoc (#507) Signed-off-by: Gabriel-Trintinalia --- ....java => AbstractLineaRequiredPlugin.java} | 2 +- .../counters/RollupGenerateCountersV0.java | 22 +++++++++++++--- .../RollupRpcEndpointServicePlugin.java | 26 ++++++++++++++++--- ...RollupGenerateConflatedTracesToFileV0.java | 7 ++++- .../RollupRpcEndpointServicePlugin.java | 24 ++++++++++++++--- .../LineaTransactionSelectorPlugin.java | 22 +++++----------- .../LineaTransactionValidatorPlugin.java | 11 +++++--- 7 files changed, 84 insertions(+), 30 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/{LineaRequiredPlugin.java => AbstractLineaRequiredPlugin.java} (95%) diff --git a/arithmetization/src/main/java/net/consensys/linea/LineaRequiredPlugin.java b/arithmetization/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/LineaRequiredPlugin.java rename to arithmetization/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java index 6f3327b071..4cf1131570 100644 --- a/arithmetization/src/main/java/net/consensys/linea/LineaRequiredPlugin.java +++ b/arithmetization/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.plugin.BesuPlugin; @Slf4j -public abstract class LineaRequiredPlugin implements BesuPlugin { +public abstract class AbstractLineaRequiredPlugin implements BesuPlugin { /** * Linea plugins extending this class will halt startup of Besu in case of exception during diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/counters/RollupGenerateCountersV0.java b/arithmetization/src/main/java/net/consensys/linea/rpc/counters/RollupGenerateCountersV0.java index f82dfb20a3..36253b60e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/rpc/counters/RollupGenerateCountersV0.java +++ b/arithmetization/src/main/java/net/consensys/linea/rpc/counters/RollupGenerateCountersV0.java @@ -27,7 +27,7 @@ import org.hyperledger.besu.plugin.services.exception.PluginRpcEndpointException; import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; -/** Responsible for trace counters generation. */ +/** This class is used to generate trace counters. */ @Slf4j public class RollupGenerateCountersV0 { private static final int CACHE_SIZE = 10_000; @@ -37,6 +37,11 @@ public class RollupGenerateCountersV0 { private final BesuContext besuContext; private TraceService traceService; + /** + * Constructor for RollupGenerateCountersV0. + * + * @param besuContext the BesuContext to be used. + */ public RollupGenerateCountersV0(final BesuContext besuContext) { this.besuContext = besuContext; } @@ -50,10 +55,14 @@ public String getName() { } /** - * Handles execution traces generation logic. + * Executes an RPC request to generate trace counters. * - * @param request holds parameters of the RPC request. - * @return an execution file trace. + * @param request The PluginRpcRequest object encapsulating the parameters of the RPC request. + * @return A Counters object encapsulating the results of the counters generation (Modules Line + * Count). The method uses a caching mechanism to store and retrieve previously computed trace + * counters for specific block numbers + *

If an exception occurs during the execution of the request, it is caught and wrapped in + * a PluginRpcEndpointException and rethrown. */ public Counters execute(final PluginRpcRequest request) { if (traceService == null) { @@ -92,6 +101,11 @@ public Counters execute(final PluginRpcRequest request) { } } + /** + * Initialize the TraceService. + * + * @return the initialized TraceService. + */ private TraceService initTraceService() { return besuContext .getService(TraceService.class) diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/counters/RollupRpcEndpointServicePlugin.java b/arithmetization/src/main/java/net/consensys/linea/rpc/counters/RollupRpcEndpointServicePlugin.java index fa1aa997c1..d5bf2ad282 100644 --- a/arithmetization/src/main/java/net/consensys/linea/rpc/counters/RollupRpcEndpointServicePlugin.java +++ b/arithmetization/src/main/java/net/consensys/linea/rpc/counters/RollupRpcEndpointServicePlugin.java @@ -18,15 +18,28 @@ import java.util.Optional; import com.google.auto.service.AutoService; -import net.consensys.linea.LineaRequiredPlugin; +import net.consensys.linea.AbstractLineaRequiredPlugin; import net.consensys.linea.zktracer.opcode.OpCodes; import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; import org.hyperledger.besu.plugin.services.RpcEndpointService; -/** Plugin with RPC endpoints. */ +/** + * Sets up an RPC endpoint for generating trace counters. + * + *

The RollupRpcEndpointServicePlugin registers an RPC endpoint named + * 'getTracesCountersByBlockNumberV0' under the 'rollup' namespace. When this endpoint is called, + * returns trace counters based on the provided request parameters. See {@link + * RollupGenerateCountersV0} + */ @AutoService(BesuPlugin.class) -public class RollupRpcEndpointServicePlugin extends LineaRequiredPlugin { +public class RollupRpcEndpointServicePlugin extends AbstractLineaRequiredPlugin { + + /** + * Register the RPC service. + * + * @param context the BesuContext to be used. + */ @Override public void doRegister(final BesuContext context) { RollupGenerateCountersV0 method = new RollupGenerateCountersV0(context); @@ -39,12 +52,19 @@ public void doRegister(final BesuContext context) { new RuntimeException("Failed to obtain RpcEndpointService from the BesuContext."))); } + /** + * Create and register the RPC service. + * + * @param method the RollupGenerateCountersV0 method to be used. + * @param rpcEndpointService the RpcEndpointService to be registered. + */ private void createAndRegister( final RollupGenerateCountersV0 method, final RpcEndpointService rpcEndpointService) { rpcEndpointService.registerRPCEndpoint( method.getNamespace(), method.getName(), method::execute); } + /** Start the RPC service. This method loads the OpCodes. */ @Override public void start() { OpCodes.load(); diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/RollupGenerateConflatedTracesToFileV0.java b/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/RollupGenerateConflatedTracesToFileV0.java index 15c2bbd4b9..bfa5260e48 100644 --- a/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/RollupGenerateConflatedTracesToFileV0.java +++ b/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/RollupGenerateConflatedTracesToFileV0.java @@ -28,7 +28,12 @@ import org.hyperledger.besu.plugin.services.exception.PluginRpcEndpointException; import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; -/** Responsible for conflated file traces generation. */ +/** + * Sets up an RPC endpoint for generating conflated file trace. This class provides an RPC endpoint + * named 'generateConflatedTracesToFileV0' under the 'rollup' namespace. When this endpoint is + * called, it triggers the execution of the 'execute' method, which generates conflated file traces + * based on the provided request parameters and writes them to a file. + */ @Slf4j public class RollupGenerateConflatedTracesToFileV0 { private final BesuContext besuContext; diff --git a/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/RollupRpcEndpointServicePlugin.java b/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/RollupRpcEndpointServicePlugin.java index 609e3318db..c8a7885a98 100644 --- a/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/RollupRpcEndpointServicePlugin.java +++ b/arithmetization/src/main/java/net/consensys/linea/rpc/tracegeneration/RollupRpcEndpointServicePlugin.java @@ -19,16 +19,27 @@ import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.LineaRequiredPlugin; +import net.consensys.linea.AbstractLineaRequiredPlugin; import net.consensys.linea.zktracer.opcode.OpCodes; import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; import org.hyperledger.besu.plugin.services.RpcEndpointService; -/** Plugin with RPC endpoints. */ +/** + * Registers RPC endpoints .This class provides an RPC endpoint named + * 'generateConflatedTracesToFileV0' under the 'rollup' namespace. It uses {@link + * RollupGenerateConflatedTracesToFileV0} to generate conflated file traces. This class provides an + * RPC endpoint named 'generateConflatedTracesToFileV0' under the 'rollup' namespace. + */ @AutoService(BesuPlugin.class) @Slf4j -public class RollupRpcEndpointServicePlugin extends LineaRequiredPlugin { +public class RollupRpcEndpointServicePlugin extends AbstractLineaRequiredPlugin { + + /** + * Register the RPC service. + * + * @param context the BesuContext to be used. + */ @Override public void doRegister(final BesuContext context) { RollupGenerateConflatedTracesToFileV0 method = @@ -42,6 +53,12 @@ public void doRegister(final BesuContext context) { new RuntimeException("Failed to obtain RpcEndpointService from the BesuContext."))); } + /** + * Create and register the RPC service. + * + * @param method the RollupGenerateConflatedTracesToFileV0 method to be used. + * @param rpcEndpointService the RpcEndpointService to be registered. + */ private void createAndRegister( final RollupGenerateConflatedTracesToFileV0 method, final RpcEndpointService rpcEndpointService) { @@ -49,6 +66,7 @@ private void createAndRegister( method.getNamespace(), method.getName(), method::execute); } + /** Start the RPC service. This method loads the OpCodes. */ @Override public void start() { OpCodes.load(); diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java b/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java index 03a3c2d452..a48cc6394f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java +++ b/arithmetization/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java @@ -18,7 +18,6 @@ import java.io.File; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -27,7 +26,7 @@ import com.google.auto.service.AutoService; import com.google.common.io.Resources; import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.LineaRequiredPlugin; +import net.consensys.linea.AbstractLineaRequiredPlugin; import org.apache.tuweni.toml.Toml; import org.apache.tuweni.toml.TomlParseResult; import org.apache.tuweni.toml.TomlTable; @@ -36,10 +35,14 @@ import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.TransactionSelectionService; -/** Implementation of the base {@link BesuPlugin} interface for Linea Transaction Selection. */ +/** + * This class extends the default transaction selection rules used by Besu. It leverages the + * TransactionSelectionService to manage and customize the process of transaction selection. This + * includes setting limits such as 'TraceLineLimit', 'maxBlockGas', and 'maxCallData'. + */ @Slf4j @AutoService(BesuPlugin.class) -public class LineaTransactionSelectorPlugin extends LineaRequiredPlugin { +public class LineaTransactionSelectorPlugin extends AbstractLineaRequiredPlugin { public static final String NAME = "linea"; private final LineaTransactionSelectorCliOptions options; private Optional service; @@ -96,17 +99,6 @@ public void start() { } } - private String toCamelCase(final String in) { - final String[] parts = in.toLowerCase().split("_"); - final StringBuilder sb = new StringBuilder(); - Arrays.stream(parts) - .forEach(p -> sb.append(p.substring(0, 1).toUpperCase()).append(p.substring(1))); - return sb.toString(); - } - - @Override - public void stop() {} - private void createAndRegister(final TransactionSelectionService transactionSelectionService) { transactionSelectionService.registerTransactionSelectorFactory( new LineaTransactionSelectorFactory(options, () -> this.limitsMap)); diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txvalidation/LineaTransactionValidatorPlugin.java b/arithmetization/src/main/java/net/consensys/linea/sequencer/txvalidation/LineaTransactionValidatorPlugin.java index e3c52cdecb..c3422b1c21 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txvalidation/LineaTransactionValidatorPlugin.java +++ b/arithmetization/src/main/java/net/consensys/linea/sequencer/txvalidation/LineaTransactionValidatorPlugin.java @@ -24,17 +24,22 @@ import com.google.auto.service.AutoService; import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.LineaRequiredPlugin; +import net.consensys.linea.AbstractLineaRequiredPlugin; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; import org.hyperledger.besu.plugin.services.PicoCLIOptions; import org.hyperledger.besu.plugin.services.PluginTransactionValidatorService; -/** Implementation of the base {@link BesuPlugin} interface for Linea Transaction Validation. */ +/** + * This class extends the default transaction validation rules for adding transactions to the + * transaction pool. It leverages the PluginTransactionValidatorService to manage and customize the + * process of transaction validation. This includes, for example, setting a deny list of addresses + * that are not allowed to add transactions to the pool. + */ @Slf4j @AutoService(BesuPlugin.class) -public class LineaTransactionValidatorPlugin extends LineaRequiredPlugin { +public class LineaTransactionValidatorPlugin extends AbstractLineaRequiredPlugin { public static final String NAME = "linea"; private final LineaTransactionValidatorCliOptions options; private final Set

denied = new HashSet<>();