Skip to content

Commit

Permalink
Merge pull request #4211 from chenyukang/yukang-fix-112-spec
Browse files Browse the repository at this point in the history
fix spec of TxPoolOrphanDoubleSpend
  • Loading branch information
doitian authored Oct 31, 2023
2 parents 5d1294e + bca78cf commit 07f8082
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions test/src/specs/tx_pool/orphan_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
8 changes: 7 additions & 1 deletion tx-pool/src/component/pool_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -190,6 +190,11 @@ impl PoolMap {

pub(crate) fn remove_entry(&mut self, id: &ProposalShortId) -> Option<TxEntry> {
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);
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions tx-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
{
Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions tx-pool/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -445,6 +446,7 @@ impl TxPoolService {
});
}
Err(reject) => {
debug!("after_process {} reject: {} ", tx_hash, reject);
if matches!(
reject,
Reject::Resolve(..)
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 07f8082

Please sign in to comment.