Skip to content

Commit

Permalink
Sort transactions by priority
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed Sep 27, 2023
1 parent b36a09d commit 67cf062
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public BaseFeePrioritizedTransactions(

@Override
protected int compareByFee(final PendingTransaction pt1, final PendingTransaction pt2) {
return Comparator.comparing(
return Comparator.comparing(PendingTransaction::hasPriority)
.thenComparing(
(PendingTransaction pendingTransaction) ->
pendingTransaction.getTransaction().getEffectivePriorityFeePerGas(nextBlockBaseFee))
.thenComparing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public GasPricePrioritizedTransactions(

@Override
protected int compareByFee(final PendingTransaction pt1, final PendingTransaction pt2) {
return comparing(PendingTransaction::isReceivedFromLocalSource)
return comparing(PendingTransaction::hasPriority)
.thenComparing(PendingTransaction::getGasPrice)
.thenComparing(PendingTransaction::getSequence)
.compare(pt1, pt2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class ReadyTransactions extends AbstractSequentialTransactionsLayer {

private final NavigableSet<PendingTransaction> orderByMaxFee =
new TreeSet<>(
Comparator.comparing((PendingTransaction pt) -> pt.getTransaction().getMaxGasPrice())
Comparator.comparing(PendingTransaction::hasPriority)
.thenComparing((PendingTransaction pt) -> pt.getTransaction().getMaxGasPrice())
.thenComparing(PendingTransaction::getSequence));

public ReadyTransactions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@

public class SparseTransactions extends AbstractTransactionsLayer {
private final NavigableSet<PendingTransaction> sparseEvictionOrder =
new TreeSet<>(Comparator.comparing(PendingTransaction::getSequence));
new TreeSet<>(
Comparator.comparing(PendingTransaction::hasPriority)
.thenComparing(PendingTransaction::getSequence));
private final Map<Address, Integer> gapBySender = new HashMap<>();
private final List<Set<Address>> orderByGap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public BaseFeePendingTransactionsSorter(
*/
private final NavigableSet<PendingTransaction> prioritizedTransactionsStaticRange =
new TreeSet<>(
comparing(PendingTransaction::isReceivedFromLocalSource)
comparing(PendingTransaction::hasPriority)
.thenComparing(
pendingTx ->
pendingTx
Expand All @@ -79,7 +79,7 @@ public BaseFeePendingTransactionsSorter(

private final NavigableSet<PendingTransaction> prioritizedTransactionsDynamicRange =
new TreeSet<>(
comparing(PendingTransaction::isReceivedFromLocalSource)
comparing(PendingTransaction::hasPriority)
.thenComparing(
pendingTx ->
pendingTx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GasPricePendingTransactionsSorter extends AbstractPendingTransactio

private final NavigableSet<PendingTransaction> prioritizedTransactions =
new TreeSet<>(
comparing(PendingTransaction::isReceivedFromLocalSource)
comparing(PendingTransaction::hasPriority)
.thenComparing(PendingTransaction::getGasPrice)
.thenComparing(PendingTransaction::getAddedAt)
.thenComparing(PendingTransaction::getSequence)
Expand Down

0 comments on commit 67cf062

Please sign in to comment.