From 2c37b155740159cf9c5296f76b55b935b9c4b4d8 Mon Sep 17 00:00:00 2001 From: yukang Date: Mon, 23 Oct 2023 23:55:56 +0800 Subject: [PATCH] code refactor --- tx-pool/src/component/orphan.rs | 2 +- tx-pool/src/process.rs | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tx-pool/src/component/orphan.rs b/tx-pool/src/component/orphan.rs index ebd99cd1568..92a419c6a82 100644 --- a/tx-pool/src/component/orphan.rs +++ b/tx-pool/src/component/orphan.rs @@ -84,7 +84,7 @@ impl OrphanPool { self.shrink_to_fit(); } - pub fn limit_size(&mut self) -> usize { + fn limit_size(&mut self) -> usize { let now = ckb_systemtime::unix_time().as_secs(); let expires: Vec<_> = self .entries diff --git a/tx-pool/src/process.rs b/tx-pool/src/process.rs index 61d303b0990..90760e3b260 100644 --- a/tx-pool/src/process.rs +++ b/tx-pool/src/process.rs @@ -473,8 +473,9 @@ impl TxPoolService { pub(crate) async fn find_orphan_by_previous(&self, tx: &TransactionView) -> Vec { let orphan = self.orphan.read().await; - let ids = orphan.find_by_previous(tx); - ids.iter() + orphan + .find_by_previous(tx) + .iter() .filter_map(|id| orphan.get(id).cloned()) .collect::>() } @@ -920,24 +921,19 @@ impl TxPoolService { } } - self.remove_orphan_txs_by_attach(attached.iter()).await; + self.remove_orphan_txs_by_attach(&attached).await; { let mut chunk = self.chunk.write().await; chunk.remove_chunk_txs(attached.iter().map(|tx| tx.proposal_short_id())); } } - async fn remove_orphan_txs_by_attach<'a>( - &self, - txs: impl Iterator, - ) { - let mut ids = vec![]; - for tx in txs { - ids.push(tx.proposal_short_id()); + async fn remove_orphan_txs_by_attach<'a>(&self, txs: &LinkedHashSet) { + for tx in txs.iter() { self.process_orphan_tx(tx).await; } let mut orphan = self.orphan.write().await; - orphan.remove_orphan_txs(ids.into_iter()); + orphan.remove_orphan_txs(txs.iter().map(|tx| tx.proposal_short_id())); } fn readd_detached_tx(