feat(txpool): implement missing remove function (#378)

This commit is contained in:
Matthias Seitz
2022-12-10 18:15:16 +01:00
committed by GitHub
parent 6870c41fb0
commit eedd31ca59
4 changed files with 26 additions and 4 deletions

View File

@ -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>) {

View File

@ -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();

View File

@ -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,

View File

@ -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.