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 3653c3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
14 changes: 7 additions & 7 deletions test/src/specs/tx_pool/orphan_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,23 @@ impl Spec for TxPoolOrphanNormal {
);
assert!(
run_replay_tx(&net, node0, tx1, 0, 2),
"tx1 is send expect nothing in orphan pool"
"tx1 is sent expect nothing in orphan pool"
);
assert!(
run_replay_tx(&net, node0, tx11, 0, 3),
"tx11 is send expect nothing in orphan pool"
"tx11 is sent expect nothing in orphan pool"
);
assert!(
run_replay_tx(&net, node0, tx12, 0, 4),
"tx12 is send expect nothing in orphan pool"
"tx12 is sent expect nothing in orphan pool"
);
assert!(
run_replay_tx(&net, node0, tx13, 0, 5),
"tx13 is send expect nothing in orphan pool"
"tx13 is sent expect nothing in orphan pool"
);
assert!(
run_replay_tx(&net, node0, final_tx, 0, 6),
"final_tx is send expect nothing in orphan pool"
"final_tx is sent expect nothing in orphan pool"
);
}
}
Expand Down Expand Up @@ -293,12 +293,12 @@ impl Spec for TxPoolOrphanUnordered {
);
assert!(
run_replay_tx(&net, node0, tx1, 1, 4),
"tx1 is send, orphan pool only contains final_tx"
"tx1 is sent, orphan pool only contains final_tx"
);

assert!(
run_replay_tx(&net, node0, tx13, 0, 6),
"tx13 is send, orphan pool is empty"
"tx13 is sent, orphan pool is empty"
);
}
}
Expand Down
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 3653c3e

Please sign in to comment.