Interface TransactionPrioritizer

All Superinterfaces:
Comparator<Transaction>
All Known Implementing Classes:
FeeBasedPrioritizer, TimestampBasedPrioritizer

public interface TransactionPrioritizer extends Comparator<Transaction>
Service Provider Interface (SPI) for ordering transactions in the mempool.

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 Details

    • compare

      int compare(Transaction t1, Transaction t2)
      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) means t1 should be selected before t2; +1 (or positive) means t2 first; 0 means equal priority.

      Specified by:
      compare in interface Comparator<Transaction>
      Parameters:
      t1 - the first transaction (non-null)
      t2 - the second transaction (non-null)
      Returns:
      negative if t1 has higher priority, positive if t2 does, zero if equal priority