Skip to content

Commit

Permalink
Upgrade to Java 21
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed Jun 11, 2024
1 parent 412af1d commit 27d1cde
Show file tree
Hide file tree
Showing 49 changed files with 620 additions and 504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class BlockCapturer implements ConflationAwareOperationTracer {
* The {@link Reaper} will collect all the data that will need to be mimicked to replay the block.
*/
private final Reaper reaper = new Reaper();

/**
* This keeps a pointer to the initial state (i.e. ) to be used at the end of tracing to store the
* minimal required information to replay the conflation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
public class Reaper {
/** Collect the reads from the state */
private final StorageReaper storage = new StorageReaper();

/** Collect the addresses read from the state */
private final AddressReaper addresses = new AddressReaper();

/** Collect the blocks within a conflation */
private final List<BlockSnapshot> blocks = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class LineaProfitabilityConfiguration {
/** It is safe to keep this as long, since it will store value <= max_int * 1000 */
private long fixedCostWei;

/** It is safe to keep this as long, since it will store value <= max_int * 1000 */
private long variableCostWei;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
public class CountersEndpointServicePlugin extends AbstractLineaSharedOptionsPlugin {
private BesuContext besuContext;
private RpcEndpointService rpcEndpointService;

/**
* Register the RPC service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public class TracesEndpointServicePlugin extends AbstractLineaSharedOptionsPlugin {
private BesuContext besuContext;
private RpcEndpointService rpcEndpointService;

/**
* Register the RPC service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class BaseBytes implements HighLowBytes {
/** The size in bytes of the high and low sections of the 256-bit block. */
private static final int LOW_HIGH_SIZE = 16;

/**
* The mutable `Bytes32` object that stores the 256-bit block of data. Equals and hashCode must
* only be computed on the numeric value wrapped by this class, so that sets of operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
public class StackedList<E extends ModuleOperation> implements List<E>, StackedContainer {

private final LinkedList<CountedList<E>> lists = new LinkedList<>();

/** The cached number of elements in this container */
private int totalSize;

Expand Down Expand Up @@ -239,8 +240,10 @@ public List<E> subList(int fromIndex, int toIndex) {
private static class StackedListIterator<F extends ModuleOperation>
implements Iterator<F>, ListIterator<F> {
private final StackedList<F> sl;

/** Position of the iterator in the list of lists */
private int head = 0;

/** Position of the iterator within the current list, i.e. this.sl.lists[head] */
private int offset = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class EcDataOperation extends ModuleOperation {

private final int ecType;
private final int nRows;

/** -1 if no switch off (i.e. preliminary checks passed) */
private int hurdleSwitchOffRow;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ public static AbstractExtCalculator create(OpCode opCode) {
return switch (opCode) {
case MULMOD -> new MulModCalculator();
case ADDMOD -> new AddModCalculator();
default -> throw new RuntimeException(
"Incompatible instruction for extended modular arithmetic module");
default ->
throw new RuntimeException(
"Incompatible instruction for extended modular arithmetic module");
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class Bytecode {

/** The bytecode. */
private final Bytes bytecode;

/** The bytecode hash; is null by default and computed & memoized on the fly when required. */
private Hash hash;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void reset() {
public boolean stackException() {
return this.stackUnderflow() || this.stackOverflow();
}

/**
* @return true if no stack exception has been raised
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,26 +957,29 @@ void traceOperation(MessageFrame frame) {

switch (this.opCodeData().instructionFamily()) {
case ADD,
MOD,
MUL,
SHF,
BIN,
WCP,
EXT,
BATCH,
MACHINE_STATE,
PUSH_POP,
DUP,
SWAP,
HALT,
INVALID -> this.addTraceSection(new StackOnlySection(this));
MOD,
MUL,
SHF,
BIN,
WCP,
EXT,
BATCH,
MACHINE_STATE,
PUSH_POP,
DUP,
SWAP,
HALT,
INVALID ->
this.addTraceSection(new StackOnlySection(this));
case KEC -> {
this.addTraceSection(
new KeccakSection(this, this.currentFrame(), new MiscFragment(this, frame)));
}
case CONTEXT, LOG -> this.addTraceSection(
new ContextLogSection(
this, new ContextFragment(this.callStack, this.currentFrame(), updateReturnData)));
case CONTEXT, LOG ->
this.addTraceSection(
new ContextLogSection(
this,
new ContextFragment(this.callStack, this.currentFrame(), updateReturnData)));
case ACCOUNT -> {
TraceSection accountSection = new AccountSection(this);
if (this.opCodeData().stackSettings().flag1()) {
Expand Down Expand Up @@ -1034,17 +1037,18 @@ void traceOperation(MessageFrame frame) {
}
this.addTraceSection(copySection);
}
case TRANSACTION -> this.addTraceSection(
new TransactionSection(
this,
TransactionFragment.prepare(
this.conflation.number(),
frame.getMiningBeneficiary(),
this.tx.transaction(),
true,
frame.getGasPrice(),
frame.getBlockValues().getBaseFee().orElse(Wei.ZERO),
this.tx.initialGas())));
case TRANSACTION ->
this.addTraceSection(
new TransactionSection(
this,
TransactionFragment.prepare(
this.conflation.number(),
frame.getMiningBeneficiary(),
this.tx.transaction(),
true,
frame.getGasPrice(),
frame.getBlockValues().getBaseFee().orElse(Wei.ZERO),
this.tx.initialGas())));
case STACK_RAM -> {
switch (this.currentFrame().opCode()) {
case CALLDATALOAD -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
@Accessors(fluent = true)
public class PlatformController {
private final Hub hub;

/** What other modules should be triggered for the current operation */
@Getter private final Signals signals;

/** The exceptions raised during the execution of the current operation */
@Getter private final Exceptions exceptions;

/** The aborting conditions raised during the execution of the current operation */
@Getter private final AbortingConditions aborts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class TxTrace {
/** The {@link TraceSection} of which this transaction trace is made of */
@Getter private final List<TraceSection> trace = new ArrayList<>();

/** A cache for the line count of this transaction */
private int cachedLineCount = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
public class DeferRegistry {
/** A list of actions deferred until the end of the current transaction */
private final List<PostTransactionDefer> txDefers = new ArrayList<>();

/** A list of actions deferred until the end of the current opcode execution */
private final List<PostExecDefer> postExecDefers = new ArrayList<>();

/** A list of actions deferred until the end of the current opcode execution */
private final List<Pair<Integer, NextContextDefer>> contextReentry = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ private StackFragment(
switch (this.opCode) {
case SHA3 -> exceptions.none() && gp.messageSize() > 0;
case RETURN -> exceptions.none() && gp.messageSize() > 0 && isDeploying;
case CREATE2 -> exceptions.none()
&& contextExceptions.none()
&& aborts.none()
&& gp.messageSize() > 0;
case CREATE2 ->
exceptions.none()
&& contextExceptions.none()
&& aborts.none()
&& gp.messageSize() > 0;
default -> false;
};
this.hashInfoSize = this.hashInfoFlag ? gp.messageSize() : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public Trace trace(Trace trace) {

/** Count the stack lines */
@Getter private int stackRowsCounter;

/** Count the non-stack lines */
private int nonStackRowsCounter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class L2Block implements Module {

/** The byte size of the RLP-encoded transaction of the conflation */
@Getter private final Deque<Integer> sizesRlpEncodedTxs = new ArrayDeque<>();

/** The byte size of the L2->L1 logs messages of the conflation */
@Getter private final Deque<List<Integer>> l2l1LogSizes = new ArrayDeque<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public void tracePreOpcode(MessageFrame frame) {
long dataByteLength = 0;
switch (opCode) {
case CALL, CALLCODE -> dataByteLength = Words.clampedToLong(frame.getStackItem(4));
case DELEGATECALL, STATICCALL -> dataByteLength =
Words.clampedToLong(frame.getStackItem(3));
case DELEGATECALL, STATICCALL ->
dataByteLength = Words.clampedToLong(frame.getStackItem(3));
}

if (dataByteLength == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public void tracePreOpcode(MessageFrame frame) {
long dataByteLength = 0;
switch (opCode) {
case CALL, CALLCODE -> dataByteLength = Words.clampedToLong(frame.getStackItem(4));
case DELEGATECALL, STATICCALL -> dataByteLength =
Words.clampedToLong(frame.getStackItem(3));
case DELEGATECALL, STATICCALL ->
dataByteLength = Words.clampedToLong(frame.getStackItem(3));
}
if (dataByteLength == 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ public void traceLog(
.dataLo(topic4.slice(16, 16).toUnsignedBigInteger())
.validateRow();
}
default -> throw new IllegalArgumentException(
"ct = " + ct + " greater than ctMax =" + ctMax);
default ->
throw new IllegalArgumentException("ct = " + ct + " greater than ctMax =" + ctMax);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public MicroData dispatch(
microData.microOp(MmuTrace.FullStackToRam);
}
}
default -> throw new IllegalArgumentException(
"Opcode %s is not supported for type 1 pre-computation".formatted(opCode));
default ->
throw new IllegalArgumentException(
"Opcode %s is not supported for type 1 pre-computation".formatted(opCode));
}

return microData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ public MicroData preProcess(final MicroData microData, final CallStack callStack
microData.exoIsRom(true);
microData.exoIsHash(true);
}
default -> throw new UnsupportedOperationException(
"OpCode.%s is not supported for MMU type 3 pre-processing."
.formatted(microData.opCode()));
default ->
throw new UnsupportedOperationException(
"OpCode.%s is not supported for MMU type 3 pre-processing."
.formatted(microData.opCode()));
}

return microData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,10 @@ void setContext(final boolean isMicro, MicroData microData, final CallStack call

microData.sourceContext(0);
}
default -> throw new UnsupportedOperationException(
"OpCode.%s is not supported for MMU type 4 pre-processing and/or processing"
.formatted(microData.opCode()));
default ->
throw new UnsupportedOperationException(
"OpCode.%s is not supported for MMU type 4 pre-processing and/or processing"
.formatted(microData.opCode()));
}
}

Expand Down Expand Up @@ -475,8 +476,9 @@ private int calculateReferenceSize(final MicroData microData, final CallStack ca
}
case CALLDATACOPY -> callStack.caller().callDataRange().length();
case RETURNDATACOPY -> topCallFrame.returnDataRange().length();
default -> throw new IllegalArgumentException(
"OpCode.%s not supported for type 4 reference size calculation.".formatted(opCode));
default ->
throw new IllegalArgumentException(
"OpCode.%s not supported for type 4 reference size calculation.".formatted(opCode));
}

return 0;
Expand Down Expand Up @@ -553,9 +555,10 @@ private int calculateReferenceOffset(final MicroData microData, final CallStack
case CODECOPY, EXTCODECOPY -> 0;
case CALLDATACOPY -> callStack.caller().callDataRange().absolute().toInt();
case RETURNDATACOPY -> callStack.current().returnDataRange().absolute().toInt();
default -> throw new IllegalArgumentException(
"OpCode.%s not supported for type 4 reference offset calculation"
.formatted(microData.opCode()));
default ->
throw new IllegalArgumentException(
"OpCode.%s not supported for type 4 reference offset calculation"
.formatted(microData.opCode()));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ private void updateOffsetType5(MicroData microData, final CallStack callStack) {
case 2 -> microData.sourceLimbOffset(acc3.add(1));
case 1 -> microData.sourceLimbOffset(acc3.add(2));
case 0 -> microData.sourceLimbOffset(EWord.ZERO);
default -> throw new IllegalStateException(
"Unexpected value: %s".formatted(microData.remainingReads()));
default ->
throw new IllegalStateException(
"Unexpected value: %s".formatted(microData.remainingReads()));
}
} else {
if (!microData.isLastRead()) {
Expand Down Expand Up @@ -210,8 +211,9 @@ private void updateMicroOpType5(MicroData microData, final CallStack callStack)
}
}
}
default -> throw new IllegalStateException(
"Unexpected value: %s".formatted(microData.remainingReads()));
default ->
throw new IllegalStateException(
"Unexpected value: %s".formatted(microData.remainingReads()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@RequiredArgsConstructor
public class Mul implements Module {
private final Hub hub;

/** A set of the operations to trace */
private final StackedSet<MulOperation> operations = new StackedSet<>();

Expand Down
Loading

0 comments on commit 27d1cde

Please sign in to comment.