mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(txpool): default transaction ordering (#1704)
This commit is contained in:
@ -81,7 +81,7 @@
|
||||
|
||||
pub use crate::{
|
||||
config::PoolConfig,
|
||||
ordering::TransactionOrdering,
|
||||
ordering::{CostOrdering, TransactionOrdering},
|
||||
traits::{
|
||||
BestTransactions, OnNewBlockEvent, PoolTransaction, PooledTransaction, PropagateKind,
|
||||
PropagatedTransactions, TransactionOrigin, TransactionPool,
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user