mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 17:18:08 -05:00
chore: add exceeds fn (#6716)
This commit is contained in:
@@ -88,6 +88,12 @@ impl<T: PoolTransaction> BlobTransactions<T> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Returns true if the pool exceeds the given limit
|
||||
#[inline]
|
||||
pub(crate) fn exceeds(&self, limit: &SubPoolLimit) -> bool {
|
||||
limit.is_exceeded(self.len(), self.size())
|
||||
}
|
||||
|
||||
/// The reported size of all transactions in this pool.
|
||||
pub(crate) fn size(&self) -> usize {
|
||||
self.size_of.into()
|
||||
@@ -188,7 +194,7 @@ impl<T: PoolTransaction> BlobTransactions<T> {
|
||||
) -> Vec<Arc<ValidPoolTransaction<T>>> {
|
||||
let mut removed = Vec::new();
|
||||
|
||||
while limit.is_exceeded(self.len(), self.size()) {
|
||||
while self.exceeds(&limit) {
|
||||
let tx = self.all.last().expect("pool is not empty");
|
||||
let id = *tx.transaction.id();
|
||||
removed.push(self.remove_transaction(&id).expect("transaction exists"));
|
||||
|
||||
@@ -156,7 +156,7 @@ impl<T: ParkedOrd> ParkedPool<T> {
|
||||
&mut self,
|
||||
limit: SubPoolLimit,
|
||||
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
if !limit.is_exceeded(self.len(), self.size()) {
|
||||
if !self.exceeds(&limit) {
|
||||
// if we are below the limits, we don't need to drop anything
|
||||
return Vec::new()
|
||||
}
|
||||
@@ -175,7 +175,7 @@ impl<T: ParkedOrd> ParkedPool<T> {
|
||||
removed.push(tx);
|
||||
}
|
||||
|
||||
if !limit.is_exceeded(self.len(), self.size()) {
|
||||
if !self.exceeds(&limit) {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -200,6 +200,12 @@ impl<T: ParkedOrd> ParkedPool<T> {
|
||||
self.by_id.len()
|
||||
}
|
||||
|
||||
/// Returns true if the pool exceeds the given limit
|
||||
#[inline]
|
||||
pub(crate) fn exceeds(&self, limit: &SubPoolLimit) -> bool {
|
||||
limit.is_exceeded(self.len(), self.size())
|
||||
}
|
||||
|
||||
/// Returns whether the pool is empty
|
||||
#[cfg(test)]
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -434,7 +434,7 @@ impl<T: TransactionOrdering> PendingPool<T> {
|
||||
|
||||
// return if either the pool is under limits or there are no more _eligible_
|
||||
// transactions to remove
|
||||
if !limit.is_exceeded(self.len(), self.size()) || non_local_senders == 0 {
|
||||
if !self.exceeds(limit) || non_local_senders == 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -456,13 +456,13 @@ impl<T: TransactionOrdering> PendingPool<T> {
|
||||
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
|
||||
let mut removed = Vec::new();
|
||||
// return early if the pool is already under the limits
|
||||
if !limit.is_exceeded(self.len(), self.size()) {
|
||||
if !self.exceeds(&limit) {
|
||||
return removed
|
||||
}
|
||||
|
||||
// first truncate only non-local transactions, returning if the pool end up under the limit
|
||||
self.remove_to_limit(&limit, false, &mut removed);
|
||||
if !limit.is_exceeded(self.len(), self.size()) {
|
||||
if !self.exceeds(&limit) {
|
||||
return removed
|
||||
}
|
||||
|
||||
@@ -473,6 +473,12 @@ impl<T: TransactionOrdering> PendingPool<T> {
|
||||
removed
|
||||
}
|
||||
|
||||
/// Returns true if the pool exceeds the given limit
|
||||
#[inline]
|
||||
pub(crate) fn exceeds(&self, limit: &SubPoolLimit) -> bool {
|
||||
limit.is_exceeded(self.len(), self.size())
|
||||
}
|
||||
|
||||
/// The reported size of all transactions in this pool.
|
||||
pub(crate) fn size(&self) -> usize {
|
||||
self.size_of.into()
|
||||
|
||||
@@ -761,10 +761,7 @@ impl<T: TransactionOrdering> TxPool<T> {
|
||||
macro_rules! discard_worst {
|
||||
($this:ident, $removed:ident, [$($limit:ident => $pool:ident),* $(,)*]) => {
|
||||
$ (
|
||||
while $this
|
||||
.config
|
||||
.$limit
|
||||
.is_exceeded($this.$pool.len(), $this.$pool.size())
|
||||
while $this.$pool.exceeds(&$this.config.$limit)
|
||||
{
|
||||
trace!(
|
||||
"discarding transactions from {}, limit: {:?}, curr size: {}, curr len: {}",
|
||||
|
||||
Reference in New Issue
Block a user