mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
feat(txpool): add is_transaction_ready to TransactionPool trait (#21742)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -610,6 +610,14 @@ where
|
||||
self.pool.pending_transactions()
|
||||
}
|
||||
|
||||
fn get_pending_transaction_by_sender_and_nonce(
|
||||
&self,
|
||||
sender: Address,
|
||||
nonce: u64,
|
||||
) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
|
||||
self.pool.get_pending_transaction_by_sender_and_nonce(sender, nonce)
|
||||
}
|
||||
|
||||
fn pending_transactions_max(
|
||||
&self,
|
||||
max: usize,
|
||||
|
||||
@@ -1090,6 +1090,16 @@ where
|
||||
self.get_pool_data().get_transactions_by_sender(sender_id)
|
||||
}
|
||||
|
||||
/// Returns a pending transaction sent by the given sender with the given nonce.
|
||||
pub fn get_pending_transaction_by_sender_and_nonce(
|
||||
&self,
|
||||
sender: Address,
|
||||
nonce: u64,
|
||||
) -> Option<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
let sender_id = self.get_sender_id(sender);
|
||||
self.get_pool_data().get_pending_transaction_by_sender_and_nonce(sender_id, nonce)
|
||||
}
|
||||
|
||||
/// Returns all queued transactions of the address by sender
|
||||
pub fn get_queued_transactions_by_sender(
|
||||
&self,
|
||||
|
||||
@@ -560,6 +560,18 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
self.all_transactions.txs_iter(sender).map(|(_, tx)| Arc::clone(&tx.transaction)).collect()
|
||||
}
|
||||
|
||||
/// Returns a pending transaction sent by the given sender with the given nonce.
|
||||
pub(crate) fn get_pending_transaction_by_sender_and_nonce(
|
||||
&self,
|
||||
sender: SenderId,
|
||||
nonce: u64,
|
||||
) -> Option<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
self.all_transactions
|
||||
.txs_iter(sender)
|
||||
.find(|(id, tx)| id.nonce == nonce && tx.subpool == SubPool::Pending)
|
||||
.map(|(_, tx)| Arc::clone(&tx.transaction))
|
||||
}
|
||||
|
||||
/// Updates only the pending fees without triggering subpool updates.
|
||||
/// Returns the previous base fee and blob fee values.
|
||||
const fn update_pending_fees_only(
|
||||
|
||||
@@ -405,6 +405,16 @@ pub trait TransactionPool: Clone + Debug + Send + Sync {
|
||||
/// Consumer: RPC
|
||||
fn pending_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
|
||||
|
||||
/// Returns a pending transaction if it exists and is ready for immediate execution
|
||||
/// (i.e., has the lowest nonce among the sender's pending transactions).
|
||||
fn get_pending_transaction_by_sender_and_nonce(
|
||||
&self,
|
||||
sender: Address,
|
||||
nonce: u64,
|
||||
) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
|
||||
self.best_transactions().find(|tx| tx.sender() == sender && tx.nonce() == nonce)
|
||||
}
|
||||
|
||||
/// Returns first `max` transactions that can be included in the next block.
|
||||
/// See <https://github.com/paradigmxyz/reth/issues/12767#issuecomment-2493223579>
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user