diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 01a2b469d9..69c512f286 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -94,7 +94,7 @@ use std::{ time::Instant, }; use tokio::sync::mpsc; -use tracing::{debug, trace, warn, info}; +use tracing::{debug, info, trace, warn}; mod events; use crate::{ blobstore::BlobStore, @@ -506,8 +506,13 @@ where transactions.into_iter().map(|tx| self.add_transaction(origin, tx)).collect::>(); // If at least one transaction was added successfully, then we enforce the pool size limits. - let discarded = - if added.iter().any(Result::is_ok) { self.discard_worst() } else { Default::default() }; + let discarded = if added.iter().any(Result::is_ok) { + let res = self.discard_worst(); + self.cleanup_senders(); + res + } else { + Default::default() + }; if discarded.is_empty() { return added @@ -807,7 +812,7 @@ where let mut pool = self.pool.write(); let mut identifiers = self.identifiers.write(); pool.cleanup_senders(); - identifiers.retain(|id, _addr| pool.all().contains_sender(id)); + identifiers.retain(|id, _addr| pool.contains_sender(id)); } /// Cleans up the blob store diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 15b60a7942..0df1bdc35a 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -123,6 +123,11 @@ impl TxPool { self.metrics.known_senders.set(self.sender_info.len() as f64); } + /// Returns whether or not the pool contains the given sender. + pub(crate) fn contains_sender(&self, sender: &SenderId) -> bool { + self.sender_info.contains_key(sender) + } + /// Returns stats about the size of pool. pub fn size(&self) -> PoolSize { PoolSize { @@ -852,8 +857,6 @@ impl TxPool { ] ); - self.cleanup_senders(); - removed }