diff --git a/pool/src/pool.rs b/pool/src/pool.rs index d2ac8be5..8d7eeb53 100644 --- a/pool/src/pool.rs +++ b/pool/src/pool.rs @@ -307,6 +307,15 @@ where Ok(()) } + // Use our bucket logic to identify the best transaction for eviction and evict it. + // We want to avoid evicting a transaction where another transaction depends on it. + // We want to evict a transaction with low fee_to_weight. + pub fn evict_transaction(&mut self) { + if let Some(evictable_transaction) = self.bucket_transactions(Weighting::NoLimit).last() { + self.entries.retain(|x| x.tx != *evictable_transaction); + }; + } + /// Buckets consist of a vec of txs and track the aggregate fee_to_weight. /// We aggregate (cut-through) dependent transactions within a bucket *unless* adding a tx /// would reduce the aggregate fee_to_weight, in which case we start a new bucket. @@ -314,7 +323,7 @@ where /// containing the tx it depends on. /// Sorting the buckets by fee_to_weight will therefore preserve dependency ordering, /// maximizing both cut-through and overall fees. - pub fn bucket_transactions(&self, weighting: Weighting) -> Vec { + fn bucket_transactions(&self, weighting: Weighting) -> Vec { let mut tx_buckets: Vec = Vec::new(); let mut output_commits = HashMap::new(); let mut rejected = HashSet::new(); diff --git a/pool/src/transaction_pool.rs b/pool/src/transaction_pool.rs index 24a9a988..5dd4ea7f 100644 --- a/pool/src/transaction_pool.rs +++ b/pool/src/transaction_pool.rs @@ -195,19 +195,11 @@ where Ok(()) } - // Remove the last transaction from the flattened bucket transactions. - // No other tx depends on it, it has low fee_to_weight and is unlikely to participate in any cut-through. + // Evict a transaction from the txpool. + // Uses bucket logic to identify the "last" transaction. + // No other tx depends on it and it has low fee_to_weight. pub fn evict_from_txpool(&mut self) { - // Get bucket transactions - let bucket_transactions = self.txpool.bucket_transactions(Weighting::NoLimit); - - // Get last transaction and remove it - if let Some(evictable_transaction) = bucket_transactions.last() { - // Remove transaction - self.txpool - .entries - .retain(|x| x.tx != *evictable_transaction); - }; + self.txpool.evict_transaction() } // Old txs will "age out" after 30 mins.