Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize High Gas Price Transactions #1449

Merged
merged 6 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
kick out oldest tx with same gas price instead of newest
Signed-off-by: Ratan Rai Sur <[email protected]>
  • Loading branch information
RatanRSur committed Oct 14, 2020
commit 565f5b582acb7a254c7d2b3a268bb18f68297603
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -74,7 +73,7 @@ public class PendingTransactions {
new TreeSet<>(
comparing(TransactionInfo::isReceivedFromLocalSource)
.thenComparing(TransactionInfo::getGasPrice)
.thenComparing(TransactionInfo::getSequence, Comparator.reverseOrder())
.thenComparing(TransactionInfo::getSequence)
.reversed());
private final Map<Address, TransactionsForSenderInfo> transactionsBySender =
new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,15 @@ public void shouldPrioritizeGasPriceThenTimeAddedToPool() {
// Fill the pool
lowGasPriceTransactions.forEach(transactions::addRemoteTransaction);

// This should kick the newest tx with the low gas price out, namely the last one we added
// This should kick the oldest tx with the low gas price out, namely the first one we added
final Transaction highGasPriceTransaction =
transactionWithNonceSenderAndGasPrice(MAX_TRANSACTIONS + 1, KEYS1, 100);
transactions.addRemoteTransaction(highGasPriceTransaction);
assertThat(transactions.size()).isEqualTo(MAX_TRANSACTIONS);

assertTransactionPending(highGasPriceTransaction);
lowGasPriceTransactions.stream()
.limit(MAX_TRANSACTIONS - 1)
.forEach(this::assertTransactionPending);
assertTransactionNotPending(lowGasPriceTransactions.get(lowGasPriceTransactions.size() - 1));
assertTransactionNotPending(lowGasPriceTransactions.get(0));
lowGasPriceTransactions.stream().skip(1).forEach(this::assertTransactionPending);
}

@Test
Expand Down