-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor(transaction-selection): Implement TransactionSelector new me…
…thods (#218) Signed-off-by: Gabriel-Trintinalia <[email protected]>
- Loading branch information
1 parent
df4daf2
commit a01f302
Showing
11 changed files
with
537 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
version=0.0.1-SNAPSHOT | ||
besuVersion=23.7.4-SNAPSHOT | ||
besuVersion=23.10.1-SNAPSHOT | ||
besuArtifactGroup=io.consensys.linea-besu | ||
distributionIdentifier=linea-besu-plugin | ||
distributionBaseUrl=https://artifacts.consensys.net/public/linea-besu/raw/names/linea-besu.tar.gz/versions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
src/main/java/net/consensys/linea/sequencer/LineaTransactionSelector.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...in/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* 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.sequencer.txselection.selectors; | ||
|
||
import java.util.List; | ||
|
||
import net.consensys.linea.sequencer.LineaConfiguration; | ||
import org.hyperledger.besu.datatypes.PendingTransaction; | ||
import org.hyperledger.besu.plugin.data.TransactionProcessingResult; | ||
import org.hyperledger.besu.plugin.data.TransactionSelectionResult; | ||
import org.hyperledger.besu.plugin.services.txselection.TransactionSelector; | ||
|
||
/** Class for transaction selection using a list of selectors. */ | ||
public class LineaTransactionSelector implements TransactionSelector { | ||
|
||
final LineaConfiguration lineaConfiguration; | ||
List<TransactionSelector> selectors; | ||
|
||
public LineaTransactionSelector(LineaConfiguration lineaConfiguration) { | ||
this.lineaConfiguration = lineaConfiguration; | ||
this.selectors = createTransactionSelectors(lineaConfiguration); | ||
} | ||
|
||
/** | ||
* Creates a list of selectors based on Linea configuration. | ||
* | ||
* @param lineaConfiguration The configuration to use. | ||
* @return A list of selectors. | ||
*/ | ||
private static List<TransactionSelector> createTransactionSelectors( | ||
final LineaConfiguration lineaConfiguration) { | ||
return List.of( | ||
new MaxTransactionCallDataTransactionSelector(lineaConfiguration.maxTxCallDataSize()), | ||
new MaxBlockCallDataTransactionSelector(lineaConfiguration.maxBlockCallDataSize())); | ||
} | ||
|
||
/** | ||
* Evaluates a transaction before processing using all selectors. Stops if any selector doesn't | ||
* select the transaction. | ||
* | ||
* @param pendingTransaction The transaction to evaluate. | ||
* @return The first non-SELECTED result or SELECTED if all selectors select the transaction. | ||
*/ | ||
@Override | ||
public TransactionSelectionResult evaluateTransactionPreProcessing( | ||
PendingTransaction pendingTransaction) { | ||
for (var selector : selectors) { | ||
TransactionSelectionResult result = | ||
selector.evaluateTransactionPreProcessing(pendingTransaction); | ||
if (!result.equals(TransactionSelectionResult.SELECTED)) { | ||
return result; | ||
} | ||
} | ||
return TransactionSelectionResult.SELECTED; | ||
} | ||
|
||
/** | ||
* Evaluates a transaction considering its processing result. Stops if any selector doesn't select | ||
* the transaction. | ||
* | ||
* @param pendingTransaction The processed transaction. | ||
* @param processingResult The result of the transaction processing. | ||
* @return The first non-SELECTED result or SELECTED if all selectors select the transaction. | ||
*/ | ||
@Override | ||
public TransactionSelectionResult evaluateTransactionPostProcessing( | ||
PendingTransaction pendingTransaction, TransactionProcessingResult processingResult) { | ||
for (var selector : selectors) { | ||
TransactionSelectionResult result = | ||
selector.evaluateTransactionPostProcessing(pendingTransaction, processingResult); | ||
if (!result.equals(TransactionSelectionResult.SELECTED)) { | ||
return result; | ||
} | ||
} | ||
return TransactionSelectionResult.SELECTED; | ||
} | ||
|
||
/** | ||
* Notifies all selectors when a transaction is selected. | ||
* | ||
* @param pendingTransaction The selected transaction. | ||
*/ | ||
@Override | ||
public void onTransactionSelected(final PendingTransaction pendingTransaction) { | ||
selectors.forEach(selector -> selector.onTransactionSelected(pendingTransaction)); | ||
} | ||
|
||
/** | ||
* Notifies all selectors when a transaction is not selected. | ||
* | ||
* @param pendingTransaction The non-selected transaction. | ||
* @param transactionSelectionResult The reason for not selecting the transaction. | ||
*/ | ||
@Override | ||
public void onTransactionNotSelected( | ||
final PendingTransaction pendingTransaction, | ||
final TransactionSelectionResult transactionSelectionResult) { | ||
selectors.forEach( | ||
selector -> | ||
selector.onTransactionNotSelected(pendingTransaction, transactionSelectionResult)); | ||
} | ||
} |
Oops, something went wrong.