Class FeeBasedPrioritizer

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

public final class FeeBasedPrioritizer extends Object implements TransactionPrioritizer, Serializable
Orders transactions by fee in descending order (highest fee = highest priority).

The fee is derived from the Transaction.getMetadata() map using the key "fee". Transactions that do not carry a fee entry are treated as zero-fee and sorted after all fee-paying transactions (FR-MEMPOOL-03).

Fee extraction

The fee value must be stored in transaction.getMetadata() under the key "fee" as a BigDecimal, BigInteger, Long, Integer, or any Number subtype. String values are also accepted and parsed via BigDecimal(String). Any other type falls back to zero-fee ordering.

Ordering contract

  • Higher fee → lower comparator return value (sorted to head of queue).
  • Equal fees are broken by timestamp ascending (oldest first) for fairness.
  • Equal fees and timestamps are broken by UUID for full stability.

Usage


 // Include fee in transaction metadata before submitting
 tx.getMetadata().put("fee", new BigDecimal("0.001"));

 TransactionMempool mempool = new TransactionMempool(new FeeBasedPrioritizer(), eventBus);
 mempool.submit(tx);
 
Since:
1.0.0
See Also:
  • Field Details

    • FEE_METADATA_KEY

      public static final String FEE_METADATA_KEY
      Metadata key used to extract the transaction fee.
      See Also:
  • Constructor Details

    • FeeBasedPrioritizer

      public FeeBasedPrioritizer()
  • Method Details

    • compare

      public int compare(Transaction t1, Transaction t2)
      Compares two transactions by fee in descending order.

      A negative return value means t1 should be selected before t2 (i.e., t1 has a higher or equal fee).

      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 has higher priority, positive if t2 does
    • toString

      public String toString()
      Returns a human-readable name for this prioritizer.
      Overrides:
      toString in class Object
      Returns:
      "FeeBasedPrioritizer[order=fee-desc]"