Skip to content

Commit

Permalink
[MINOR] Add javadoc (#507)
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <[email protected]>
  • Loading branch information
Gabriel-Trintinalia authored Dec 20, 2023
1 parent 27f6af8 commit 3ee98ea
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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
* <p>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) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -42,13 +53,20 @@ 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) {
rpcEndpointService.registerRPCEndpoint(
method.getNamespace(), method.getName(), method::execute);
}

/** Start the RPC service. This method loads the OpCodes. */
@Override
public void start() {
OpCodes.load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<TransactionSelectionService> service;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address> denied = new HashSet<>();
Expand Down

0 comments on commit 3ee98ea

Please sign in to comment.