Skip to content

Commit 6166209

Browse files
authored
chore(pool): replace saturating_sub with unchecked_sub (#17890)
1 parent 198ba18 commit 6166209

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

crates/transaction-pool/src/identifier.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ impl TransactionId {
101101
/// This returns `transaction_nonce - 1` if `transaction_nonce` is higher than the
102102
/// `on_chain_nonce`
103103
pub fn ancestor(transaction_nonce: u64, on_chain_nonce: u64, sender: SenderId) -> Option<Self> {
104-
(transaction_nonce > on_chain_nonce)
105-
.then(|| Self::new(sender, transaction_nonce.saturating_sub(1)))
104+
// SAFETY: transaction_nonce > on_chain_nonce ⇒ transaction_nonce >= 1
105+
(transaction_nonce > on_chain_nonce).then(|| Self::new(sender, transaction_nonce - 1))
106106
}
107107

108108
/// Returns the [`TransactionId`] that would come before this transaction.
109109
pub fn unchecked_ancestor(&self) -> Option<Self> {
110+
// SAFETY: self.nonce != 0 ⇒ self.nonce >= 1
110111
(self.nonce != 0).then(|| Self::new(self.sender, self.nonce - 1))
111112
}
112113

0 commit comments

Comments
 (0)