From 02a2f6bce75d9cd64e95334c37ad5374bef68784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= <38285177+OlivierBBB@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:44:47 +0200 Subject: [PATCH] Provide `chainId` to `createZkTracer(...)` (#93) * fix: provide chainId to createZkTracer(...) * fix: bumped arithmetization version to 0.8.0-rc2 * Make sure chainId is present and positive Signed-off-by: Fabio Di Fabio * Set arithmetizationVersion=0.8.0-rc4 Signed-off-by: Fabio Di Fabio --------- Signed-off-by: Fabio Di Fabio Co-authored-by: Fabio Di Fabio --- gradle.properties | 4 +-- .../linea/AbstractLineaRequiredPlugin.java | 29 ++++++++++++++++++- .../linea/extradata/LineaExtraDataPlugin.java | 9 ------ .../linea/rpc/methods/LineaEstimateGas.java | 6 ++-- .../LineaEstimateGasEndpointPlugin.java | 10 ------- .../LineaTransactionPoolValidatorPlugin.java | 11 +------ .../validators/SimulationValidator.java | 7 +++-- .../LineaTransactionSelectorPlugin.java | 11 +------ .../selectors/LineaTransactionSelector.java | 6 +++- .../TraceLineLimitTransactionSelector.java | 6 +++- .../validators/SimulationValidatorTest.java | 1 + ...TraceLineLimitTransactionSelectorTest.java | 2 ++ 12 files changed, 52 insertions(+), 50 deletions(-) diff --git a/gradle.properties b/gradle.properties index f0e3c8c0..3b1a8781 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -releaseVersion=0.8.0-rc1.1 +releaseVersion=0.8.0-rc4.1 besuVersion=24.10-delivery34 -arithmetizationVersion=0.8.0-rc1 +arithmetizationVersion=0.8.0-rc4 besuArtifactGroup=io.consensys.linea-besu distributionIdentifier=linea-sequencer distributionBaseUrl=https://artifacts.consensys.net/public/linea-besu/raw/names/linea-besu.tar.gz/versions/ \ No newline at end of file diff --git a/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java b/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java index c3b51351..152dd326 100644 --- a/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/AbstractLineaRequiredPlugin.java @@ -18,9 +18,11 @@ import lombok.extern.slf4j.Slf4j; import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; +import org.hyperledger.besu.plugin.services.BlockchainService; @Slf4j public abstract class AbstractLineaRequiredPlugin extends AbstractLineaPrivateOptionsPlugin { + protected BlockchainService blockchainService; /** * Linea plugins extending this class will halt startup of Besu in case of exception during @@ -34,7 +36,15 @@ public abstract class AbstractLineaRequiredPlugin extends AbstractLineaPrivateOp public void register(final BesuContext context) { super.register(context); try { - log.info("Registering Linea plugin " + this.getClass().getName()); + log.info("Registering Linea plugin {}", this.getClass().getName()); + + blockchainService = + context + .getService(BlockchainService.class) + .orElseThrow( + () -> + new RuntimeException( + "Failed to obtain BlockchainService from the BesuContext.")); doRegister(context); @@ -52,4 +62,21 @@ public void register(final BesuContext context) { * @param context */ public abstract void doRegister(final BesuContext context); + + @Override + public void beforeExternalServices() { + super.beforeExternalServices(); + + blockchainService + .getChainId() + .ifPresentOrElse( + chainId -> { + if (chainId.signum() <= 0) { + throw new IllegalArgumentException("Chain id must be greater than zero."); + } + }, + () -> { + throw new IllegalArgumentException("Chain id required"); + }); + } } diff --git a/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java b/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java index 7fe0aa98..ed100ec3 100644 --- a/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/extradata/LineaExtraDataPlugin.java @@ -23,7 +23,6 @@ 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.BlockchainService; import org.hyperledger.besu.plugin.services.RpcEndpointService; /** This plugin registers handlers that are activated when new blocks are imported */ @@ -33,7 +32,6 @@ public class LineaExtraDataPlugin extends AbstractLineaRequiredPlugin { public static final String NAME = "linea"; private BesuContext besuContext; private RpcEndpointService rpcEndpointService; - private BlockchainService blockchainService; @Override public Optional getName() { @@ -50,13 +48,6 @@ public void doRegister(final BesuContext context) { () -> new RuntimeException( "Failed to obtain RpcEndpointService from the BesuContext.")); - blockchainService = - context - .getService(BlockchainService.class) - .orElseThrow( - () -> - new RuntimeException( - "Failed to obtain BlockchainService from the BesuContext.")); } /** diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/methods/LineaEstimateGas.java b/sequencer/src/main/java/net/consensys/linea/rpc/methods/LineaEstimateGas.java index 34d25066..9e81b72e 100644 --- a/sequencer/src/main/java/net/consensys/linea/rpc/methods/LineaEstimateGas.java +++ b/sequencer/src/main/java/net/consensys/linea/rpc/methods/LineaEstimateGas.java @@ -270,7 +270,7 @@ private Long estimateGasUsed( final var estimateGasTracer = new EstimateGasOperationTracer(); final var chainHeadHeader = blockchainService.getChainHeadHeader(); - final var zkTracer = createZkTracer(chainHeadHeader); + final var zkTracer = createZkTracer(chainHeadHeader, blockchainService.getChainId().get()); final TracerAggregator zkAndGasTracer = TracerAggregator.create(estimateGasTracer, zkTracer); final var chainHeadHash = chainHeadHeader.getBlockHash(); @@ -491,8 +491,8 @@ private Transaction createTransactionForSimulation( return txBuilder.build(); } - private ZkTracer createZkTracer(final BlockHeader chainHeadHeader) { - var zkTracer = new ZkTracer(l1L2BridgeConfiguration); + private ZkTracer createZkTracer(final BlockHeader chainHeadHeader, final BigInteger chainId) { + var zkTracer = new ZkTracer(l1L2BridgeConfiguration, chainId); zkTracer.traceStartConflation(1L); zkTracer.traceStartBlock(chainHeadHeader); return zkTracer; diff --git a/sequencer/src/main/java/net/consensys/linea/rpc/services/LineaEstimateGasEndpointPlugin.java b/sequencer/src/main/java/net/consensys/linea/rpc/services/LineaEstimateGasEndpointPlugin.java index 0ac2f2ed..6d80e523 100644 --- a/sequencer/src/main/java/net/consensys/linea/rpc/services/LineaEstimateGasEndpointPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/rpc/services/LineaEstimateGasEndpointPlugin.java @@ -24,7 +24,6 @@ import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; import org.hyperledger.besu.plugin.services.BesuConfiguration; -import org.hyperledger.besu.plugin.services.BlockchainService; import org.hyperledger.besu.plugin.services.RpcEndpointService; import org.hyperledger.besu.plugin.services.TransactionSimulationService; @@ -35,7 +34,6 @@ public class LineaEstimateGasEndpointPlugin extends AbstractLineaRequiredPlugin private BesuConfiguration besuConfiguration; private RpcEndpointService rpcEndpointService; private TransactionSimulationService transactionSimulationService; - private BlockchainService blockchainService; private LineaEstimateGas lineaEstimateGasMethod; /** @@ -69,14 +67,6 @@ public void doRegister(final BesuContext context) { new RuntimeException( "Failed to obtain TransactionSimulatorService from the BesuContext.")); - blockchainService = - context - .getService(BlockchainService.class) - .orElseThrow( - () -> - new RuntimeException( - "Failed to obtain BlockchainService from the BesuContext.")); - lineaEstimateGasMethod = new LineaEstimateGas( besuConfiguration, transactionSimulationService, blockchainService, rpcEndpointService); diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java index 0db9229f..98c45653 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/LineaTransactionPoolValidatorPlugin.java @@ -34,7 +34,6 @@ import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; import org.hyperledger.besu.plugin.services.BesuConfiguration; -import org.hyperledger.besu.plugin.services.BlockchainService; import org.hyperledger.besu.plugin.services.TransactionPoolValidatorService; import org.hyperledger.besu.plugin.services.TransactionSimulationService; @@ -49,7 +48,6 @@ public class LineaTransactionPoolValidatorPlugin extends AbstractLineaRequiredPlugin { public static final String NAME = "linea"; private BesuConfiguration besuConfiguration; - private BlockchainService blockchainService; private TransactionPoolValidatorService transactionPoolValidatorService; private TransactionSimulationService transactionSimulationService; private Optional rejectedTxJsonRpcManager = Optional.empty(); @@ -69,14 +67,6 @@ public void doRegister(final BesuContext context) { new RuntimeException( "Failed to obtain BesuConfiguration from the BesuContext.")); - blockchainService = - context - .getService(BlockchainService.class) - .orElseThrow( - () -> - new RuntimeException( - "Failed to obtain BlockchainService from the BesuContext.")); - transactionPoolValidatorService = context .getService(TransactionPoolValidatorService.class) @@ -97,6 +87,7 @@ public void doRegister(final BesuContext context) { @Override public void start() { super.start(); + try (Stream lines = Files.lines( Path.of(new File(transactionPoolValidatorConfiguration().denyListPath()).toURI()))) { diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java index c2abbf49..86530ab0 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidator.java @@ -17,6 +17,7 @@ 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; +import java.math.BigInteger; import java.time.Instant; import java.util.List; import java.util.Map; @@ -86,7 +87,7 @@ public Optional validateTransaction( new ModuleLineCountValidator(moduleLineLimitsMap); final var chainHeadHeader = blockchainService.getChainHeadHeader(); - final var zkTracer = createZkTracer(chainHeadHeader); + final var zkTracer = createZkTracer(chainHeadHeader, blockchainService.getChainId().get()); final var maybeSimulationResults = transactionSimulationService.simulate( transaction, chainHeadHeader.getBlockHash(), zkTracer, true); @@ -170,8 +171,8 @@ private void logSimulationResult( .log(); } - private ZkTracer createZkTracer(final BlockHeader chainHeadHeader) { - var zkTracer = new ZkTracer(l1L2BridgeConfiguration); + private ZkTracer createZkTracer(final BlockHeader chainHeadHeader, BigInteger chainId) { + var zkTracer = new ZkTracer(l1L2BridgeConfiguration, chainId); zkTracer.traceStartConflation(1L); zkTracer.traceStartBlock(chainHeadHeader); return zkTracer; diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java index 021758ef..a84754e7 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorPlugin.java @@ -28,7 +28,6 @@ import org.hyperledger.besu.plugin.BesuContext; import org.hyperledger.besu.plugin.BesuPlugin; import org.hyperledger.besu.plugin.services.BesuConfiguration; -import org.hyperledger.besu.plugin.services.BlockchainService; import org.hyperledger.besu.plugin.services.TransactionSelectionService; /** @@ -41,7 +40,6 @@ public class LineaTransactionSelectorPlugin extends AbstractLineaRequiredPlugin { public static final String NAME = "linea"; private TransactionSelectionService transactionSelectionService; - private BlockchainService blockchainService; private Optional rejectedTxJsonRpcManager = Optional.empty(); private BesuConfiguration besuConfiguration; @@ -60,14 +58,6 @@ public void doRegister(final BesuContext context) { new RuntimeException( "Failed to obtain TransactionSelectionService from the BesuContext.")); - blockchainService = - context - .getService(BlockchainService.class) - .orElseThrow( - () -> - new RuntimeException( - "Failed to obtain BlockchainService from the BesuContext.")); - besuConfiguration = context .getService(BesuConfiguration.class) @@ -80,6 +70,7 @@ public void doRegister(final BesuContext context) { @Override public void start() { super.start(); + final LineaTransactionSelectorConfiguration txSelectorConfiguration = transactionSelectorConfiguration(); final LineaRejectedTxReportingConfiguration lineaRejectedTxReportingConfiguration = diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java index 5cc75976..a396b83f 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java @@ -80,7 +80,11 @@ private List createTransactionSelectors( traceLineLimitTransactionSelector = new TraceLineLimitTransactionSelector( - limitsMap, txSelectorConfiguration, l1L2BridgeConfiguration, tracerConfiguration); + blockchainService.getChainId().get(), + limitsMap, + txSelectorConfiguration, + l1L2BridgeConfiguration, + tracerConfiguration); return List.of( new MaxBlockCallDataTransactionSelector(txSelectorConfiguration.maxBlockCallDataSize()), diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelector.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelector.java index 79c857e9..ed7f0675 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelector.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelector.java @@ -19,6 +19,7 @@ import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW_CACHED; import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED; +import java.math.BigInteger; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -56,6 +57,7 @@ public class TraceLineLimitTransactionSelector implements PluginTransactionSelec private static final Marker BLOCK_LINE_COUNT_MARKER = MarkerFactory.getMarker("BLOCK_LINE_COUNT"); @VisibleForTesting protected static Set overLineCountLimitCache = new LinkedHashSet<>(); private final ZkTracer zkTracer; + private final BigInteger chainId; private final String limitFilePath; private final Map moduleLimits; private final int overLimitCacheSize; @@ -63,6 +65,7 @@ public class TraceLineLimitTransactionSelector implements PluginTransactionSelec private Map currCumulatedLineCount; public TraceLineLimitTransactionSelector( + final BigInteger chainId, final Map moduleLimits, final LineaTransactionSelectorConfiguration txSelectorConfiguration, final LineaL1L2BridgeSharedConfiguration l1L2BridgeConfiguration, @@ -72,6 +75,7 @@ public TraceLineLimitTransactionSelector( System.exit(1); } + this.chainId = chainId; this.moduleLimits = moduleLimits; this.limitFilePath = tracerConfiguration.moduleLimitsFilePath(); this.overLimitCacheSize = txSelectorConfiguration.overLinesLimitCacheSize(); @@ -217,7 +221,7 @@ private String logTxLineCount() { private class ZkTracerWithLog extends ZkTracer { public ZkTracerWithLog(final LineaL1L2BridgeSharedConfiguration bridgeConfiguration) { - super(bridgeConfiguration); + super(bridgeConfiguration, chainId); } @Override diff --git a/sequencer/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidatorTest.java b/sequencer/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidatorTest.java index cd1e9ed1..d8f39597 100644 --- a/sequencer/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidatorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/sequencer/txpoolvalidation/validators/SimulationValidatorTest.java @@ -131,6 +131,7 @@ public void initialize(final WireMockRuntimeInfo wmInfo) throws MalformedURLExce final var blockHeader = mock(BlockHeader.class); when(blockHeader.getBaseFee()).thenReturn(Optional.of(BASE_FEE)); when(blockchainService.getChainHeadHeader()).thenReturn(blockHeader); + when(blockchainService.getChainId()).thenReturn(Optional.of(BigInteger.ONE)); final var rejectedTxReportingConf = LineaRejectedTxReportingConfiguration.builder() diff --git a/sequencer/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelectorTest.java b/sequencer/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelectorTest.java index 103eea16..37ae28a6 100644 --- a/sequencer/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelectorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/sequencer/txselection/selectors/TraceLineLimitTransactionSelectorTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; +import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -250,6 +251,7 @@ private class TestableTraceLineLimitTransactionSelector final Map moduleLimits, final int overLimitCacheSize) { super( + BigInteger.ONE, moduleLimits, LineaTransactionSelectorConfiguration.builder() .overLinesLimitCacheSize(overLimitCacheSize)