Skip to content

Commit

Permalink
Merge branch 'arith-dev' into 1189-fix-ramtolimbsinglesource-doesnt-r…
Browse files Browse the repository at this point in the history
…ead-tbo
  • Loading branch information
OlivierBBB committed Sep 20, 2024
2 parents 6b347e7 + 94d6f26 commit a3560c0
Show file tree
Hide file tree
Showing 44 changed files with 375 additions and 388 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
package net.consensys.linea.zktracer.container.module;

import net.consensys.linea.zktracer.container.ModuleOperation;
import net.consensys.linea.zktracer.container.stacked.StackedList;
import net.consensys.linea.zktracer.container.stacked.ModuleOperationStackedList;
import org.hyperledger.besu.evm.worldstate.WorldView;

/**
* A {@link OperationListModule} is a {@link Module} that contains ordered {@link ModuleOperation}
* where we can keep trace of duplicates.
*/
public interface OperationListModule<E extends ModuleOperation> extends Module {
StackedList<E> operations();
ModuleOperationStackedList<E> operations();

@Override
default void enterTransaction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package net.consensys.linea.zktracer.container.module;

import net.consensys.linea.zktracer.container.ModuleOperation;
import net.consensys.linea.zktracer.container.stacked.StackedSet;
import net.consensys.linea.zktracer.container.stacked.ModuleOperationStackedSet;
import org.hyperledger.besu.evm.worldstate.WorldView;

/**
Expand All @@ -25,7 +25,7 @@
*/
public interface OperationSetModule<E extends ModuleOperation> extends Module {

StackedSet<E> operations();
ModuleOperationStackedSet<E> operations();

@Override
default void enterTransaction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@
* @param <E> the type of elements stored in the set
*/
@Accessors(fluent = true)
public class StackedList<E extends ModuleOperation> {
public class ModuleOperationStackedList<E extends ModuleOperation> {
private final List<E> operationsCommitedToTheConflation;
@Getter private final List<E> operationsInTransaction;
private final CountOnlyOperation lineCounter = new CountOnlyOperation();
private boolean conflationFinished = false;

public StackedList() {
public ModuleOperationStackedList() {
operationsCommitedToTheConflation = new ArrayList<>();
operationsInTransaction = new ArrayList<>();
}

/** Prefer this constructor as we preallocate more needed memory */
public StackedList(
public ModuleOperationStackedList(
final int expectedConflationNumberOperations, final int expectedTransactionNumberOperations) {
operationsCommitedToTheConflation = new ArrayList<>(expectedConflationNumberOperations);
operationsInTransaction = new ArrayList<>(expectedTransactionNumberOperations);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* 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.zktracer.container.stacked;

import java.util.Collection;
import java.util.Set;

import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.experimental.Accessors;
import net.consensys.linea.zktracer.container.ModuleOperation;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Implements a system of pseudo-stacked squashed sets where {@link
* ModuleOperationStackedSet#operationsCommitedToTheConflation()} represents the set of all
* operations since the beginning of the conflation and {@link
* ModuleOperationStackedSet#operationsInTransaction()} represents the operations added by the last
* transaction. We can pop only the operations added by last transaction. The line counting is done
* by a separate {@link CountOnlyOperation}.
*
* @param <E> the type of elements stored in the set
*/
@Accessors(fluent = true)
public class ModuleOperationStackedSet<E extends ModuleOperation> extends StackedSet<E> {
private static final Logger log = LoggerFactory.getLogger(ModuleOperationStackedSet.class);
private final CountOnlyOperation lineCounter = new CountOnlyOperation();
@Getter private boolean conflationFinished = false;

public ModuleOperationStackedSet() {
super();
}

/** Prefer this constructor as we preallocate more needed memory */
public ModuleOperationStackedSet(
final int expectedConflationNumberOperations, final int expectedTransactionNumberOperations) {
super(expectedConflationNumberOperations, expectedTransactionNumberOperations);
}

/**
* Upon entering a new transaction, the set of operations generated by the previous transaction
* {@link ModuleOperationStackedSet#operationsInTransaction()} (which is empty if no such
* transaction exists) is added to the set of committed operations {@link
* ModuleOperationStackedSet#operationsCommitedToTheConflation()}. {@link
* ModuleOperationStackedSet#operationsInTransaction()} is further reset to be empty.
*/
public void enter() {
super.enter();
lineCounter.enter();
}

public void pop() {
super.pop();
lineCounter.pop();
}

public int size() {
return operationsInTransaction().size() + operationsCommitedToTheConflation().size();
}

public int lineCount() {
return lineCounter.lineCount();
}

public Set<E> getAll() {
Preconditions.checkState(conflationFinished, "Conflation not finished");
return operationsCommitedToTheConflation();
}

public boolean isEmpty() {
return size() == 0;
}

public boolean contains(Object o) {
return operationsInTransaction().contains(o) || operationsCommitedToTheConflation().contains(o);
}

public boolean add(E e) {
if (!operationsCommitedToTheConflation().contains(e)) {
final boolean isNew = operationsInTransaction().add(e);
if (isNew) {
lineCounter.add(e.lineCount());
}
return isNew;
} else {
log.trace(
"Operation of type {} was already in operationsCommitedToTheConflation hashset, reference is ",
e.getClass().getName(),
e);
}
return false;
}

public boolean containsAll(@NotNull Collection<?> c) {
for (var x : c) {
if (!contains(x)) {
return false;
}
}
return true;
}

public boolean addAll(@NotNull Collection<? extends E> c) {
boolean r = false;
for (var x : c) {
r |= add(x);
}
return r;
}

public void clear() {
operationsCommitedToTheConflation().clear();
operationsInTransaction().clear();
lineCounter.clear();
}

public void finishConflation() {
conflationFinished = true;
operationsCommitedToTheConflation().addAll(operationsInTransaction());
operationsInTransaction().clear();
lineCounter.enter(); // this is not mandatory but it is more consistent
}
}

This file was deleted.

Loading

0 comments on commit a3560c0

Please sign in to comment.