feat(txpool): default transaction ordering (#1704)

This commit is contained in:
Roman Krasiuk
2023-03-10 18:30:36 +02:00
committed by GitHub
parent 99a821aa78
commit a0f195590c
2 changed files with 23 additions and 2 deletions

View File

@ -81,7 +81,7 @@
pub use crate::{
config::PoolConfig,
ordering::TransactionOrdering,
ordering::{CostOrdering, TransactionOrdering},
traits::{
BestTransactions, OnNewBlockEvent, PoolTransaction, PooledTransaction, PropagateKind,
PropagatedTransactions, TransactionOrigin, TransactionPool,

View File

@ -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<T>(PhantomData<T>);
impl<T> TransactionOrdering for CostOrdering<T>
where
T: PoolTransaction + 'static,
{
type Priority = U256;
type Transaction = T;
fn priority(&self, transaction: &Self::Transaction) -> Self::Priority {
transaction.cost()
}
}