Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Optimise TransactionPool.addRemoteTransaction #1448

Merged
merged 2 commits into from
May 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,11 +104,11 @@ public ValidationResult<TransactionInvalidReason> addLocalTransaction(
}

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()) {
Expand All @@ -130,13 +128,6 @@ public void addRemoteTransactions(final Collection<Transaction> transactions) {
}
}

// 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);
}
Expand Down