Package com.privatechain.core.mempool
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMetadata key used to extract the transaction fee. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompare(Transaction t1, Transaction t2) Compares two transactions by fee in descending order.toString()Returns a human-readable name for this prioritizer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
FEE_METADATA_KEY
Metadata key used to extract the transaction fee.- See Also:
-
-
Constructor Details
-
FeeBasedPrioritizer
public FeeBasedPrioritizer()
-
-
Method Details
-
compare
Compares two transactions by fee in descending order.A negative return value means
t1should be selected beforet2(i.e.,t1has a higher or equal fee).- Specified by:
comparein interfaceComparator<Transaction>- Specified by:
comparein interfaceTransactionPrioritizer- Parameters:
t1- the first transaction (non-null)t2- the second transaction (non-null)- Returns:
- negative if
t1has higher priority, positive ift2does
-
toString
Returns a human-readable name for this prioritizer.
-