Skip to content

Commit

Permalink
Update with latest Besu changes
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 committed Feb 3, 2025
1 parent 8111279 commit c204c4c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 387 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
releaseVersion=1.2.0-rc3.2
besuVersion=25.1-delivery45
besuVersion=25.2-bundles
arithmetizationVersion=beta-v1.2.0-rc3
besuArtifactGroup=io.consensys.linea-besu
distributionIdentifier=linea-sequencer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.consensys.linea.metrics.HistogramMetrics;
import net.consensys.linea.plugins.config.LineaL1L2BridgeSharedConfiguration;
import net.consensys.linea.sequencer.txselection.selectors.LineaTransactionSelector;
import org.hyperledger.besu.plugin.data.ProcessableBlockHeader;
import org.hyperledger.besu.plugin.services.BlockchainService;
import org.hyperledger.besu.plugin.services.txselection.BlockTransactionSelectionService;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
Expand Down Expand Up @@ -80,17 +81,7 @@ public PluginTransactionSelector create(final SelectorsStateManager selectorsSta
}

@Override
public void selectPendingTransactions(final BlockTransactionSelectionService blockTransactionSelectionService) {
final var bundles = privateTxPool.getBundles();

for(final var bundle: bundles) {
for(final var pendingTx: bundle) {
if(! blockTransactionSelectionService.evaluatePendingTransaction(pendingTx)) {
blockTransactionSelectionService.rollback();
break;
}
}
blockTransactionSelectionService.commit();
}
}
public void selectPendingTransactions(
final BlockTransactionSelectionService blockTransactionSelectionService,
final ProcessableBlockHeader pendingBlockHeader) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.hyperledger.besu.datatypes.Transaction;
import org.hyperledger.besu.plugin.data.TransactionProcessingResult;
import org.hyperledger.besu.plugin.data.TransactionSelectionResult;
import org.hyperledger.besu.plugin.services.txselection.AbstractPluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.AbstractStatefulPluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.SelectorsStateManager;
import org.hyperledger.besu.plugin.services.txselection.SelectorsStateManager.DuplicableLongState;
import org.hyperledger.besu.plugin.services.txselection.TransactionEvaluationContext;
Expand All @@ -34,7 +34,7 @@
*/
@Slf4j
public class MaxBlockCallDataTransactionSelector
extends AbstractPluginTransactionSelector<DuplicableLongState> {
extends AbstractStatefulPluginTransactionSelector<DuplicableLongState> {

private final int maxBlockCallDataSize;

Expand Down Expand Up @@ -63,7 +63,7 @@ public TransactionSelectionResult evaluateTransactionPreProcessing(
final int transactionCallDataSize = transaction.getPayload().size();

final var selectorState = getWorkingState();
final var stateCumulativeBlockCallDataSize = selectorState.getValue();
final var stateCumulativeBlockCallDataSize = selectorState.get();

final long newCumulativeBlockCallDataSize =
Math.addExact(stateCumulativeBlockCallDataSize, transactionCallDataSize);
Expand All @@ -85,7 +85,7 @@ public TransactionSelectionResult evaluateTransactionPreProcessing(
.addArgument(newCumulativeBlockCallDataSize)
.log();

selectorState.setValue(newCumulativeBlockCallDataSize);
selectorState.set(newCumulativeBlockCallDataSize);

return SELECTED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.hyperledger.besu.datatypes.Transaction;
import org.hyperledger.besu.plugin.data.TransactionProcessingResult;
import org.hyperledger.besu.plugin.data.TransactionSelectionResult;
import org.hyperledger.besu.plugin.services.txselection.AbstractPluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.AbstractStatefulPluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.SelectorsStateManager;
import org.hyperledger.besu.plugin.services.txselection.SelectorsStateManager.DuplicableLongState;
import org.hyperledger.besu.plugin.services.txselection.TransactionEvaluationContext;
Expand All @@ -35,7 +35,8 @@
* configure a max gas per block that is below the limit defined by the protocol.
*/
@Slf4j
public class MaxBlockGasTransactionSelector extends AbstractPluginTransactionSelector<DuplicableLongState> {
public class MaxBlockGasTransactionSelector
extends AbstractStatefulPluginTransactionSelector<DuplicableLongState> {

private final long maxGasPerBlock;

Expand Down Expand Up @@ -76,7 +77,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing(
}

final var selectorState = getWorkingState();
final var stateCumulativeBlockGasUsed = selectorState.getValue();
final var stateCumulativeBlockGasUsed = selectorState.get();

final long newCumulativeBlockGasUsed =
Math.addExact(stateCumulativeBlockGasUsed, gasUsedByTransaction);
Expand All @@ -93,7 +94,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing(
return TX_TOO_LARGE_FOR_REMAINING_USER_GAS;
}

selectorState.setValue(newCumulativeBlockGasUsed);
selectorState.set(newCumulativeBlockGasUsed);

return SELECTED;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.hyperledger.besu.plugin.data.TransactionSelectionResult.SELECTED;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
Expand All @@ -44,7 +43,7 @@
import org.hyperledger.besu.plugin.data.TransactionProcessingResult;
import org.hyperledger.besu.plugin.data.TransactionSelectionResult;
import org.hyperledger.besu.plugin.services.tracer.BlockAwareOperationTracer;
import org.hyperledger.besu.plugin.services.txselection.AbstractPluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.AbstractStatefulPluginTransactionSelector;
import org.hyperledger.besu.plugin.services.txselection.SelectorsStateManager;
import org.hyperledger.besu.plugin.services.txselection.SelectorsStateManager.DuplicableState;
import org.hyperledger.besu.plugin.services.txselection.TransactionEvaluationContext;
Expand All @@ -58,8 +57,8 @@
*/
@Slf4j
public class TraceLineLimitTransactionSelector
extends AbstractPluginTransactionSelector<
TraceLineLimitTransactionSelector.DuplicableLineLimitMap> {
extends AbstractStatefulPluginTransactionSelector<
TraceLineLimitTransactionSelector.DuplicableLineLimitMap> {
private static final Marker BLOCK_LINE_COUNT_MARKER = MarkerFactory.getMarker("BLOCK_LINE_COUNT");
@VisibleForTesting protected static Set<Hash> overLineCountLimitCache = new LinkedHashSet<>();
private final ZkTracer zkTracer;
Expand Down Expand Up @@ -145,7 +144,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing(
final TransactionProcessingResult processingResult) {

final var selectorState = getWorkingState();
final var stateLineLimitMap = selectorState.getValue();
final var stateLineLimitMap = selectorState.get();

// check that we are not exceeding line number for any module
final Map<String, Integer> currCumulatedLineCount = zkTracer.getModulesLineCount();
Expand Down Expand Up @@ -186,7 +185,7 @@ public TransactionSelectionResult evaluateTransactionPostProcessing(
break;
}

selectorState.setValue(currCumulatedLineCount);
selectorState.set(currCumulatedLineCount);

return SELECTED;
}
Expand Down Expand Up @@ -243,7 +242,7 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo
.addKeyValue(
"traceCounts",
() ->
getConfirmedState().getValue().entrySet().stream()
getCommitedState().get().entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(e -> '"' + e.getKey() + "\":" + e.getValue())
.collect(Collectors.joining(",")))
Expand All @@ -259,7 +258,7 @@ public DuplicableLineLimitMap(final Map<String, Integer> map) {

@Override
protected DuplicableState<Map<String, Integer>> deepCopy() {
return new DuplicableLineLimitMap(Map.copyOf(getValue()));
return new DuplicableLineLimitMap(Map.copyOf(get()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,54 +46,46 @@ public void initialize() {
selectorsStateManager = new SelectorsStateManager();
transactionSelector =
new MaxBlockCallDataTransactionSelector(selectorsStateManager, BLOCK_CALL_DATA_MAX_SIZE);
selectorsStateManager.blockSelectionStarted();
}

@Test
public void shouldSelectTransactionWhen_BlockCallDataSize_IsLessThan_MaxBlockCallDataSize() {
final var evaluationContext1 = mockTransactionOfCallDataSize(BLOCK_CALL_DATA_HALF_SIZE);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext1, SELECTED);

final var evaluationContext2 = mockTransactionOfCallDataSize(BLOCK_CALL_DATA_HALF_SIZE - 1);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext2, SELECTED);
}

@Test
public void shouldSelectTransactionWhen_BlockCallDataSize_IsEqualTo_MaxBlockCallDataSize() {
final var evaluationContext1 = mockTransactionOfCallDataSize(BLOCK_CALL_DATA_HALF_SIZE);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext1, SELECTED);

final var evaluationContext2 = mockTransactionOfCallDataSize(BLOCK_CALL_DATA_HALF_SIZE);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext2, SELECTED);
}

@Test
public void
shouldNotSelectTransactionWhen_BlockCallDataSize_IsGreaterThan_MaxBlockCallDataSize() {
final var evaluationContext1 = mockTransactionOfCallDataSize(BLOCK_CALL_DATA_HALF_SIZE);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext1, SELECTED);

final var evaluationContext2 = mockTransactionOfCallDataSize(BLOCK_CALL_DATA_HALF_SIZE + 1);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext2, BLOCK_CALLDATA_OVERFLOW);
}

@Test
public void shouldNotSelectAdditionalTransactionOnceBlockIsFull() {
final var evaluationContext1 = mockTransactionOfCallDataSize(TX_CALL_DATA_SIZE);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext1, SELECTED);

final var evaluationContext2 = mockTransactionOfCallDataSize(TX_CALL_DATA_SIZE);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext2, BLOCK_CALLDATA_OVERFLOW);

final var evaluationContext3 = mockTransactionOfCallDataSize(TX_CALL_DATA_SIZE);
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(transactionSelector, evaluationContext3, BLOCK_CALLDATA_OVERFLOW);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public void initialize() {
selectorsStateManager = new SelectorsStateManager();
transactionSelector =
new MaxBlockGasTransactionSelector(selectorsStateManager, MAX_GAS_PER_BLOCK);
selectorsStateManager.blockSelectionStarted();
}

@Test
public void shouldSelectWhen_GasUsedByTransaction_IsLessThan_MaxGasPerBlock() {
final var mockTransactionProcessingResult =
mockTransactionProcessingResult(MAX_GAS_PER_BLOCK - 1);
final var evaluationContext = mockEvaluationContext();
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(
transactionSelector, evaluationContext, mockTransactionProcessingResult, SELECTED);
}
Expand All @@ -62,7 +62,6 @@ public void shouldSelectWhen_GasUsedByTransaction_IsLessThan_MaxGasPerBlock() {
public void shouldSelectWhen_GasUsedByTransaction_IsEqual_MaxGasPerBlock() {
final var mockTransactionProcessingResult = mockTransactionProcessingResult(MAX_GAS_PER_BLOCK);
final var evaluationContext = mockEvaluationContext();
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(
transactionSelector, evaluationContext, mockTransactionProcessingResult, SELECTED);
}
Expand All @@ -72,7 +71,6 @@ public void shouldNotSelectWhen_GasUsedByTransaction_IsGreaterThan_MaxGasPerBloc
final var mockTransactionProcessingResult =
mockTransactionProcessingResult(MAX_GAS_PER_BLOCK + 1);
final var evaluationContext = mockEvaluationContext();
selectorsStateManager.startNewEvaluation();
verifyTransactionSelection(
transactionSelector,
evaluationContext,
Expand All @@ -83,7 +81,6 @@ public void shouldNotSelectWhen_GasUsedByTransaction_IsGreaterThan_MaxGasPerBloc
@Test
public void shouldNotSelectWhen_CumulativeGasUsed_IsGreaterThan_MaxGasPerBlock() {
final var evaluationContext1 = mockEvaluationContext();
selectorsStateManager.startNewEvaluation();

// block empty, transaction 80% max gas, should select
verifyTransactionSelection(
Expand All @@ -93,7 +90,6 @@ public void shouldNotSelectWhen_CumulativeGasUsed_IsGreaterThan_MaxGasPerBlock()
SELECTED);

final var evaluationContext2 = mockEvaluationContext();
selectorsStateManager.startNewEvaluation();

// block 80% full, transaction 80% max gas, should not select
verifyTransactionSelection(
Expand All @@ -103,7 +99,6 @@ public void shouldNotSelectWhen_CumulativeGasUsed_IsGreaterThan_MaxGasPerBlock()
TX_TOO_LARGE_FOR_REMAINING_USER_GAS);

final var evaluationContext3 = mockEvaluationContext();
selectorsStateManager.startNewEvaluation();

// block 80% full, transaction 20% max gas, should select
verifyTransactionSelection(
Expand Down
Loading

0 comments on commit c204c4c

Please sign in to comment.