From 809d0cab03beaabd261269eadf0eac6d73bc318e Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Mon, 6 Mar 2023 16:49:48 +0200 Subject: [PATCH] fix(txpool): queued tx ordering (#1643) --- crates/transaction-pool/src/pool/mod.rs | 1 - crates/transaction-pool/src/pool/parked.rs | 9 ++++++--- crates/transaction-pool/src/pool/transaction.rs | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) delete mode 100644 crates/transaction-pool/src/pool/transaction.rs diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 3772b41861..334dec5eb2 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -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; diff --git a/crates/transaction-pool/src/pool/parked.rs b/crates/transaction-pool/src/pool/parked.rs index 94105a1609..ed16256b6d 100644 --- a/crates/transaction-pool/src/pool/parked.rs +++ b/crates/transaction-pool/src/pool/parked.rs @@ -231,8 +231,8 @@ impl Ord for BasefeeOrd { /// `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(Arc>); @@ -240,6 +240,9 @@ impl_ord_wrapper!(QueuedOrd); impl Ord for QueuedOrd { 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)) } } diff --git a/crates/transaction-pool/src/pool/transaction.rs b/crates/transaction-pool/src/pool/transaction.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/crates/transaction-pool/src/pool/transaction.rs +++ /dev/null @@ -1 +0,0 @@ -