Optimise TransactionPool.addRemoteTransaction (#1448)

* Bail out of addRemoteTransactions immediately if we're not in sync instead of after we sort by nonce and begin iterating.

* Don't sort transactions by nonce. This was only required because we previously rejected transactions where the nonce was too high.

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Adrian Sutton 6 years ago committed by GitHub
parent 3d76bdd802
commit 22492c0b8f
  1. 17
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java

@ -33,9 +33,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator;
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;
@ -106,11 +104,11 @@ public class TransactionPool implements BlockAddedObserver {
}
public void addRemoteTransactions(final Collection<Transaction> transactions) {
if (!syncState.isInSync(SYNC_TOLERANCE)) {
return;
}
final Set<Transaction> addedTransactions = new HashSet<>();
for (final Transaction transaction : sortByNonce(transactions)) {
if (!syncState.isInSync(SYNC_TOLERANCE)) {
return;
}
for (final Transaction transaction : transactions) {
final ValidationResult<TransactionInvalidReason> validationResult =
validateTransaction(transaction);
if (validationResult.isValid()) {
@ -130,13 +128,6 @@ public class TransactionPool implements BlockAddedObserver {
}
}
// Sort transactions by nonce to ensure we import sequences of transactions correctly
private List<Transaction> sortByNonce(final Collection<Transaction> transactions) {
final List<Transaction> sortedTransactions = new ArrayList<>(transactions);
sortedTransactions.sort(Comparator.comparing(Transaction::getNonce));
return sortedTransactions;
}
public void addTransactionListener(final PendingTransactionListener listener) {
pendingTransactions.addTransactionListener(listener);
}

Loading…
Cancel
Save