Skip to main content

tempo_transaction_pool/
ordering.rs

1//! Transaction ordering for Tempo's pool.
2
3use reth_transaction_pool::{PoolTransaction, Priority, TransactionOrdering};
4use std::marker::PhantomData;
5
6/// Orders transactions by effective coinbase tip using a compact priority value.
7#[derive(Debug)]
8pub struct TempoTipOrdering<T>(PhantomData<T>);
9
10impl<T> TransactionOrdering for TempoTipOrdering<T>
11where
12    T: PoolTransaction + 'static,
13{
14    type PriorityValue = u64;
15    type Transaction = T;
16
17    fn priority(
18        &self,
19        transaction: &Self::Transaction,
20        base_fee: u64,
21    ) -> Priority<Self::PriorityValue> {
22        transaction
23            .effective_tip_per_gas(base_fee)
24            .map(|priority| priority.try_into().unwrap_or(u64::MAX))
25            .into()
26    }
27}
28
29impl<T> Default for TempoTipOrdering<T> {
30    fn default() -> Self {
31        Self(Default::default())
32    }
33}
34
35impl<T> Clone for TempoTipOrdering<T> {
36    fn clone(&self) -> Self {
37        Self::default()
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::{TempoTipOrdering, TransactionOrdering};
44    use crate::test_utils::TxBuilder;
45
46    #[test]
47    fn priority_saturates_to_u64_max() {
48        let tx = TxBuilder::default()
49            .max_fee(u128::MAX)
50            .max_priority_fee(u128::MAX)
51            .build();
52
53        assert_eq!(
54            TempoTipOrdering::default().priority(&tx, 0),
55            reth_transaction_pool::Priority::Value(u64::MAX)
56        );
57    }
58}