Skip to content

Commit

Permalink
Remove LowestInvalidNonceCache
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 Nov 9, 2023
1 parent 701cbb0 commit f8848c6
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public static RpcErrorType convertTransactionInvalidReason(
return RpcErrorType.ETH_SEND_TX_REPLACEMENT_UNDERPRICED;
case NONCE_TOO_FAR_IN_FUTURE_FOR_SENDER:
return RpcErrorType.NONCE_TOO_FAR_IN_FUTURE_FOR_SENDER;
case LOWER_NONCE_INVALID_TRANSACTION_EXISTS:
return RpcErrorType.LOWER_NONCE_INVALID_TRANSACTION_EXISTS;
case TOTAL_BLOB_GAS_TOO_HIGH:
return RpcErrorType.TOTAL_BLOB_GAS_TOO_HIGH;
case TX_POOL_DISABLED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public enum TransactionInvalidReason {
MAX_PRIORITY_FEE_PER_GAS_EXCEEDS_MAX_FEE_PER_GAS,
INITCODE_TOO_LARGE,
NONCE_TOO_FAR_IN_FUTURE_FOR_SENDER,
LOWER_NONCE_INVALID_TRANSACTION_EXISTS,
TOTAL_BLOB_GAS_TOO_HIGH,
GAS_PRICE_TOO_LOW,
GAS_PRICE_BELOW_CURRENT_BASE_FEE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ void manageBlockAdded(

String logStats();

default List<Transaction> signalInvalidAndGetDependentTransactions(
final Transaction transaction) {
// ToDo: remove when the legacy tx pool is removed
return List.of();
}

default void signalInvalidAndRemoveDependentTransactions(final Transaction transaction) {
// ToDo: remove when the legacy tx pool is removed
// no-op
}

@FunctionalInterface
interface TransactionSelector {
TransactionSelectionResult evaluateTransaction(PendingTransaction pendingTransaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ private enum Status {
new TransactionAddedResult(TransactionInvalidReason.TRANSACTION_REPLACEMENT_UNDERPRICED);
public static final TransactionAddedResult NONCE_TOO_FAR_IN_FUTURE_FOR_SENDER =
new TransactionAddedResult(TransactionInvalidReason.NONCE_TOO_FAR_IN_FUTURE_FOR_SENDER);
public static final TransactionAddedResult LOWER_NONCE_INVALID_TRANSACTION_KNOWN =
new TransactionAddedResult(TransactionInvalidReason.LOWER_NONCE_INVALID_TRANSACTION_EXISTS);

public static final TransactionAddedResult ADDED = new TransactionAddedResult(Status.ADDED);
public static final TransactionAddedResult TRY_NEXT_LAYER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.IntSummaryStatistics;
Expand Down Expand Up @@ -94,8 +93,6 @@
public class TransactionPool implements BlockAddedObserver {
private static final Logger LOG = LoggerFactory.getLogger(TransactionPool.class);
private static final Logger LOG_FOR_REPLAY = LoggerFactory.getLogger("LOG_FOR_REPLAY");
private static final List<TransactionInvalidReason> INVALID_TX_CACHE_IGNORED_ERRORS =
new ArrayList<>(Arrays.asList(TransactionInvalidReason.NONCE_TOO_LOW));
private final Supplier<PendingTransactions> pendingTransactionsSupplier;
private final PluginTransactionValidator pluginTransactionValidator;
private volatile PendingTransactions pendingTransactions;
Expand Down Expand Up @@ -280,11 +277,6 @@ private ValidationResult<TransactionInvalidReason> addTransaction(
.log();
metrics.incrementRejected(
isLocal, hasPriority, validationResult.result.getInvalidReason(), "txpool");
if (!isLocal
&& !INVALID_TX_CACHE_IGNORED_ERRORS.contains(
validationResult.result.getInvalidReason())) {
pendingTransactions.signalInvalidAndRemoveDependentTransactions(transaction);
}
}

return validationResult.result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static org.hyperledger.besu.ethereum.eth.transactions.TransactionAddedResult.ADDED;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionAddedResult.ALREADY_KNOWN;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionAddedResult.LOWER_NONCE_INVALID_TRANSACTION_KNOWN;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionAddedResult.NONCE_TOO_FAR_IN_FUTURE_FOR_SENDER;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionAddedResult.REJECTED_UNDERPRICED_REPLACEMENT;

Expand Down Expand Up @@ -69,7 +68,6 @@
* <p>This class is safe for use across multiple threads.
*/
public abstract class AbstractPendingTransactionsSorter implements PendingTransactions {
private static final int DEFAULT_LOWEST_INVALID_KNOWN_NONCE_CACHE = 10_000;
private static final Logger LOG =
LoggerFactory.getLogger(AbstractPendingTransactionsSorter.class);

Expand All @@ -82,8 +80,6 @@ public abstract class AbstractPendingTransactionsSorter implements PendingTransa
protected final Map<Address, PendingTransactionsForSender> transactionsBySender =
new ConcurrentHashMap<>();

protected final LowestInvalidNonceCache lowestInvalidKnownNonceCache =
new LowestInvalidNonceCache(DEFAULT_LOWEST_INVALID_KNOWN_NONCE_CACHE);
protected final Subscribers<PendingTransactionAddedListener> pendingTransactionSubscribers =
Subscribers.create();

Expand Down Expand Up @@ -136,7 +132,6 @@ public AbstractPendingTransactionsSorter(
public void reset() {
pendingTransactions.clear();
transactionsBySender.clear();
lowestInvalidKnownNonceCache.reset();
}

@Override
Expand Down Expand Up @@ -179,21 +174,10 @@ public List<Transaction> getPriorityTransactions() {
public TransactionAddedResult addTransaction(
final PendingTransaction transaction, final Optional<Account> maybeSenderAccount) {

if (!transaction.isReceivedFromLocalSource()
&& lowestInvalidKnownNonceCache.hasInvalidLowerNonce(transaction.getTransaction())) {
LOG.atDebug()
.setMessage(
"Dropping transaction {} since the sender has an invalid transaction with lower nonce")
.addArgument(transaction::toTraceLog)
.log();
return LOWER_NONCE_INVALID_TRANSACTION_KNOWN;
}

final TransactionAddedResult transactionAddedStatus =
internalAddTransaction(transaction, maybeSenderAccount);
if (transactionAddedStatus.equals(ADDED)) {
if (!transaction.isReceivedFromLocalSource()) {
lowestInvalidKnownNonceCache.registerValidTransaction(transaction.getTransaction());
remoteTransactionAddedCounter.inc();
} else {
localTransactionAddedCounter.inc();
Expand Down Expand Up @@ -223,7 +207,6 @@ public void manageBlockAdded(

public void transactionAddedToBlock(final Transaction transaction) {
removeTransaction(transaction, true);
lowestInvalidKnownNonceCache.registerValidTransaction(transaction);
}

private void incrementTransactionRemovedCounter(
Expand Down Expand Up @@ -259,8 +242,6 @@ public void selectTransactions(final TransactionSelector selector) {

if (result.discard()) {
transactionsToRemove.add(transactionToProcess.getTransaction());
transactionsToRemove.addAll(
signalInvalidAndGetDependentTransactions(transactionToProcess.getTransaction()));
}

if (result.stop()) {
Expand Down Expand Up @@ -504,34 +485,4 @@ public String toTraceLog() {
return sb.toString();
}
}

@Override
public List<Transaction> signalInvalidAndGetDependentTransactions(final Transaction transaction) {
final long invalidNonce = lowestInvalidKnownNonceCache.registerInvalidTransaction(transaction);

PendingTransactionsForSender txsForSender = transactionsBySender.get(transaction.getSender());
if (txsForSender != null) {
return txsForSender
.streamPendingTransactions()
.filter(pendingTx -> pendingTx.getTransaction().getNonce() > invalidNonce)
.peek(
pendingTx ->
LOG.atTrace()
.setMessage(
"Transaction {} invalid since there is a lower invalid nonce {} for the sender")
.addArgument(pendingTx::toTraceLog)
.addArgument(invalidNonce)
.log())
.map(PendingTransaction::getTransaction)
.collect(Collectors.toList());
}
return List.of();
}

@Override
public void signalInvalidAndRemoveDependentTransactions(final Transaction transaction) {
synchronized (lock) {
signalInvalidAndGetDependentTransactions(transaction).forEach(this::removeTransaction);
}
}
}

This file was deleted.

0 comments on commit f8848c6

Please sign in to comment.