fix(txpool): queued tx ordering (#1643)

This commit is contained in:
Roman Krasiuk
2023-03-06 16:49:48 +02:00
committed by GitHub
parent ce2b83e774
commit 809d0cab03
3 changed files with 6 additions and 5 deletions

View File

@@ -92,7 +92,6 @@ mod parked;
pub(crate) mod pending;
pub(crate) mod size;
pub(crate) mod state;
mod transaction;
pub mod txpool;
mod update;

View File

@@ -231,8 +231,8 @@ impl<T: PoolTransaction> Ord for BasefeeOrd<T> {
/// `Queued` transactions are transactions that are currently blocked by other parked (basefee,
/// queued) or missing transactions.
///
/// The primary order function for is always compares via the timestamp when the transaction was
/// created
/// The primary order function always compares the transaction costs first. In case these
/// are equal, it compares the timestamps when the transactions were created.
#[derive(Debug)]
pub(crate) struct QueuedOrd<T: PoolTransaction>(Arc<ValidPoolTransaction<T>>);
@@ -240,6 +240,9 @@ impl_ord_wrapper!(QueuedOrd);
impl<T: PoolTransaction> Ord for QueuedOrd<T> {
fn cmp(&self, other: &Self) -> Ordering {
other.timestamp.cmp(&self.timestamp)
// Higher cost is better
self.cost.cmp(&other.cost).then_with(||
// Lower timestamp is better
other.timestamp.cmp(&self.timestamp))
}
}