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 <matthew1001@gmail.com>

* Update unit tests

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>

* Use list of errors to ignore

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>

---------

Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matt Whitehead <matthew1001@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/6110/head
Matt Whitehead 1 year ago committed by GitHub
parent de8ca108a3
commit 84dee295d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java
  2. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractLegacyTransactionPoolTest.java

@ -55,6 +55,7 @@ import java.io.IOException;
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 @@ import org.slf4j.LoggerFactory;
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;
@ -277,7 +280,9 @@ public class TransactionPool implements BlockAddedObserver {
.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);
}
}

@ -16,7 +16,7 @@ package org.hyperledger.besu.ethereum.eth.transactions.sorter;
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));

Loading…
Cancel
Save