diff --git a/sequencer/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java b/sequencer/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java index 93e18d6d..c3ea0674 100644 --- a/sequencer/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/AbstractLineaSharedOptionsPlugin.java @@ -35,7 +35,7 @@ @Slf4j public abstract class AbstractLineaSharedOptionsPlugin implements BesuPlugin { - private static String CLI_OPTIONS_PREFIX = "linea"; + private static final String CLI_OPTIONS_PREFIX = "linea"; private static boolean cliOptionsRegistered = false; private static boolean configured = false; private static LineaTransactionSelectorCliOptions transactionSelectorCliOptions; diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracer.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracer.java deleted file mode 100644 index eba0f4ee..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracer.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.continoustracing; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Optional; - -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.continoustracing.exception.InvalidBlockTraceException; -import net.consensys.linea.continoustracing.exception.TraceVerificationException; -import net.consensys.linea.corset.CorsetValidator; -import net.consensys.linea.zktracer.ZkTracer; -import org.apache.commons.io.FileUtils; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.plugin.data.BlockTraceResult; -import org.hyperledger.besu.plugin.data.TransactionTraceResult; -import org.hyperledger.besu.plugin.services.TraceService; - -@Slf4j -public class ContinuousTracer { - private static final Optional TRACES_PATH = - Optional.ofNullable(System.getenv("TRACES_DIR")).map(Paths::get); - private final TraceService traceService; - private final CorsetValidator corsetValidator; - - public ContinuousTracer(final TraceService traceService, final CorsetValidator corsetValidator) { - this.traceService = traceService; - this.corsetValidator = corsetValidator; - } - - public CorsetValidator.Result verifyTraceOfBlock( - final Hash blockHash, final String zkEvmBin, final ZkTracer zkTracer) - throws TraceVerificationException, InvalidBlockTraceException { - zkTracer.traceStartConflation(1); - - final BlockTraceResult blockTraceResult; - try { - blockTraceResult = traceService.traceBlock(blockHash, zkTracer); - } catch (final Exception e) { - throw new TraceVerificationException(blockHash, e.getMessage()); - } finally { - // TODO: After consulting with the Arithmetization team, it is ok to pass the world state as - // null for now, but it - // should be fixed at some point. - zkTracer.traceEndConflation(null); - } - - for (final TransactionTraceResult transactionTraceResult : - blockTraceResult.transactionTraceResults()) { - if (transactionTraceResult.getStatus() != TransactionTraceResult.Status.SUCCESS) { - throw new InvalidBlockTraceException( - transactionTraceResult.getTxHash(), - transactionTraceResult.errorMessage().orElse("Unknown error")); - } - } - - final CorsetValidator.Result result; - try { - result = - corsetValidator.validate( - TRACES_PATH.map(zkTracer::writeToTmpFile).orElseGet(zkTracer::writeToTmpFile), - zkEvmBin); - if (!result.isValid()) { - log.error("Trace of block {} is not valid", blockHash.toHexString()); - return result; - } - } catch (RuntimeException e) { - log.error( - "Error while validating trace of block {}: {}", blockHash.toHexString(), e.getMessage()); - throw new TraceVerificationException(blockHash, e.getMessage()); - } - - try { - FileUtils.delete(result.traceFile()); - } catch (IOException e) { - log.warn("Error while deleting trace file {}: {}", result.traceFile(), e.getMessage()); - } - - log.info("Trace of block {} is valid", blockHash.toHexString()); - return result; - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingBlockAddedListener.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingBlockAddedListener.java deleted file mode 100644 index f34c255f..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingBlockAddedListener.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.continoustracing; - -import java.io.IOException; -import java.nio.file.Files; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.continoustracing.exception.InvalidBlockTraceException; -import net.consensys.linea.continoustracing.exception.InvalidTraceHandlerException; -import net.consensys.linea.continoustracing.exception.TraceVerificationException; -import net.consensys.linea.corset.CorsetValidator; -import net.consensys.linea.zktracer.ZkTracer; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.plugin.data.AddedBlockContext; -import org.hyperledger.besu.plugin.data.BlockHeader; -import org.hyperledger.besu.plugin.services.BesuEvents; - -@Slf4j -public class ContinuousTracingBlockAddedListener implements BesuEvents.BlockAddedListener { - private final ContinuousTracer continuousTracer; - private final TraceFailureHandler traceFailureHandler; - private final String zkEvmBin; - - static final int BLOCK_PARALLELISM = 5; - final ThreadPoolExecutor pool = - new ThreadPoolExecutor( - BLOCK_PARALLELISM, - BLOCK_PARALLELISM, - 0L, - TimeUnit.SECONDS, - new ArrayBlockingQueue<>(BLOCK_PARALLELISM), - new ThreadPoolExecutor.CallerRunsPolicy()); - - public ContinuousTracingBlockAddedListener( - final ContinuousTracer continuousTracer, - final TraceFailureHandler traceFailureHandler, - final String zkEvmBin) { - this.continuousTracer = continuousTracer; - this.traceFailureHandler = traceFailureHandler; - this.zkEvmBin = zkEvmBin; - } - - @Override - public void onBlockAdded(final AddedBlockContext addedBlockContext) { - pool.submit( - () -> { - final BlockHeader blockHeader = addedBlockContext.getBlockHeader(); - final Hash blockHash = blockHeader.getBlockHash(); - log.info("Tracing block {} ({})", blockHeader.getNumber(), blockHash.toHexString()); - - try { - final CorsetValidator.Result traceResult = - continuousTracer.verifyTraceOfBlock(blockHash, zkEvmBin, new ZkTracer()); - Files.delete(traceResult.traceFile().toPath()); - - if (!traceResult.isValid()) { - log.error("Corset returned and error for block {}", blockHeader.getNumber()); - traceFailureHandler.handleCorsetFailure(blockHeader, traceResult); - return; - } - log.info("Trace for block {} verified successfully", blockHeader.getNumber()); - } catch (InvalidBlockTraceException e) { - log.error("Error while tracing block {}: {}", blockHeader.getNumber(), e.getMessage()); - traceFailureHandler.handleBlockTraceFailure(blockHeader.getNumber(), e.txHash(), e); - } catch (TraceVerificationException e) { - log.error(e.getMessage()); - } catch (InvalidTraceHandlerException e) { - log.error("Error while handling invalid trace: {}", e.getMessage()); - } catch (IOException e) { - log.error("IO error: {}", e.getMessage()); - } finally { - log.info("End of tracing block {}", blockHeader.getNumber()); - } - }); - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingCliOptions.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingCliOptions.java deleted file mode 100644 index 4cc72a2a..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingCliOptions.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.continoustracing; - -import com.google.common.base.MoreObjects; -import picocli.CommandLine; - -public class ContinuousTracingCliOptions { - public static final String CONTINUOUS_TRACING_ENABLED = - "--plugin-linea-continuous-tracing-enabled"; - public static final String CONTINUOUS_TRACING_ZK_EVM_BIN = - "--plugin-linea-continuous-tracing-zk-evm-bin"; - - @CommandLine.Option( - names = {CONTINUOUS_TRACING_ENABLED}, - hidden = true, - paramLabel = "", - description = "Enable continuous tracing (default: false)") - private boolean continuousTracingEnabled = false; - - @CommandLine.Option( - names = {CONTINUOUS_TRACING_ZK_EVM_BIN}, - hidden = true, - paramLabel = "", - description = "Path to the ZkEvm binary") - private String zkEvmBin = null; - - private ContinuousTracingCliOptions() {} - - public static ContinuousTracingCliOptions create() { - return new ContinuousTracingCliOptions(); - } - - public ContinuousTracingConfiguration toDomainObject() { - return new ContinuousTracingConfiguration(continuousTracingEnabled, zkEvmBin); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add(CONTINUOUS_TRACING_ENABLED, continuousTracingEnabled) - .add(CONTINUOUS_TRACING_ZK_EVM_BIN, zkEvmBin) - .toString(); - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingConfiguration.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingConfiguration.java deleted file mode 100644 index c213b9d5..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingConfiguration.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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.continoustracing; - -public record ContinuousTracingConfiguration(boolean continuousTracing, String zkEvmBin) {} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingPlugin.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingPlugin.java deleted file mode 100644 index 8a76acf8..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/ContinuousTracingPlugin.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.continoustracing; - -import java.util.Optional; - -import com.google.auto.service.AutoService; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.corset.CorsetValidator; -import org.hyperledger.besu.plugin.BesuContext; -import org.hyperledger.besu.plugin.BesuPlugin; -import org.hyperledger.besu.plugin.services.BesuEvents; -import org.hyperledger.besu.plugin.services.PicoCLIOptions; -import org.hyperledger.besu.plugin.services.TraceService; - -@Slf4j -@AutoService(BesuPlugin.class) -public class ContinuousTracingPlugin implements BesuPlugin { - public static final String NAME = "linea-continuous"; - public static final String ENV_WEBHOOK_URL = "SLACK_SHADOW_NODE_WEBHOOK_URL"; - - private final ContinuousTracingCliOptions options; - private BesuContext context; - - public ContinuousTracingPlugin() { - options = ContinuousTracingCliOptions.create(); - } - - @Override - public Optional getName() { - return Optional.of(NAME); - } - - @Override - public void register(final BesuContext context) { - final PicoCLIOptions cmdlineOptions = - context - .getService(PicoCLIOptions.class) - .orElseThrow( - () -> - new IllegalStateException( - "Expecting a PicoCLI options to register CLI options with, but none found.")); - - cmdlineOptions.addPicoCLIOptions(getName().get(), options); - - this.context = context; - } - - @Override - public void start() { - log.info("Starting {} with configuration: {}", NAME, options); - - final ContinuousTracingConfiguration tracingConfiguration = options.toDomainObject(); - - if (!tracingConfiguration.continuousTracing()) { - return; - } - - // BesuEvents can only be requested after the plugin has been registered. - final BesuEvents besuEvents = - context - .getService(BesuEvents.class) - .orElseThrow( - () -> - new IllegalStateException( - "Expecting a BesuEvents to register events with, but none found.")); - - final TraceService traceService = - context - .getService(TraceService.class) - .orElseThrow( - () -> new IllegalStateException("Expecting a TraceService, but none found.")); - - if (tracingConfiguration.zkEvmBin() == null) { - log.error("zkEvmBin must be specified when continuousTracing is enabled"); - System.exit(1); - } - - final String webHookUrl = System.getenv(ENV_WEBHOOK_URL); - if (webHookUrl == null) { - log.error( - "Webhook URL must be specified as environment variable {} when continuousTracing is enabled", - ENV_WEBHOOK_URL); - System.exit(1); - } - - besuEvents.addBlockAddedListener( - new ContinuousTracingBlockAddedListener( - new ContinuousTracer(traceService, new CorsetValidator()), - new TraceFailureHandler(SlackNotificationService.create(webHookUrl)), - tracingConfiguration.zkEvmBin())); - } - - @Override - public void stop() {} -} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/SlackNotificationService.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/SlackNotificationService.java deleted file mode 100644 index d3a10eab..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/SlackNotificationService.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.continoustracing; - -import static com.slack.api.model.block.Blocks.asBlocks; -import static com.slack.api.model.block.Blocks.divider; -import static com.slack.api.model.block.Blocks.section; -import static com.slack.api.model.block.composition.BlockCompositions.markdownText; - -import java.io.IOException; -import java.util.stream.Collectors; - -import com.slack.api.Slack; -import com.slack.api.webhook.Payload; -import com.slack.api.webhook.WebhookResponse; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.corset.CorsetValidator; -import org.hyperledger.besu.datatypes.Hash; - -@Slf4j -public class SlackNotificationService { - final Slack slack; - final String webHookUrl; - - protected SlackNotificationService(final Slack slack, final String webHookUrl) { - this.slack = slack; - this.webHookUrl = webHookUrl; - } - - public static SlackNotificationService create(final String webHookUrl) { - return new SlackNotificationService(Slack.getInstance(), webHookUrl); - } - - public void sendCorsetFailureNotification( - final long blockNumber, final String blockHash, final CorsetValidator.Result validationResult) - throws IOException { - final Payload messagePayload = - Payload.builder() - .text("Slack couldn't properly display the message.") - .blocks( - asBlocks( - section( - section -> - section.text( - markdownText( - String.format( - "*Trace verification failure for block %d (%s)", - blockNumber, blockHash)))), - divider(), - section( - section -> - section.text( - markdownText( - "Trace verification failed with the following error:\n\n" - + "```" - + validationResult - .corsetOutput() - // Remove all ANSI escape codes that Slack does not like - .replaceAll("\u001B\\[[;\\d]*m", "") - + "```\n\n" - + "Trace file: " - + validationResult.traceFile()))))) - .build(); - - WebhookResponse response = slack.send(webHookUrl, messagePayload); - checkResponse(response); - } - - public void sendBlockTraceFailureNotification( - final long blockNumber, final Hash txHash, final Throwable throwable) throws IOException { - - log.info("Throwable.getMessage(): {}", throwable.getMessage()); - - final Payload messagePayload = - Payload.builder() - .text("Slack couldn't properly display the message.") - .blocks( - asBlocks( - section( - section -> - section.text( - markdownText( - String.format( - "*Error while tracing transaction %s in block %d*", - txHash.toHexString(), blockNumber)))), - divider(), - section( - section -> - section.text( - markdownText( - "Trace generation failed with the following error:\n\n" - + "```" - // more than 2000 characters will cause a 400 error when - // sending the message - + throwable - .getMessage() - .lines() - .limit(3) - .collect(Collectors.joining("\n")) - .substring(0, 2000) - + "```"))))) - .build(); - - WebhookResponse response = slack.send(webHookUrl, messagePayload); - checkResponse(response); - } - - private void checkResponse(final WebhookResponse response) throws IOException { - if (response.getCode() != 200) { - throw new IOException( - "Error while sending notification: status code: " - + response.getCode() - + ", body: " - + response.getBody()); - } - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java deleted file mode 100644 index ed62584e..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/TraceFailureHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.continoustracing; - -import java.io.IOException; - -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.continoustracing.exception.InvalidTraceHandlerException; -import net.consensys.linea.corset.CorsetValidator; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.plugin.data.BlockHeader; - -@Slf4j -public class TraceFailureHandler { - final SlackNotificationService slackNotificationService; - - public TraceFailureHandler(final SlackNotificationService slackNotificationService) { - this.slackNotificationService = slackNotificationService; - } - - public void handleCorsetFailure( - final BlockHeader blockHeader, final CorsetValidator.Result result) - throws InvalidTraceHandlerException { - try { - slackNotificationService.sendCorsetFailureNotification( - blockHeader.getNumber(), blockHeader.getBlockHash().toHexString(), result); - } catch (IOException e) { - log.error("Error while sending slack notification: {}", e.getMessage()); - throw new InvalidTraceHandlerException(e); - } - } - - public void handleBlockTraceFailure( - final long blockNumber, final Hash txHash, final Throwable throwable) { - try { - slackNotificationService.sendBlockTraceFailureNotification(blockNumber, txHash, throwable); - } catch (IOException e) { - log.error("Error while handling block trace failure: {}", e.getMessage()); - } - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidBlockTraceException.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidBlockTraceException.java deleted file mode 100644 index 80847cf1..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidBlockTraceException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.continoustracing.exception; - -import org.hyperledger.besu.datatypes.Hash; - -public class InvalidBlockTraceException extends Throwable { - final Hash txHash; - - public InvalidBlockTraceException(final Hash txHash, final String message) { - super(message); - - this.txHash = txHash; - } - - public Hash txHash() { - return txHash; - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidTraceHandlerException.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidTraceHandlerException.java deleted file mode 100644 index 5e4b2f4e..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/InvalidTraceHandlerException.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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.continoustracing.exception; - -public class InvalidTraceHandlerException extends Throwable { - public InvalidTraceHandlerException(Throwable t) { - super(t); - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/TraceVerificationException.java b/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/TraceVerificationException.java deleted file mode 100644 index 5fb13608..00000000 --- a/sequencer/src/main/java/net/consensys/linea/continoustracing/exception/TraceVerificationException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.continoustracing.exception; - -import org.hyperledger.besu.datatypes.Hash; - -public class TraceVerificationException extends Throwable { - public TraceVerificationException(final Hash blockHash, final String message) { - super( - "Verification of trace of block " + blockHash + " has failed.\nError message: " + message); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/extradata/LineaExtraDataHandler.java b/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataHandler.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/extradata/LineaExtraDataHandler.java rename to sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataHandler.java index 2aeed3c6..fe1c039a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/extradata/LineaExtraDataHandler.java +++ b/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataHandler.java @@ -24,7 +24,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt32; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.datatypes.rpc.JsonRpcResponseType; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponseType; import org.hyperledger.besu.plugin.data.AddedBlockContext; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.services.BesuEvents; diff --git a/arithmetization/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java b/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java rename to sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/LineaEndpointServicePlugin.java similarity index 98% rename from sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java rename to sequencer/src/main/java/net/consensys/linea/rpc/LineaEndpointServicePlugin.java index 0aab37ab..abc9c186 100644 --- a/sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEndpointServicePlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/rpc/LineaEndpointServicePlugin.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.rpc.linea; +package net.consensys.linea.rpc; import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.createLimitModules; diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java b/sequencer/src/main/java/net/consensys/linea/rpc/LineaEstimateGas.java similarity index 99% rename from sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java rename to sequencer/src/main/java/net/consensys/linea/rpc/LineaEstimateGas.java index a390ff7c..0de4b34b 100644 --- a/sequencer/src/main/java/net/consensys/linea/rpc/linea/LineaEstimateGas.java +++ b/sequencer/src/main/java/net/consensys/linea/rpc/LineaEstimateGas.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.rpc.linea; +package net.consensys.linea.rpc; import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.ModuleLineCountResult.MODULE_NOT_DEFINED; import static net.consensys.linea.sequencer.modulelimit.ModuleLineCountValidator.ModuleLineCountResult.TX_MODULE_LINE_COUNT_OVERFLOW; @@ -43,7 +43,6 @@ import org.bouncycastle.crypto.params.ECDomainParameters; import org.hyperledger.besu.crypto.SECPSignature; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.datatypes.rpc.RpcMethodError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonCallParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter; @@ -56,6 +55,7 @@ import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.exception.PluginRpcEndpointException; import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; +import org.hyperledger.besu.plugin.services.rpc.RpcMethodError; @Slf4j public class LineaEstimateGas { diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/capture/Capture.java b/sequencer/src/main/java/net/consensys/linea/rpc/capture/Capture.java deleted file mode 100644 index 7277bdd9..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/capture/Capture.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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.rpc.capture; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** FileTrace represents an execution trace. */ -public record Capture(@JsonProperty("capture") String capture) {} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureEndpointServicePlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureEndpointServicePlugin.java deleted file mode 100644 index 3868fb07..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureEndpointServicePlugin.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.rpc.capture; - -import java.util.Optional; - -import com.google.auto.service.AutoService; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.AbstractLineaRequiredPlugin; -import org.hyperledger.besu.plugin.BesuContext; -import org.hyperledger.besu.plugin.BesuPlugin; -import org.hyperledger.besu.plugin.services.RpcEndpointService; - -/** - * Registers RPC endpoints .This class provides an RPC endpoint named - * 'generateConflatedTracesToFileV0' under the 'rollup' namespace. It uses {@link CaptureToFile} to - * generate conflated file traces. This class provides an RPC endpoint named - * 'generateConflatedTracesToFileV0' under the 'rollup' namespace. - */ -@AutoService(BesuPlugin.class) -@Slf4j -public class CaptureEndpointServicePlugin extends AbstractLineaRequiredPlugin { - - /** - * Register the RPC service. - * - * @param context the BesuContext to be used. - */ - @Override - public void doRegister(final BesuContext context) { - CaptureToFile method = new CaptureToFile(context); - - Optional service = context.getService(RpcEndpointService.class); - createAndRegister( - method, - service.orElseThrow( - () -> - 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 CaptureToFile 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() {} -} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureParams.java b/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureParams.java deleted file mode 100644 index a9973d99..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureParams.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.rpc.capture; - -import java.security.InvalidParameterException; - -/** Holds needed parameters for sending an execution trace generation request. */ -@SuppressWarnings("unused") -public record CaptureParams(long fromBlock, long toBlock) { - private static final int EXPECTED_PARAMS_SIZE = 2; - - /** - * Parses a list of params to a {@link CaptureParams} object. - * - * @param params an array of parameters. - * @return a parsed {@link CaptureParams} object.. - */ - public static CaptureParams createTraceParams(final Object[] params) { - // validate params size - if (params.length != EXPECTED_PARAMS_SIZE) { - throw new InvalidParameterException( - String.format("Expected %d parameters but got %d", EXPECTED_PARAMS_SIZE, params.length)); - } - - long fromBlock = Long.parseLong(params[0].toString()); - long toBlock = Long.parseLong(params[1].toString()); - - return new CaptureParams(fromBlock, toBlock); - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureToFile.java b/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureToFile.java deleted file mode 100644 index 958a9b3c..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/capture/CaptureToFile.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.rpc.capture; - -import com.google.common.base.Stopwatch; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.blockcapture.BlockCapturer; -import org.hyperledger.besu.plugin.BesuContext; -import org.hyperledger.besu.plugin.services.TraceService; -import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; - -/** - * 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 CaptureToFile { - private final BesuContext besuContext; - private TraceService traceService; - - public CaptureToFile(final BesuContext besuContext) { - this.besuContext = besuContext; - } - - public String getNamespace() { - return "rollup"; - } - - public String getName() { - return "captureConflation"; - } - - /** - * Handles execution traces generation logic. - * - * @param request holds parameters of the RPC request. - * @return an execution file trace. - */ - public Capture execute(final PluginRpcRequest request) { - if (this.traceService == null) { - this.traceService = getTraceService(); - } - - CaptureParams params = CaptureParams.createTraceParams(request.getParams()); - final long fromBlock = params.fromBlock(); - final long toBlock = params.toBlock(); - final BlockCapturer tracer = new BlockCapturer(); - - Stopwatch sw = Stopwatch.createStarted(); - traceService.trace( - fromBlock, - toBlock, - worldStateBeforeTracing -> { - tracer.setWorld(worldStateBeforeTracing); - tracer.traceStartConflation(toBlock - fromBlock + 1); - }, - tracer::traceEndConflation, - tracer); - log.info("[CAPTURE] capture for {}-{} computed in {}", fromBlock, toBlock, sw); - return new Capture(tracer.toJson()); - } - - private TraceService getTraceService() { - return this.besuContext - .getService(TraceService.class) - .orElseThrow( - () -> - new RuntimeException( - "Unable to find trace service. Please ensure TraceService is registered.")); - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/counters/Counters.java b/sequencer/src/main/java/net/consensys/linea/rpc/counters/Counters.java deleted file mode 100644 index 9e1d2e36..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/counters/Counters.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.rpc.counters; - -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** FileTrace represents an execution trace. */ -public record Counters( - @JsonProperty("tracesEngineVersion") String tracesEngineVersion, - @JsonProperty("blockNumber") long blockNumber, - @JsonProperty("tracesCounters") Map traceCountersByModule) {} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersEndpointServicePlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersEndpointServicePlugin.java deleted file mode 100644 index 8c46578d..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersEndpointServicePlugin.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.rpc.counters; - -import com.google.auto.service.AutoService; -import net.consensys.linea.AbstractLineaSharedOptionsPlugin; -import org.hyperledger.besu.plugin.BesuContext; -import org.hyperledger.besu.plugin.BesuPlugin; -import org.hyperledger.besu.plugin.services.RpcEndpointService; - -/** - * Sets up an RPC endpoint for generating trace counters. - * - *

The CountersEndpointServicePlugin 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 GenerateCountersV0} - */ -@AutoService(BesuPlugin.class) -public class CountersEndpointServicePlugin extends AbstractLineaSharedOptionsPlugin { - private BesuContext besuContext; - private RpcEndpointService rpcEndpointService; - /** - * Register the RPC service. - * - * @param context the BesuContext to be used. - */ - @Override - public void register(final BesuContext context) { - super.register(context); - besuContext = context; - rpcEndpointService = - context - .getService(RpcEndpointService.class) - .orElseThrow( - () -> - new RuntimeException( - "Failed to obtain RpcEndpointService from the BesuContext.")); - } - - @Override - public void beforeExternalServices() { - super.beforeExternalServices(); - GenerateCountersV0 method = new GenerateCountersV0(besuContext); - createAndRegister(method, rpcEndpointService); - } - - /** - * 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 GenerateCountersV0 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() {} -} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersRequestParams.java b/sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersRequestParams.java deleted file mode 100644 index 83e48fc6..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/counters/CountersRequestParams.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.rpc.counters; - -import java.security.InvalidParameterException; - -import net.consensys.linea.zktracer.ZkTracer; - -/** Holds needed parameters for sending an execution trace generation request. */ -@SuppressWarnings("unused") -public record CountersRequestParams(long blockNumber, String runtimeVersion) { - private static final int EXPECTED_PARAMS_SIZE = 2; - - /** - * Parses a list of params to a {@link CountersRequestParams} object. - * - * @param params an array of parameters. - * @return a parsed {@link CountersRequestParams} object.. - */ - public static CountersRequestParams createTraceParams(final Object[] params) { - // validate params size - if (params.length != EXPECTED_PARAMS_SIZE) { - throw new InvalidParameterException( - String.format("Expected %d parameters but got %d", EXPECTED_PARAMS_SIZE, params.length)); - } - - long blockNumber = Long.parseLong(params[0].toString()); - String version = params[1].toString(); - - if (!version.equals(getTracerRuntime())) { - throw new InvalidParameterException( - String.format( - "INVALID_TRACES_VERSION: Runtime version is %s, requesting version %s", - getTracerRuntime(), version)); - } - - return new CountersRequestParams(blockNumber, version); - } - - private static String getTracerRuntime() { - return ZkTracer.class.getPackage().getSpecificationVersion(); - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/counters/GenerateCountersV0.java b/sequencer/src/main/java/net/consensys/linea/rpc/counters/GenerateCountersV0.java deleted file mode 100644 index c59803be..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/counters/GenerateCountersV0.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.rpc.counters; - -import java.util.Map; - -import com.google.common.base.Stopwatch; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.ZkTracer; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.plugin.BesuContext; -import org.hyperledger.besu.plugin.services.TraceService; -import org.hyperledger.besu.plugin.services.exception.PluginRpcEndpointException; -import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; - -/** This class is used to generate trace counters. */ -@Slf4j -public class GenerateCountersV0 { - private static final int CACHE_SIZE = 10_000; - static final Cache> cache = - CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).build(); - - private final BesuContext besuContext; - private TraceService traceService; - - /** - * Constructor for RollupGenerateCountersV0. - * - * @param besuContext the BesuContext to be used. - */ - public GenerateCountersV0(final BesuContext besuContext) { - this.besuContext = besuContext; - } - - public String getNamespace() { - return "rollup"; - } - - public String getName() { - return "getTracesCountersByBlockNumberV0"; - } - - /** - * Executes an RPC request to generate trace counters. - * - * @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) { - traceService = initTraceService(); - } - - try { - final Stopwatch sw = Stopwatch.createStarted(); - final CountersRequestParams params = - CountersRequestParams.createTraceParams(request.getParams()); - final long requestedBlockNumber = params.blockNumber(); - - final Counters r = - new Counters( - params.runtimeVersion(), - requestedBlockNumber, - cache - .asMap() - .computeIfAbsent( - requestedBlockNumber, - blockNumber -> { - final ZkTracer tracer = new ZkTracer(); - traceService.trace( - blockNumber, - blockNumber, - worldStateBeforeTracing -> tracer.traceStartConflation(1), - tracer::traceEndConflation, - tracer); - - return tracer.getModulesLineCount(); - })); - log.info("counters for {} returned in {}", requestedBlockNumber, sw); - return r; - } catch (Exception ex) { - throw new PluginRpcEndpointException(RpcErrorType.PLUGIN_INTERNAL_ERROR, ex.getMessage()); - } - } - - /** - * Initialize the TraceService. - * - * @return the initialized TraceService. - */ - private TraceService initTraceService() { - return besuContext - .getService(TraceService.class) - .orElseThrow( - () -> - new RuntimeException( - "Unable to find trace service. Please ensure TraceService is registered.")); - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/GenerateConflatedTracesV0.java b/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/GenerateConflatedTracesV0.java deleted file mode 100644 index d03bcb50..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/GenerateConflatedTracesV0.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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.rpc.tracegeneration; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import com.google.common.base.Stopwatch; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.ZkTracer; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.plugin.BesuContext; -import org.hyperledger.besu.plugin.services.BesuConfiguration; -import org.hyperledger.besu.plugin.services.TraceService; -import org.hyperledger.besu.plugin.services.exception.PluginRpcEndpointException; -import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; - -/** - * 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 GenerateConflatedTracesV0 { - private final BesuContext besuContext; - private Path tracesPath; - private TraceService traceService; - - public GenerateConflatedTracesV0(final BesuContext besuContext) { - this.besuContext = besuContext; - } - - public String getNamespace() { - return "rollup"; - } - - public String getName() { - return "generateConflatedTracesToFileV0"; - } - - /** - * Handles execution traces generation logic. - * - * @param request holds parameters of the RPC request. - * @return an execution file trace. - */ - public TraceFile execute(final PluginRpcRequest request) { - Stopwatch sw = Stopwatch.createStarted(); - if (this.traceService == null) { - this.traceService = getTraceService(); - } - if (this.tracesPath == null) { - this.tracesPath = getTracesPath(); - } - - try { - TraceRequestParams params = TraceRequestParams.createTraceParams(request.getParams()); - - final long fromBlock = params.fromBlock(); - final long toBlock = params.toBlock(); - final ZkTracer tracer = new ZkTracer(); - traceService.trace( - fromBlock, - toBlock, - worldStateBeforeTracing -> tracer.traceStartConflation(toBlock - fromBlock + 1), - tracer::traceEndConflation, - tracer); - log.info("[TRACING] trace for {}-{} computed in {}", fromBlock, toBlock, sw); - sw.reset().start(); - final String path = writeTraceToFile(tracer, params.runtimeVersion()); - log.info("[TRACING] trace for {}-{} serialized to {} in {}", path, toBlock, fromBlock, sw); - return new TraceFile(params.runtimeVersion(), path); - } catch (Exception ex) { - throw new PluginRpcEndpointException(RpcErrorType.PLUGIN_INTERNAL_ERROR, ex.getMessage()); - } - } - - private Path getTracesPath() { - final String envVar = System.getenv("TRACES_DIR"); - if (envVar == null) { - return this.besuContext - .getService(BesuConfiguration.class) - .map(BesuConfiguration::getDataPath) - .map(x -> x.resolve("traces")) - .orElseThrow( - () -> - new RuntimeException( - "Unable to find data path. Please ensure BesuConfiguration is registered.")); - } else { - return Paths.get(envVar); - } - } - - private TraceService getTraceService() { - return this.besuContext - .getService(TraceService.class) - .orElseThrow( - () -> - new RuntimeException( - "Unable to find trace service. Please ensure TraceService is registered.")); - } - - private String writeTraceToFile(final ZkTracer tracer, final String traceRuntimeVersion) { - final Path fileName = generateOutputFileName(traceRuntimeVersion); - tracer.writeToFile(fileName); - return fileName.toAbsolutePath().toString(); - } - - private Path generateOutputFileName(final String tracesEngineVersion) { - if (!Files.isDirectory(tracesPath) && !tracesPath.toFile().mkdirs()) { - throw new RuntimeException( - String.format( - "Trace directory '%s' does not exist and could not be made.", - tracesPath.toAbsolutePath())); - } - - return tracesPath.resolve( - Paths.get( - String.format( - "%.10s-%s.traces.%s", - System.currentTimeMillis(), tracesEngineVersion, getFileFormat()))); - } - - private String getFileFormat() { - return "lt"; - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceFile.java b/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceFile.java deleted file mode 100644 index a6248490..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceFile.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.rpc.tracegeneration; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** FileTrace represents an execution trace. */ -public record TraceFile( - @JsonProperty("tracesEngineVersion") String tracesEngineVersion, - @JsonProperty("traceFileName") String traceFileName) {} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceRequestParams.java b/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceRequestParams.java deleted file mode 100644 index ff785de9..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TraceRequestParams.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.rpc.tracegeneration; - -import java.security.InvalidParameterException; - -import net.consensys.linea.zktracer.ZkTracer; - -/** Holds needed parameters for sending an execution trace generation request. */ -@SuppressWarnings("unused") -public record TraceRequestParams(long fromBlock, long toBlock, String runtimeVersion) { - private static final int EXPECTED_PARAMS_SIZE = 3; - - /** - * Parses a list of params to a {@link TraceRequestParams} object. - * - * @param params an array of parameters. - * @return a parsed {@link TraceRequestParams} object.. - */ - public static TraceRequestParams createTraceParams(final Object[] params) { - // validate params size - if (params.length != EXPECTED_PARAMS_SIZE) { - throw new InvalidParameterException( - String.format("Expected %d parameters but got %d", EXPECTED_PARAMS_SIZE, params.length)); - } - - long fromBlock = Long.parseLong(params[0].toString()); - long toBlock = Long.parseLong(params[1].toString()); - String version = params[2].toString(); - - if (!version.equals(getTracerRuntime())) { - throw new InvalidParameterException( - String.format( - "INVALID_TRACES_VERSION: Runtime version is %s, requesting version %s", - getTracerRuntime(), version)); - } - - return new TraceRequestParams(fromBlock, toBlock, version); - } - - private static String getTracerRuntime() { - return ZkTracer.class.getPackage().getSpecificationVersion(); - } -} diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TracesEndpointServicePlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TracesEndpointServicePlugin.java deleted file mode 100644 index b4bb0384..00000000 --- a/sequencer/src/main/java/net/consensys/linea/rpc/tracegeneration/TracesEndpointServicePlugin.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.rpc.tracegeneration; - -import com.google.auto.service.AutoService; -import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.AbstractLineaSharedOptionsPlugin; -import org.hyperledger.besu.plugin.BesuContext; -import org.hyperledger.besu.plugin.BesuPlugin; -import org.hyperledger.besu.plugin.services.RpcEndpointService; - -/** - * Registers RPC endpoints .This class provides an RPC endpoint named - * 'generateConflatedTracesToFileV0' under the 'rollup' namespace. It uses {@link - * GenerateConflatedTracesV0} to generate conflated file traces. This class provides an RPC endpoint - * named 'generateConflatedTracesToFileV0' under the 'rollup' namespace. - */ -@AutoService(BesuPlugin.class) -@Slf4j -public class TracesEndpointServicePlugin extends AbstractLineaSharedOptionsPlugin { - private BesuContext besuContext; - private RpcEndpointService rpcEndpointService; - /** - * Register the RPC service. - * - * @param context the BesuContext to be used. - */ - @Override - public void register(final BesuContext context) { - super.register(context); - besuContext = context; - rpcEndpointService = - context - .getService(RpcEndpointService.class) - .orElseThrow( - () -> - new RuntimeException( - "Failed to obtain RpcEndpointService from the BesuContext.")); - } - - @Override - public void beforeExternalServices() { - super.beforeExternalServices(); - GenerateConflatedTracesV0 method = new GenerateConflatedTracesV0(besuContext); - - createAndRegister(method, rpcEndpointService); - } - - /** - * 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 GenerateConflatedTracesV0 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() {} -} diff --git a/sequencer/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java b/sequencer/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java deleted file mode 100644 index 88d09aa5..00000000 --- a/sequencer/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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.continoustracing; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.matches; -import static org.mockito.Mockito.when; - -import java.nio.file.Path; -import java.util.List; - -import net.consensys.linea.continoustracing.exception.InvalidBlockTraceException; -import net.consensys.linea.continoustracing.exception.TraceVerificationException; -import net.consensys.linea.corset.CorsetValidator; -import net.consensys.linea.zktracer.ZkTracer; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.plugin.data.BlockTraceResult; -import org.hyperledger.besu.plugin.data.TransactionTraceResult; -import org.hyperledger.besu.plugin.services.TraceService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentMatchers; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -public class ContinuousTracerTest { - private static final Hash BLOCK_HASH = - Hash.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000042"); - - private ContinuousTracer continuousTracer; - - @Mock TraceService traceServiceMock; - @Mock CorsetValidator corsetValidatorMock; - @Mock ZkTracer zkTracerMock; - - @BeforeEach - void setUp() { - continuousTracer = new ContinuousTracer(traceServiceMock, corsetValidatorMock); - } - - @Test - void shouldReturnSuccessIfVerificationIsSuccessful() - throws InvalidBlockTraceException, TraceVerificationException { - final List transactionTraceResults = - List.of(TransactionTraceResult.success(Hash.ZERO)); - final BlockTraceResult blockTraceResult = new BlockTraceResult(transactionTraceResults); - when(traceServiceMock.traceBlock(ArgumentMatchers.any(), ArgumentMatchers.any())) - .thenReturn(blockTraceResult); - - when(corsetValidatorMock.validate(ArgumentMatchers.any(), matches("testZkEvmBin"))) - .thenReturn( - new CorsetValidator.Result( - true, Path.of("testTraceFile").toFile(), "testCorsetOutput")); - - when(zkTracerMock.writeToTmpFile()).thenReturn(Path.of("")); - - final CorsetValidator.Result validationResult = - continuousTracer.verifyTraceOfBlock(BLOCK_HASH, "testZkEvmBin", zkTracerMock); - assertThat(validationResult.isValid()).isTrue(); - } - - @Test - void shouldReturnFailureIfVerificationIsNotSuccessful() - throws InvalidBlockTraceException, TraceVerificationException { - final List transactionTraceResults = - List.of(TransactionTraceResult.success(Hash.ZERO)); - final BlockTraceResult blockTraceResult = new BlockTraceResult(transactionTraceResults); - when(traceServiceMock.traceBlock(ArgumentMatchers.any(), ArgumentMatchers.any())) - .thenReturn(blockTraceResult); - - when(zkTracerMock.writeToTmpFile()).thenReturn(Path.of("")); - - when(corsetValidatorMock.validate(ArgumentMatchers.any(), matches("testZkEvmBin"))) - .thenReturn( - new CorsetValidator.Result( - false, Path.of("testTraceFile").toFile(), "testCorsetOutput")); - - final CorsetValidator.Result validationResult = - continuousTracer.verifyTraceOfBlock(BLOCK_HASH, "testZkEvmBin", zkTracerMock); - assertThat(validationResult.isValid()).isFalse(); - } - - @Test - void shouldThrowInvalidBlockTraceExceptionIfTracingHasInternalError() { - final List transactionTraceResults = - List.of(TransactionTraceResult.error(Hash.ZERO, "errorMessage")); - final BlockTraceResult blockTraceResult = new BlockTraceResult(transactionTraceResults); - when(traceServiceMock.traceBlock(ArgumentMatchers.any(), ArgumentMatchers.any())) - .thenReturn(blockTraceResult); - - assertThrows( - InvalidBlockTraceException.class, - () -> continuousTracer.verifyTraceOfBlock(BLOCK_HASH, "testZkEvmBin", new ZkTracer())); - } -}