Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Oct 24, 2023
1 parent b4c38ad commit 2c37b15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tx-pool/src/component/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions tx-pool/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ impl TxPoolService {

pub(crate) async fn find_orphan_by_previous(&self, tx: &TransactionView) -> Vec<OrphanEntry> {
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::<Vec<_>>()
}
Expand Down Expand Up @@ -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<Item = &'a TransactionView>,
) {
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<TransactionView>) {
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(
Expand Down

0 comments on commit 2c37b15

Please sign in to comment.