diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLimitsValidationResult.java b/arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLimitsValidationResult.java index 69728c9b..ba661cf8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLimitsValidationResult.java +++ b/arithmetization/src/main/java/net/consensys/linea/sequencer/modulelimit/ModuleLimitsValidationResult.java @@ -85,4 +85,22 @@ public static ModuleLimitsValidationResult blockModuleLineCountFull( cumulativeModuleLineCount, cumulativeModuleLineLimit); } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(result.name()); + if (moduleName != null) { + sb.append("[module=").append(moduleName); + + if (moduleLineCount != null) { + sb.append(",lineCount=").append(moduleLineCount); + sb.append(",lineLimit=").append(moduleLineLimit); + sb.append(",cumulativeLineCount=").append(cumulativeModuleLineCount); + sb.append(",cumulativeLineLimit=").append(cumulativeModuleLineLimit); + } + + sb.append(']'); + } + return sb.toString(); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java b/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java index 0709f4d9..f1df6623 100644 --- a/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java +++ b/arithmetization/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java @@ -28,6 +28,7 @@ import net.consensys.linea.zktracer.ZkTracer; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.plugin.data.BlockHeader; +import org.hyperledger.besu.plugin.data.TransactionSimulationResult; import org.hyperledger.besu.plugin.services.BlockchainService; import org.hyperledger.besu.plugin.services.TransactionSimulationService; import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionPoolValidator; @@ -62,6 +63,13 @@ public Optional validateTransaction( final boolean isRemoteAndP2pEnabled = !isLocal && txPoolValidatorConf.txPoolSimulationCheckP2pEnabled(); if (isRemoteAndP2pEnabled || isLocalAndApiEnabled) { + log.atTrace() + .setMessage( + "Starting simulation validation for tx with hash={}, isLocal={}, hasPriority={}") + .addArgument(transaction::getHash) + .addArgument(isLocal) + .addArgument(hasPriority) + .log(); final ModuleLineCountValidator moduleLineCountValidator = new ModuleLineCountValidator(moduleLineLimitsMap); @@ -72,34 +80,65 @@ public Optional validateTransaction( transactionSimulationService.simulate( transaction, chainHeadHeader.getBlockHash(), zkTracer, true); - ModuleLimitsValidationResult moduleLimit = + ModuleLimitsValidationResult moduleLimitResult = moduleLineCountValidator.validate(zkTracer.getModulesLineCount()); - if (moduleLimit.getResult() != ModuleLineCountValidator.ModuleLineCountResult.VALID) { - return Optional.of(handleModuleOverLimit(moduleLimit)); + logSimulationResult( + transaction, isLocal, hasPriority, maybeSimulationResults, moduleLimitResult); + + if (moduleLimitResult.getResult() != ModuleLineCountValidator.ModuleLineCountResult.VALID) { + return Optional.of(handleModuleOverLimit(moduleLimitResult)); } if (maybeSimulationResults.isPresent()) { final var simulationResult = maybeSimulationResults.get(); if (simulationResult.isInvalid()) { - return Optional.of( + final String errMsg = "Invalid transaction" - + simulationResult.getInvalidReason().map(ir -> ": " + ir).orElse("")); + + simulationResult.getInvalidReason().map(ir -> ": " + ir).orElse(""); + log.debug(errMsg); + return Optional.of(errMsg); } if (!simulationResult.isSuccessful()) { - return Optional.of( + final String errMsg = "Reverted transaction" + simulationResult .getRevertReason() .map(rr -> ": " + rr.toHexString()) - .orElse("")); + .orElse(""); + log.debug(errMsg); + return Optional.of(errMsg); } } } + log.atTrace() + .setMessage( + "Simulation validation not enabled for tx with hash={}, isLocal={}, hasPriority={}") + .addArgument(transaction::getHash) + .addArgument(isLocal) + .addArgument(hasPriority) + .log(); return Optional.empty(); } + private void logSimulationResult( + final Transaction transaction, + final boolean isLocal, + final boolean hasPriority, + final Optional maybeSimulationResults, + final ModuleLimitsValidationResult moduleLimitResult) { + log.atTrace() + .setMessage( + "Result of simulation validation for tx with hash={}, isLocal={}, hasPriority={}, is {}, module line counts {}") + .addArgument(transaction::getHash) + .addArgument(isLocal) + .addArgument(hasPriority) + .addArgument(maybeSimulationResults) + .addArgument(moduleLimitResult) + .log(); + } + private ZkTracer createZkTracer(final BlockHeader chainHeadHeader) { var zkTracer = new ZkTracer(l1L2BridgeConfiguration); zkTracer.traceStartConflation(1L);