Skip to content

Commit 56d688b

Browse files
authored
Small refactoring in transaction pool (#7179)
1 parent 7b3e418 commit 56d688b

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

crates/transaction-pool/src/pool/blob.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,18 +433,19 @@ impl PartialOrd<Self> for BlobOrd {
433433
}
434434

435435
impl Ord for BlobOrd {
436+
/// Compares two `BlobOrd` instances.
437+
///
438+
/// The comparison is performed in reverse order based on the priority field. This is
439+
/// because transactions with larger negative values in the priority field will take more fee
440+
/// jumps, making them take longer to become executable. Therefore, transactions with lower
441+
/// ordering should return `Greater`, ensuring they are evicted first.
442+
///
443+
/// If the priority values are equal, the submission ID is used to break ties.
436444
fn cmp(&self, other: &Self) -> Ordering {
437-
// order in reverse, so transactions with a lower ordering return Greater - this is
438-
// important because transactions with larger negative values will take more fee jumps and
439-
// it will take longer to become executable, so those should be evicted first
440-
let ord = other.priority.cmp(&self.priority);
441-
442-
// use submission_id to break ties
443-
if ord == Ordering::Equal {
444-
self.submission_id.cmp(&other.submission_id)
445-
} else {
446-
ord
447-
}
445+
other
446+
.priority
447+
.cmp(&self.priority)
448+
.then_with(|| self.submission_id.cmp(&other.submission_id))
448449
}
449450
}
450451

crates/transaction-pool/src/traits.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,17 +494,15 @@ impl PropagateKind {
494494
/// Returns the peer the transaction was sent to
495495
pub const fn peer(&self) -> &PeerId {
496496
match self {
497-
PropagateKind::Full(peer) => peer,
498-
PropagateKind::Hash(peer) => peer,
497+
PropagateKind::Full(peer) | PropagateKind::Hash(peer) => peer,
499498
}
500499
}
501500
}
502501

503502
impl From<PropagateKind> for PeerId {
504503
fn from(value: PropagateKind) -> Self {
505504
match value {
506-
PropagateKind::Full(peer) => peer,
507-
PropagateKind::Hash(peer) => peer,
505+
PropagateKind::Full(peer) | PropagateKind::Hash(peer) => peer,
508506
}
509507
}
510508
}

crates/transaction-pool/src/validate/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ impl<T: PoolTransaction> ValidTransaction<T> {
126126
/// Consumes the wrapper and returns the transaction.
127127
pub fn into_transaction(self) -> T {
128128
match self {
129-
Self::Valid(transaction) => transaction,
130-
Self::ValidWithSidecar { transaction, .. } => transaction,
129+
Self::Valid(transaction) | Self::ValidWithSidecar { transaction, .. } => transaction,
131130
}
132131
}
133132

0 commit comments

Comments
 (0)