From 84dee295d9c31b371bf6d68da169129ed5bb5c01 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Tue, 31 Oct 2023 15:12:19 +0000 Subject: [PATCH] Don't put NONCE_TOO_LOW transactions into the invalid nonce cache (#6067) * Don't put NONCE_TOO_LOW transactions into the invalid nonce cache Signed-off-by: Matthew Whitehead * Update unit tests Signed-off-by: Matthew Whitehead * Use list of errors to ignore Signed-off-by: Matthew Whitehead --------- Signed-off-by: Matthew Whitehead Signed-off-by: Matt Whitehead Signed-off-by: Fabio Di Fabio Co-authored-by: Fabio Di Fabio --- .../besu/ethereum/eth/transactions/TransactionPool.java | 7 ++++++- .../sorter/AbstractLegacyTransactionPoolTest.java | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java index c41027deb1b..9e0ca14a284 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java @@ -55,6 +55,7 @@ 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; @@ -93,6 +94,8 @@ 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 INVALID_TX_CACHE_IGNORED_ERRORS = + new ArrayList<>(Arrays.asList(TransactionInvalidReason.NONCE_TOO_LOW)); private final Supplier pendingTransactionsSupplier; private final PluginTransactionValidator pluginTransactionValidator; private volatile PendingTransactions pendingTransactions; @@ -277,7 +280,9 @@ private ValidationResult addTransaction( .log(); metrics.incrementRejected( isLocal, hasPriority, validationResult.result.getInvalidReason(), "txpool"); - if (!isLocal) { + if (!isLocal + && !INVALID_TX_CACHE_IGNORED_ERRORS.contains( + validationResult.result.getInvalidReason())) { pendingTransactions.signalInvalidAndRemoveDependentTransactions(transaction); } } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractLegacyTransactionPoolTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractLegacyTransactionPoolTest.java index 1b35bd26516..46d735f9954 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractLegacyTransactionPoolTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractLegacyTransactionPoolTest.java @@ -16,7 +16,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.singletonList; -import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.NONCE_TOO_LOW; +import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.TRANSACTION_ALREADY_KNOWN; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; @@ -38,7 +38,7 @@ public abstract class AbstractLegacyTransactionPoolTest extends AbstractTransact public void shouldNotAddRemoteTransactionsWhenThereIsALowestInvalidNonceForTheSender() { givenTransactionIsValid(transaction1); when(transactionValidatorFactory.get().validate(eq(transaction0), any(Optional.class), any())) - .thenReturn(ValidationResult.invalid(NONCE_TOO_LOW)); + .thenReturn(ValidationResult.invalid(TRANSACTION_ALREADY_KNOWN)); transactionPool.addRemoteTransactions(asList(transaction0, transaction1));