Class TimestampBasedPrioritizer

java.lang.Object
com.privatechain.core.mempool.TimestampBasedPrioritizer
All Implemented Interfaces:
TransactionPrioritizer, Serializable, Comparator<Transaction>

public final class TimestampBasedPrioritizer extends Object implements TransactionPrioritizer, Serializable
Orders transactions by submission timestamp in ascending order (oldest first / FIFO).

This prioritizer is the default used when no explicit prioritizer is configured via BlockchainConfig.Builder.transactionPrioritizer(TransactionPrioritizer). It favors transactions that have been waiting longest, which provides a fair, predictable ordering suitable for development and testing (FR-MEMPOOL-03).

Ordering contract

  • A transaction with an earlier timestamp sorts before one with a later timestamp (ascending / the lowest timestamp = highest priority in the queue).
  • When two transactions share the same timestamp, their UUID natural order is used as a stable tiebreaker to ensure deterministic sorting.
  • null timestamps are treated as Long.MAX_VALUE (lowest priority), which guards against NPEs from partially-constructed objects.
Since:
1.0.0
See Also:
  • Constructor Details

    • TimestampBasedPrioritizer

      public TimestampBasedPrioritizer()
  • Method Details

    • compare

      public int compare(Transaction t1, Transaction t2)
      Compares two transactions by their submission timestamps.

      Returns a negative integer if t1 should be selected before t2 (i.e., t1 has an earlier timestamp).

      Returns a positive integer if t1 should be selected after t2 (i.e., t1 has a newer timestamp).

      If both transections has a same timestamp then we compare their transections id.

      Returns a negative integer if t1.getId() is less than t2.getId()

      Returns a positive integer if t1.getId() is greater than t2.getId()

      Specified by:
      compare in interface Comparator<Transaction>
      Specified by:
      compare in interface TransactionPrioritizer
      Parameters:
      t1 - the first transaction (non-null)
      t2 - the second transaction (non-null)
      Returns:
      negative if t1 sorts first, positive if t2 sorts first
    • toString

      public String toString()
      Returns a human-readable name for this prioritizer.
      Overrides:
      toString in class Object
      Returns:
      "timestamp-asc"