From a611f4cfb2273edd47b6a0bbf8b3bfcf109f02d9 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 15 May 2019 10:45:42 +1000 Subject: [PATCH 1/2] Bail out of addRemoteTransactions immediately if we're not in sync instead of after we sort by nonce and begin iterating. --- .../pantheon/ethereum/eth/transactions/TransactionPool.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java index 07fdf82d4d..bce58211a8 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java @@ -106,11 +106,11 @@ public ValidationResult addLocalTransaction( } public void addRemoteTransactions(final Collection transactions) { + if (!syncState.isInSync(SYNC_TOLERANCE)) { + return; + } final Set addedTransactions = new HashSet<>(); for (final Transaction transaction : sortByNonce(transactions)) { - if (!syncState.isInSync(SYNC_TOLERANCE)) { - return; - } final ValidationResult validationResult = validateTransaction(transaction); if (validationResult.isValid()) { From 646aef867874a13179a18dd6ebed253a193111a3 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Wed, 15 May 2019 10:48:25 +1000 Subject: [PATCH 2/2] Don't sort transactions by nonce. This was only required because we previously rejected transactions where the nonce was too high. --- .../ethereum/eth/transactions/TransactionPool.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java index bce58211a8..0954d843c2 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java @@ -33,9 +33,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason; import tech.pegasys.pantheon.ethereum.mainnet.ValidationResult; -import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -110,7 +108,7 @@ public void addRemoteTransactions(final Collection transactions) { return; } final Set addedTransactions = new HashSet<>(); - for (final Transaction transaction : sortByNonce(transactions)) { + for (final Transaction transaction : transactions) { final ValidationResult validationResult = validateTransaction(transaction); if (validationResult.isValid()) { @@ -130,13 +128,6 @@ public void addRemoteTransactions(final Collection transactions) { } } - // Sort transactions by nonce to ensure we import sequences of transactions correctly - private List sortByNonce(final Collection transactions) { - final List sortedTransactions = new ArrayList<>(transactions); - sortedTransactions.sort(Comparator.comparing(Transaction::getNonce)); - return sortedTransactions; - } - public void addTransactionListener(final PendingTransactionListener listener) { pendingTransactions.addTransactionListener(listener); }