Skip to content

Commit

Permalink
Don't put NONCE_TOO_LOW transactions into the invalid nonce cache (#6067
Browse files Browse the repository at this point in the history
)

* Don't put NONCE_TOO_LOW transactions into the invalid nonce cache

Signed-off-by: Matthew Whitehead <[email protected]>

* Update unit tests

Signed-off-by: Matthew Whitehead <[email protected]>

* Use list of errors to ignore

Signed-off-by: Matthew Whitehead <[email protected]>

---------

Signed-off-by: Matthew Whitehead <[email protected]>
Signed-off-by: Matt Whitehead <[email protected]>
Signed-off-by: Fabio Di Fabio <[email protected]>
Co-authored-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
matthew1001 and fab-10 authored Oct 31, 2023
1 parent de8ca10 commit 84dee29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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 @@ -277,7 +280,9 @@ private ValidationResult<TransactionInvalidReason> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));

Expand Down

0 comments on commit 84dee29

Please sign in to comment.