mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat(txpool): implement missing remove function (#378)
This commit is contained in:
@ -235,9 +235,9 @@ where
|
||||
|
||||
fn remove_invalid(
|
||||
&self,
|
||||
_tx_hashes: &[TxHash],
|
||||
hashes: impl IntoIterator<Item = TxHash>,
|
||||
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
|
||||
todo!()
|
||||
self.pool.remove_invalid(hashes)
|
||||
}
|
||||
|
||||
fn retain_unknown(&self, hashes: &mut Vec<TxHash>) {
|
||||
|
||||
@ -334,6 +334,20 @@ where
|
||||
self.pool.read().best_transactions()
|
||||
}
|
||||
|
||||
/// Removes and returns all matching transactions from the pool.
|
||||
pub(crate) fn remove_invalid(
|
||||
&self,
|
||||
hashes: impl IntoIterator<Item = TxHash>,
|
||||
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
let removed = self.pool.write().remove_invalid(hashes);
|
||||
|
||||
let mut listener = self.event_listener.write();
|
||||
|
||||
removed.iter().for_each(|tx| listener.discarded(tx.hash()));
|
||||
|
||||
removed
|
||||
}
|
||||
|
||||
/// Removes all transactions that are missing in the pool.
|
||||
pub(crate) fn retain_unknown(&self, hashes: &mut Vec<TxHash>) {
|
||||
let pool = self.pool.read();
|
||||
|
||||
@ -276,6 +276,14 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes and returns all matching transactions from the pool.
|
||||
pub(crate) fn remove_invalid(
|
||||
&mut self,
|
||||
hashes: impl IntoIterator<Item = TxHash>,
|
||||
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
hashes.into_iter().filter_map(|hash| self.remove_transaction_by_hash(&hash)).collect()
|
||||
}
|
||||
|
||||
/// Remove the transaction from the entire pool.
|
||||
///
|
||||
/// This includes the total set of transaction and the subpool it currently resides in.
|
||||
@ -289,7 +297,7 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
|
||||
/// Remove the transaction from the entire pool via its hash.
|
||||
///
|
||||
/// This includes the total set of transaction and the subpool it currently resides in.
|
||||
/// This includes the total set of transactions and the subpool it currently resides in.
|
||||
fn remove_transaction_by_hash(
|
||||
&mut self,
|
||||
tx_hash: &H256,
|
||||
|
||||
@ -83,7 +83,7 @@ pub trait TransactionPool: Send + Sync + 'static {
|
||||
/// Consumer: Block production
|
||||
fn remove_invalid(
|
||||
&self,
|
||||
tx_hashes: &[TxHash],
|
||||
hashes: impl IntoIterator<Item = TxHash>,
|
||||
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;
|
||||
|
||||
/// Retains only those hashes that are unknown to the pool.
|
||||
|
||||
Reference in New Issue
Block a user