diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index d355e34d24..5429798824 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -81,7 +81,7 @@ pub use crate::{ config::PoolConfig, - ordering::TransactionOrdering, + ordering::{CostOrdering, TransactionOrdering}, traits::{ BestTransactions, OnNewBlockEvent, PoolTransaction, PooledTransaction, PropagateKind, PropagatedTransactions, TransactionOrigin, TransactionPool, diff --git a/crates/transaction-pool/src/ordering.rs b/crates/transaction-pool/src/ordering.rs index f5bf68eb95..b96db09548 100644 --- a/crates/transaction-pool/src/ordering.rs +++ b/crates/transaction-pool/src/ordering.rs @@ -1,5 +1,6 @@ use crate::traits::PoolTransaction; -use std::fmt; +use reth_primitives::U256; +use std::{fmt, marker::PhantomData}; /// Transaction ordering trait to determine the order of transactions. /// @@ -18,3 +19,23 @@ pub trait TransactionOrdering: Send + Sync + 'static { /// Returns the priority score for the given transaction. fn priority(&self, transaction: &Self::Transaction) -> Self::Priority; } + +/// Default ordering for the pool. +/// +/// The transactions are ordered by their cost. The higher the cost, +/// the higher the priority of this transaction is. +#[derive(Debug, Default)] +#[non_exhaustive] +pub struct CostOrdering(PhantomData); + +impl TransactionOrdering for CostOrdering +where + T: PoolTransaction + 'static, +{ + type Priority = U256; + type Transaction = T; + + fn priority(&self, transaction: &Self::Transaction) -> Self::Priority { + transaction.cost() + } +}