diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 65f541db2..b4b313023 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -41,6 +41,8 @@ public class TxTrace implements PostTransactionDefer { @Getter private long leftoverGas = -1; @Getter private long gasRefundFinalCounter = 0; // TODO: + private static final int PARALLELIZATION_THRESHOLD = 10_000; + public int size() { return this.trace.size(); } @@ -72,16 +74,22 @@ public void add(TraceSection section) { } public long refundedGas() { - if (this.refundedGas == -1) { - this.refundedGas = 0; - for (TraceSection section : this.trace) { - if (!section.hasReverted()) { - this.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 this.refundedGas; } @Override