Interface TransactionPrioritizer
- All Superinterfaces:
Comparator<Transaction>
- All Known Implementing Classes:
FeeBasedPrioritizer,TimestampBasedPrioritizer
Implement this interface to control which transactions are selected first when a miner assembles the next block. The built-in implementations are:
FeeBasedPrioritizer— highest fee-per-byte first (FR-MEMPOOL-03)TimestampBasedPrioritizer— oldest submitted first (FIFO)
The interface extends Comparator<Transaction> so that
implementations can be used directly with Java's standard collection utilities
(e.g., PriorityQueue).
A positive return value from compare(com.privatechain.core.model.Transaction, com.privatechain.core.model.Transaction) means the first transaction
has lower priority than the second (consistent with min-heap ordering
in PriorityQueue, where the head is the least element).
// Example: always prefer transactions from a VIP address
public class VipPrioritizer implements TransactionPrioritizer {
\@Override
public int compare(Transaction a, Transaction b) {
boolean aVip = VIP_SET.contains(a.getSenderAddress());
boolean bVip = VIP_SET.contains(b.getSenderAddress());
if (aVip && !bVip) return -1; // a has higher priority
if (!aVip && bVip) return 1;
return a.getTimestamp().compareTo(b.getTimestamp());
}
}
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionintcompare(Transaction t1, Transaction t2) Compares two transactions to determine their relative priority.Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Method Details
-
compare
Compares two transactions to determine their relative priority.Implementations must be consistent, transitive, and free of side effects. A return value of
-1(or any negative number) meanst1should be selected beforet2;+1(or positive) meanst2first;0means equal priority.- Specified by:
comparein interfaceComparator<Transaction>- Parameters:
t1- the first transaction (non-null)t2- the second transaction (non-null)- Returns:
- negative if
t1has higher priority, positive ift2does, zero if equal priority
-