From 5b41165142a061e8ca06b9763781313118bb809f Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 31 Oct 2023 09:36:58 +0800 Subject: [PATCH 1/2] fix spec of TxPoolOrphanDoubleSpend --- test/src/specs/tx_pool/orphan_tx.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/specs/tx_pool/orphan_tx.rs b/test/src/specs/tx_pool/orphan_tx.rs index de6f29766b..64d4545bd9 100644 --- a/test/src/specs/tx_pool/orphan_tx.rs +++ b/test/src/specs/tx_pool/orphan_tx.rs @@ -343,8 +343,8 @@ impl Spec for TxPoolOrphanDoubleSpend { ); assert!( - run_replay_tx(&net, node0, tx12, 1, 0), - "tx12 is not in orphan pool" + run_replay_tx(&net, node0, tx12, 2, 0), + "tx12 in orphan pool" ); } } From bca78cfbe384f8fcf727bfe03ac5f57a9a86eac6 Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 31 Oct 2023 17:04:15 +0800 Subject: [PATCH 2/2] add debug logs for txpool --- tx-pool/src/component/pool_map.rs | 8 +++++++- tx-pool/src/pool.rs | 3 +++ tx-pool/src/process.rs | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tx-pool/src/component/pool_map.rs b/tx-pool/src/component/pool_map.rs index a0830a42d4..dc573ab675 100644 --- a/tx-pool/src/component/pool_map.rs +++ b/tx-pool/src/component/pool_map.rs @@ -7,7 +7,7 @@ use crate::component::sort_key::{AncestorsScoreSortKey, EvictKey}; use crate::error::Reject; use crate::TxEntry; -use ckb_logger::trace; +use ckb_logger::{debug, trace}; use ckb_types::core::error::OutPointError; use ckb_types::packed::OutPoint; use ckb_types::prelude::*; @@ -190,6 +190,11 @@ impl PoolMap { pub(crate) fn remove_entry(&mut self, id: &ProposalShortId) -> Option { self.entries.remove_by_id(id).map(|entry| { + debug!( + "remove entry {} from status: {:?}", + entry.inner.transaction().hash(), + entry.status + ); self.update_ancestors_index_key(&entry.inner, EntryOp::Remove); self.update_descendants_index_key(&entry.inner, EntryOp::Remove); self.remove_entry_edges(&entry.inner); @@ -455,6 +460,7 @@ impl PoolMap { entry.add_ancestor_weight(&ancestor.inner); } if entry.ancestors_count > self.max_ancestors_count { + debug!("debug: exceeded maximum ancestors count"); return Err(Reject::ExceededMaximumAncestorsCount); } diff --git a/tx-pool/src/pool.rs b/tx-pool/src/pool.rs index 20e3028e32..c28cbba83c 100644 --- a/tx-pool/src/pool.rs +++ b/tx-pool/src/pool.rs @@ -228,6 +228,7 @@ impl TxPool { fn remove_committed_tx(&mut self, tx: &TransactionView, callbacks: &Callbacks) { let short_id = tx.proposal_short_id(); if let Some(entry) = self.pool_map.remove_entry(&short_id) { + debug!("remove_committed_tx for {}", tx.hash()); callbacks.call_committed(self, &entry) } { @@ -249,6 +250,8 @@ impl TxPool { .collect(); for entry in removed { + let tx_hash = entry.transaction().hash(); + debug!("remove_expired {} timestamp({})", tx_hash, entry.timestamp); self.pool_map.remove_entry(&entry.proposal_short_id()); let reject = Reject::Expiry(entry.timestamp); callbacks.call_reject(self, &entry, reject); diff --git a/tx-pool/src/process.rs b/tx-pool/src/process.rs index e9be766d56..bbf2ba1777 100644 --- a/tx-pool/src/process.rs +++ b/tx-pool/src/process.rs @@ -403,6 +403,7 @@ impl TxPoolService { self.process_orphan_tx(&tx).await; } Err(reject) => { + debug!("after_process {} remote reject: {} ", tx_hash, reject); if is_missing_input(reject) && all_inputs_is_unknown(snapshot, &tx) { self.add_orphan(tx, peer, declared_cycle).await; } else { @@ -445,6 +446,7 @@ impl TxPoolService { }); } Err(reject) => { + debug!("after_process {} reject: {} ", tx_hash, reject); if matches!( reject, Reject::Resolve(..) @@ -1081,19 +1083,23 @@ fn _submit_entry( entry: TxEntry, callbacks: &Callbacks, ) -> Result<(), Reject> { + let tx_hash = entry.transaction().hash(); match status { TxStatus::Fresh => { if tx_pool.add_pending(entry.clone())? { + debug!("submit_entry pending {}", tx_hash); callbacks.call_pending(tx_pool, &entry); } } TxStatus::Gap => { if tx_pool.add_gap(entry.clone())? { + debug!("submit_entry gap {}", tx_hash); callbacks.call_pending(tx_pool, &entry); } } TxStatus::Proposed => { if tx_pool.add_proposed(entry.clone())? { + debug!("submit_entry proposed {}", tx_hash); callbacks.call_proposed(tx_pool, &entry, true); } } @@ -1147,6 +1153,11 @@ fn _update_tx_pool_for_reorg( for (id, entry) in proposals { debug!("begin to proposed: {:x}", id); if let Err(e) = tx_pool.proposed_rtx(&id) { + debug!( + "Failed to add proposed tx {}, reason: {}", + entry.transaction().hash(), + e + ); callbacks.call_reject(tx_pool, &entry, e); } else { callbacks.call_proposed(tx_pool, &entry, false)