Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spec of TxPoolOrphanDoubleSpend #4211

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading