Skip to content

Commit

Permalink
Create release 0.1.4-test30
Browse files Browse the repository at this point in the history
Signed-off-by: Ameziane H <[email protected]>
  • Loading branch information
ahamlat committed Jul 24, 2024
1 parent 48d3726 commit fc3b932
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 54 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.1.4-test30
Test pre-release 30 from branch `release-v0.1.4-testX` with code ported from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* Improve ZkTracer initialization time [#11](https://github.com/Consensys/linea-sequencer/pull/11) (This PR was removed by error in 0.1.4-test29)
* Parallelize refundedGas for big transactions [linea-arithmetization#793](https://github.com/Consensys/linea-arithmetization/pull/793)


## 0.1.4-test29
Test pre-release 29 from branch `release-v0.1.4-testX` with code ported from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* Implement linea_setExtraData [#19](https://github.com/Consensys/linea-sequencer/pull/19)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.auto.service.AutoService;
import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.corset.CorsetValidator;
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.BesuEvents;
Expand Down Expand Up @@ -97,8 +96,6 @@ public void start() {
System.exit(1);
}

OpCodes.load(); // must be loaded explicitly

besuEvents.addBlockAddedListener(
new ContinuousTracingBlockAddedListener(
new ContinuousTracer(traceService, new CorsetValidator()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.auto.service.AutoService;
import lombok.extern.slf4j.Slf4j;
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;
Expand Down Expand Up @@ -63,10 +62,4 @@ private void createAndRegister(
rpcEndpointService.registerRPCEndpoint(
method.getNamespace(), method.getName(), method::execute);
}

/** Start the RPC service. This method loads the OpCodes. */
@Override
public void start() {
OpCodes.load();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.google.auto.service.AutoService;
import net.consensys.linea.AbstractLineaSharedOptionsPlugin;
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;
Expand Down Expand Up @@ -70,10 +69,4 @@ private void createAndRegister(
rpcEndpointService.registerRPCEndpoint(
method.getNamespace(), method.getName(), method::execute);
}

/** Start the RPC service. This method loads the OpCodes. */
@Override
public void start() {
OpCodes.load();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.auto.service.AutoService;
import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.AbstractLineaSharedOptionsPlugin;
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;
Expand Down Expand Up @@ -72,10 +71,4 @@ private void createAndRegister(
rpcEndpointService.registerRPCEndpoint(
method.getNamespace(), method.getName(), method::execute);
}

/** Start the RPC service. This method loads the OpCodes. */
@Override
public void start() {
OpCodes.load();
}
}
43 changes: 20 additions & 23 deletions sequencer/src/main/java/net/consensys/linea/zktracer/ZkTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
import net.consensys.linea.config.LineaL1L2BridgeConfiguration;
import net.consensys.linea.zktracer.module.Module;
import net.consensys.linea.zktracer.module.hub.Hub;
import net.consensys.linea.zktracer.opcode.OpCodes;
import net.consensys.linea.zktracer.types.Utils;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.toml.Toml;
import org.apache.tuweni.toml.TomlTable;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.PendingTransaction;
Expand All @@ -56,8 +54,21 @@ public class ZkTracer implements ConflationAwareOperationTracer {
/** The {@link GasCalculator} used in this version of the arithmetization */
public static final GasCalculator gasCalculator = new LondonGasCalculator();

private static final Map<String, Integer> spillings;

static {
try {
// Load spillings configured in src/main/resources/spillings.toml.
spillings = Utils.computeSpillings();
} catch (final Exception e) {
final String errorMsg =
"A problem happened during spillings initialization, cause " + e.getCause();
log.error(errorMsg);
throw new RuntimeException(e);
}
}

@Getter private final Hub hub;
private final Map<String, Integer> spillings = new HashMap<>();
private Hash hashOfLastTransactionTraced = Hash.EMPTY;

public ZkTracer() {
Expand All @@ -66,25 +77,11 @@ public ZkTracer() {

public ZkTracer(final LineaL1L2BridgeConfiguration bridgeConfiguration) {
this.hub = new Hub(bridgeConfiguration.contract(), bridgeConfiguration.topic());

// Load opcodes configured in src/main/resources/opcodes.yml.
OpCodes.load();

// Load spillings configured in src/main/resources/spillings.toml.
try {
final TomlTable table =
Toml.parse(getClass().getClassLoader().getResourceAsStream("spillings.toml"))
.getTable("spillings");
table.toMap().keySet().forEach(k -> spillings.put(k, Math.toIntExact(table.getLong(k))));

for (Module m : this.hub.getModulesToCount()) {
if (!this.spillings.containsKey(m.moduleKey())) {
throw new IllegalStateException(
"Spilling for module " + m.moduleKey() + " not defined in spillings.toml");
}
for (Module m : this.hub.getModulesToCount()) {
if (!spillings.containsKey(m.moduleKey())) {
throw new IllegalStateException(
"Spilling for module " + m.moduleKey() + " not defined in spillings.toml");
}
} catch (final Exception e) {
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -234,7 +231,7 @@ public Map<String, Integer> getModulesLineCount() {
modulesLineCount.put(
m.moduleKey(),
m.lineCount()
+ Optional.ofNullable(this.spillings.get(m.moduleKey()))
+ Optional.ofNullable(spillings.get(m.moduleKey()))
.orElseThrow(
() ->
new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class TxTrace {
/** A cache for the line count of this transaction */
private int cachedLineCount = 0;

private long refundedGas = -1;
private static final int PARALLELIZATION_THRESHOLD = 10_000;

public int size() {
return this.trace.size();
}
Expand Down Expand Up @@ -67,13 +70,22 @@ public void add(TraceSection section) {
}

public long refundedGas() {
long refundedGas = 0;
for (TraceSection section : this.trace) {
if (!section.hasReverted()) {
refundedGas += section.refundDelta();
if (this.trace.size() >= PARALLELIZATION_THRESHOLD) {
return this.trace.parallelStream()
.filter(section -> !section.hasReverted())
.mapToLong(TraceSection::refundDelta)
.sum();
} else {
if (this.refundedGas == -1) {
this.refundedGas = 0;
for (TraceSection section : this.trace) {
if (!section.hasReverted()) {
this.refundedGas += section.refundDelta();
}
}
}
return this.refundedGas;
}
return refundedGas;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ public class OpCodes {
private static Map<Integer, OpCodeData> valueToOpCodeDataMap;
private static Map<OpCode, OpCodeData> opCodeToOpCodeDataMap;

/** Loads all opcode metadata from src/main/resources/opcodes.yml. */
static {
/** Loads all opcode metadata from src/main/resources/opcodes.yml. */
init();
}

@SneakyThrows(IOException.class)
public static void load() {
private static void init() {
JsonNode rootNode =
YAML_CONVERTER
.getObjectMapper()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@

package net.consensys.linea.zktracer.types;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.google.common.base.Preconditions;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.toml.Toml;
import org.apache.tuweni.toml.TomlTable;

public class Utils {

Expand Down Expand Up @@ -83,4 +88,15 @@ public static BitDecOutput bitDecomposition(int input, int nbStep) {
}
return output;
}

public static Map<String, Integer> computeSpillings() throws IOException {
final Map<String, Integer> spillings = new HashMap<>();

final TomlTable table =
Toml.parse(Utils.class.getClassLoader().getResourceAsStream("spillings.toml"))
.getTable("spillings");
table.toMap().keySet().forEach(k -> spillings.put(k, Math.toIntExact(table.getLong(k))));

return spillings;
}
}

0 comments on commit fc3b932

Please sign in to comment.